# nazib-riasat/19august architecture

> Architecture diagram of the GitHub repository nazib-riasat/19august, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nazib-riasat/19august
- Repository: https://github.com/nazib-riasat/19august

## Overview

#### Purpose and Entry Points
GRAFT is a research pipeline for provenance-preserving temporal graph memory and checker-conditioned evidence-set selection. Its stable programmatic entry is the `graft` Python package; configuration begins with `graft/config/loader.py` and typed models in `graft/schemas.py`. Operational entry points are phase scripts such as `scripts/verify_handoff.py`, `scripts/locomo_ingest.py`, and `scripts/phase3_gate2.py`.

#### Reproducible Runtime and Persistence
Cross-machine determinism is an architectural requirement. Canonical serialization, content-derived IDs, append-only event logging, graph replay, budget accounting, and run manifests establish reproducible experiment identity and auditability.
- `graft/canonical.py`
- `graft/eventlog.py`
- `graft/graphstore.py`
- `graft/runtime.py`
- `graft/ledger.py`

Configuration uses frozen schema-backed presets; resolved configuration hashes—not YAML formatting—identify runs.
- `graft/config/schema.py`
- `graft/config/loader.py`
- `graft/config/presets/default.yaml`

#### Deterministic Evidence Core
The core defines the formal boundary between proposed evidence sets and valid, rewarded terminals: graph resolution, obligation coverage, legality masks, checker verdicts, utility, and reward `R = 1[H] * exp(beta*U)`. Incremental state transitions must agree with the full checker, enabling safe ADD/undo generation.
- `graft/core/checker.py`
- `graft/core/obligations.py`
- `graft/core/masks.py`
- `graft/core/reward.py`
- `graft/core/incremental.py`

#### Synthetic Environment, Learners, and Search
The synthetic layer provides enumerable ProofLattice environments and exact distributional evaluation. Set generation consumes these states through policies, rollouts, a shared trainer, and nine learner arms, including GAFlowNet and checker-conditioned LED variants. Phase-4 search supplies greedy, beam, submodular, PCST, and portfolio selection behind Gate-3 evaluation.
- `graft/synth/lattice.py`
- `graft/synth/exact.py`
- `graft/setgen/trainer.py`
- `graft/setgen/learners/gaflownet.py`
- `graft/setgen/search/gate3.py`

Phase-3 calibration and Gate-2 reports/checkpoints are persisted under `Phase3_slurm_result/985953/`; frozen calibration must remain comparable across runs.

#### Real-Data Ingestion and Graph Construction
Stage A transforms conversational/corpus inputs into provenance-bearing records via extraction, grounding, NLI verification, support gating, temporal parsing, and obligation parsing. Stage B turns accepted material into graph candidates, encoded/embedded features, learned links, validation, and committed graph updates.
- `graft/ingest/pipeline.py`
- `graft/ingest/extractor.py`
- `graft/ingest/grounding.py`
- `graft/ingest/nli.py`
- `graft/graphbuild/commit.py`
- `graft/graphbuild/train.py`

LoCoMo is externally downloaded, SHA-pinned, and ingested locally; it is evaluation-only. Annotation artifacts for the feasibility phase reside in `data/phase2_5/`.

#### Retrieval, Gating, and Reading
Later stages query the constructed graph/corpus through lexical, dense, entity, temporal, expansion, and fusion retrieval; then assess answerability/risk and invoke a reader/orchestrator to produce serialized answers. These are explicit boundaries between evidence acquisition, gate decisions, and answer generation.
- `graft/retrieve/pool.py`
- `graft/retrieve/fuse.py`
- `graft/gate/decide.py`
- `graft/gate/model.py`
- `graft/reader/orchestrator.py`

#### Infrastructure and Dependencies
The project targets Python 3.11/3.12. Base dependencies are in `requirements.txt`; Phase 3 adds PyTorch via `requirements-ml.txt`, with CPU training supported and CUDA installation relevant on Blackwell GPUs. Batch execution is supported through `scripts/slurm_phase3_narval.sh` and stored Slurm results. External datasets include LoCoMo, 2Wiki, and MuSiQue-Ans; model-assisted extraction/linking is represented by prompt and LLM-link modules.

Main entry points: [`graft/setgen/trainer.py`](https://github.com/nazib-riasat/19august/blob/master/graft/setgen/trainer.py) (Set-generation trainer), [`graft/core/checker.py`](https://github.com/nazib-riasat/19august/blob/master/graft/core/checker.py) (Evidence checker), [`graft/runtime.py`](https://github.com/nazib-riasat/19august/blob/master/graft/runtime.py) (Reproducible runtime), [`graft/graphstore.py`](https://github.com/nazib-riasat/19august/blob/master/graft/graphstore.py) (Replayable graph store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundation["Runtime &amp; Reproducibility"]
  node_config["Resolved configuration<br/>[loader.py]"]
  node_runtime["Reproducible runtime<br/>[runtime.py]"]
  node_canonical["Canonical identity<br/>serialization<br/>[canonical.py]"]
  node_eventlog[("Append-only event log<br/>audit log<br/>[eventlog.py]")]
  node_graphstore[("Replayable graph store<br/>graph persistence<br/>[graphstore.py]")]
  node_ledger["Budget ledger<br/>accounting<br/>[ledger.py]"]
end

subgraph group_core["Evidence Core"]
  node_checker{{"Evidence checker<br/>validity boundary<br/>[checker.py]"}}
  node_obligations["Obligation coverage<br/>constraint model<br/>[obligations.py]"]
  node_incremental["Incremental transitions<br/>state transition<br/>[incremental.py]"]
  node_reward["Utility and reward<br/>reward model<br/>[reward.py]"]
end

subgraph group_learning["Synthetic Learning &amp; Search"]
  node_prooflattice["ProofLattice environment<br/>synthetic environment<br/>[lattice.py]"]
  node_exacteval["Exact distributional evaluation<br/>evaluator<br/>[exact.py]"]
  node_trainer["Set-generation trainer<br/>training orchestration<br/>[trainer.py]"]
  node_gaflownet["GAFlowNet learner<br/>learner arm<br/>[gaflownet.py]"]
  node_gate3search["Gate-3 selector portfolio<br/>search evaluation<br/>[gate3.py]"]
end

subgraph group_ingestion["Data Ingestion &amp; Graph Build"]
  node_source_data["Corpus and LoCoMo inputs<br/>external datasets"]
  node_ingest["Stage A provenance ingestion<br/>ingestion pipeline<br/>[pipeline.py]"]
  node_graphbuild["Stage B graph construction<br/>graph builder<br/>[commit.py]"]
end

subgraph group_serving["Retrieval, Gating &amp; Reading"]
  node_retrieval["Evidence retrieval and fusion<br/>retrieval pipeline<br/>[fuse.py]"]
  node_gate{{"Answerability and risk gate<br/>decision gate<br/>[decide.py]"}}
  node_reader["Reader orchestrator<br/>answer generation<br/>[orchestrator.py]"]
end

node_config -->|"resolved settings"| node_runtime
node_canonical -->|"run identity"| node_runtime
node_runtime -->|"records events"| node_eventlog
node_runtime -->|"accounts budget"| node_ledger
node_eventlog -->|"replay updates"| node_graphstore
node_obligations -->|"coverage constraints"| node_checker
node_checker -.->|"full-check agreement"| node_incremental
node_checker -->|"valid terminal H"| node_reward
node_prooflattice -->|"enumerable states"| node_trainer
node_checker -->|"legality and verdicts"| node_trainer
node_incremental -->|"ADD/undo actions"| node_trainer
node_reward -->|"training reward"| node_trainer
node_trainer -->|"trains learner arm"| node_gaflownet
node_gaflownet -->|"evaluated exactly"| node_exacteval
node_trainer -->|"candidate policies"| node_gate3search
node_source_data -->|"raw conversations and corpora"| node_ingest
node_ingest -->|"accepted provenance records"| node_graphbuild
node_graphbuild -->|"committed graph updates"| node_graphstore
node_graphstore -->|"graph and corpus evidence"| node_retrieval
node_retrieval -->|"fused evidence pool"| node_gate
node_gate -->|"gated context"| node_reader
node_checker -->|"selection validity"| node_gate3search

click node_config "https://github.com/nazib-riasat/19august/blob/master/graft/config/loader.py"
click node_runtime "https://github.com/nazib-riasat/19august/blob/master/graft/runtime.py"
click node_canonical "https://github.com/nazib-riasat/19august/blob/master/graft/canonical.py"
click node_eventlog "https://github.com/nazib-riasat/19august/blob/master/graft/eventlog.py"
click node_graphstore "https://github.com/nazib-riasat/19august/blob/master/graft/graphstore.py"
click node_ledger "https://github.com/nazib-riasat/19august/blob/master/graft/ledger.py"
click node_checker "https://github.com/nazib-riasat/19august/blob/master/graft/core/checker.py"
click node_obligations "https://github.com/nazib-riasat/19august/blob/master/graft/core/obligations.py"
click node_incremental "https://github.com/nazib-riasat/19august/blob/master/graft/core/incremental.py"
click node_reward "https://github.com/nazib-riasat/19august/blob/master/graft/core/reward.py"
click node_prooflattice "https://github.com/nazib-riasat/19august/blob/master/graft/synth/lattice.py"
click node_exacteval "https://github.com/nazib-riasat/19august/blob/master/graft/synth/exact.py"
click node_trainer "https://github.com/nazib-riasat/19august/blob/master/graft/setgen/trainer.py"
click node_gaflownet "https://github.com/nazib-riasat/19august/blob/master/graft/setgen/learners/gaflownet.py"
click node_gate3search "https://github.com/nazib-riasat/19august/blob/master/graft/setgen/search/gate3.py"
click node_ingest "https://github.com/nazib-riasat/19august/blob/master/graft/ingest/pipeline.py"
click node_graphbuild "https://github.com/nazib-riasat/19august/blob/master/graft/graphbuild/commit.py"
click node_retrieval "https://github.com/nazib-riasat/19august/blob/master/graft/retrieve/fuse.py"
click node_gate "https://github.com/nazib-riasat/19august/blob/master/graft/gate/decide.py"
click node_reader "https://github.com/nazib-riasat/19august/blob/master/graft/reader/orchestrator.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_runtime,node_canonical,node_eventlog,node_graphstore,node_ledger toneBlue
class node_checker,node_obligations,node_incremental,node_reward toneAmber
class node_prooflattice,node_exacteval,node_trainer,node_gaflownet,node_gate3search toneMint
class node_source_data,node_ingest,node_graphbuild toneRose
class node_retrieval,node_gate,node_reader toneIndigo
```

## Components

### Runtime & Reproducibility

- [Resolved configuration](https://github.com/nazib-riasat/19august/blob/master/graft/config/loader.py): config · Frozen schemas and presets produce hashable run settings. · `graft/config/loader.py`
- [Reproducible runtime](https://github.com/nazib-riasat/19august/blob/master/graft/runtime.py): runtime · Creates run identity, manifests, and deterministic execution context. · `graft/runtime.py`
- [Canonical identity](https://github.com/nazib-riasat/19august/blob/master/graft/canonical.py): serialization · Content-derived IDs and canonical serialization. · `graft/canonical.py`
- [Append-only event log](https://github.com/nazib-riasat/19august/blob/master/graft/eventlog.py): audit log · `graft/eventlog.py`
- [Replayable graph store](https://github.com/nazib-riasat/19august/blob/master/graft/graphstore.py): graph persistence · Persists committed updates and supports graph replay. · `graft/graphstore.py`
- [Budget ledger](https://github.com/nazib-riasat/19august/blob/master/graft/ledger.py): accounting · `graft/ledger.py`

### Evidence Core

- [Evidence checker](https://github.com/nazib-riasat/19august/blob/master/graft/core/checker.py): validity boundary · Resolves graph evidence and produces legality and terminal verdicts. · `graft/core/checker.py`
- [Obligation coverage](https://github.com/nazib-riasat/19august/blob/master/graft/core/obligations.py): constraint model · `graft/core/obligations.py`
- [Incremental transitions](https://github.com/nazib-riasat/19august/blob/master/graft/core/incremental.py): state transition · Safe ADD/undo transitions agree with full checking. · `graft/core/incremental.py`
- [Utility and reward](https://github.com/nazib-riasat/19august/blob/master/graft/core/reward.py): reward model · Rewards valid terminals using checker-conditioned utility. · `graft/core/reward.py`

### Synthetic Learning & Search

- [ProofLattice environment](https://github.com/nazib-riasat/19august/blob/master/graft/synth/lattice.py): synthetic environment · Enumerable states for controlled evidence-set experiments. · `graft/synth/lattice.py`
- [Exact distributional evaluation](https://github.com/nazib-riasat/19august/blob/master/graft/synth/exact.py): evaluator · `graft/synth/exact.py`
- [Set-generation trainer](https://github.com/nazib-riasat/19august/blob/master/graft/setgen/trainer.py): training orchestration · Shared training loop for checker-conditioned learner arms. · `graft/setgen/trainer.py`
- [GAFlowNet learner](https://github.com/nazib-riasat/19august/blob/master/graft/setgen/learners/gaflownet.py): learner arm · `graft/setgen/learners/gaflownet.py`
- [Gate-3 selector portfolio](https://github.com/nazib-riasat/19august/blob/master/graft/setgen/search/gate3.py): search evaluation · Greedy, beam, submodular, PCST, and portfolio selection. · `graft/setgen/search/gate3.py`

### Data Ingestion & Graph Build

- **Corpus and LoCoMo inputs**: external datasets · LoCoMo is SHA-pinned, locally ingested, and evaluation-only.
- [Stage A provenance ingestion](https://github.com/nazib-riasat/19august/blob/master/graft/ingest/pipeline.py): ingestion pipeline · Extraction, grounding, NLI, support gating, temporal and obligation parsing. · `graft/ingest/pipeline.py`
- [Stage B graph construction](https://github.com/nazib-riasat/19august/blob/master/graft/graphbuild/commit.py): graph builder · Builds candidates, features, learned links, validation, and commits. · `graft/graphbuild/commit.py`

### Retrieval, Gating & Reading

- [Evidence retrieval and fusion](https://github.com/nazib-riasat/19august/blob/master/graft/retrieve/fuse.py): retrieval pipeline · Combines lexical, dense, entity, temporal, and expansion retrieval. · `graft/retrieve/fuse.py`
- [Answerability and risk gate](https://github.com/nazib-riasat/19august/blob/master/graft/gate/decide.py): decision gate · `graft/gate/decide.py`
- [Reader orchestrator](https://github.com/nazib-riasat/19august/blob/master/graft/reader/orchestrator.py): answer generation · Produces serialized answers from gated evidence. · `graft/reader/orchestrator.py`

## Connections

- Resolved configuration → Reproducible runtime: resolved settings
- Canonical identity → Reproducible runtime: run identity
- Reproducible runtime → Append-only event log: records events
- Reproducible runtime → Budget ledger: accounts budget
- Append-only event log → Replayable graph store: replay updates
- Obligation coverage → Evidence checker: coverage constraints
- Evidence checker → Incremental transitions: full-check agreement
- Evidence checker → Utility and reward: valid terminal H
- ProofLattice environment → Set-generation trainer: enumerable states
- Evidence checker → Set-generation trainer: legality and verdicts
- Incremental transitions → Set-generation trainer: ADD/undo actions
- Utility and reward → Set-generation trainer: training reward
- Set-generation trainer → GAFlowNet learner: trains learner arm
- GAFlowNet learner → Exact distributional evaluation: evaluated exactly
- Set-generation trainer → Gate-3 selector portfolio: candidate policies
- Corpus and LoCoMo inputs → Stage A provenance ingestion: raw conversations and corpora
- Stage A provenance ingestion → Stage B graph construction: accepted provenance records
- Stage B graph construction → Replayable graph store: committed graph updates
- Replayable graph store → Evidence retrieval and fusion: graph and corpus evidence
- Evidence retrieval and fusion → Answerability and risk gate: fused evidence pool
- Answerability and risk gate → Reader orchestrator: gated context
- Evidence checker → Gate-3 selector portfolio: selection validity
