Agent context: CRN-craft
Start with README.md, architecture, crn-craft describe
(crn-craft.describe/1.0) and the contracts. Release 0.7.0
merged the former network engine and rules engine into one; its
implementation log records every step and
deviation. Older campaign logs describe the engines as they were then.
The one engine
- One crate,
crn-craft; the engine is the modulecrn_craft::rules. The cratecrn-craft-rulesis a deprecated facade (pub use crn_craft::rules::*) that keeps 0.6.0 paths compiling. The command line iscrn-craft-cli; Python isbindings/pythonpluspython/crn_craft. Default engine MSRV 1.85.integrations/jobs(1.88),integrations/diffsol(1.89) andvalidation/parameter-optimization/workerare separate workspaces with their own lockfiles; keep them out of the default dependency gate. - One model format:
crn-craft.model/1.0. Attribute-free types are ordinary species; attributed types, patterns withwhereandfactor, observables, whole-rulepropensityexpressions, continuous variables and a patterncountfor higher-order reactions are in the model reference. A networkcrn-craft.model/0.1is read only through the converter (crn-craft convert,crn_craft.convert). - One request and result:
crn-craft.run/1.0andcrn-craft.result/1.0;fsprequests givecrn-craft.fsp-result/1.0. Therules-model0.1–0.4 andrules-run0.1–0.6 documents are still read and replay byte for byte. Amodel/1.0model needs arun/1.0request. - Methods:
tree(the default),static_direct,next_reaction,mtdna_direct,thinning,tau,binomial,hybrid, andfsp. Static Direct has the selectorslinear,composition_rejection,sorting,rssa_crandauto(therun/1.0default) (exact methods). One random number generator: ChaCha8, one stream per replicate. - Features on the flat view of a closed model (
crn_craft::rules::FlatView): finite state projection, analysis (analysis/1.0), ODE kinetics forcrn-diffsol, GillesPy2 export. Models without a closed set of species are refused withCRN-R017. - Python:
import crn_craft as crnwrites the 1.0 contracts, asks for the quantiles 0.025, 0.5 and 0.975 and leaves the selector toauto.crn_craft.rulesis the 0.6.0 API with its defaults (therules-*versions, the linear scan, no quantiles).Result.savewrites markdown orcrn-craft.report/1.0. Parameter sweeps usebind_parameters(parameter sweeps). The buildercrn.Modelwrites species with attributes too (add_species(..., attributes=[...]),add_initial,add_observable,crn.pattern,crn.copy,crn.new,crn.mass_action).ensembledefaults tomax_events=10**8with the sampling budget following it, andsimulate()warns withIncompleteEnsembleWarning(or raises withstrict=True) when replicates end early.
Where things are
- Engine sources:
crates/crn-craft/src/rules/(model, expressions, lowering, methods, selectors, flat view, converter, generators) andcrates/crn-craft/src/(FSP, analysis, kinetics, export, archives, strict JSON, diagnostics, samplers, discovery and check). - Tests:
crates/crn-craft/tests/. Stored requests undertests/stored/(invariant I1) and generated-code fixtures undertests/generated/(I3); never edit either by hand. - Schemas:
schemas/, written fromcrn-craft describe KIND. - Validation scripts:
validation/. The merge gates, the 0.6.0 references and their declarations:validation/merge/(RESULTS.md). - The frozen 0.6.0 user manual, run in CI:
validation/compat/manual-0.6.0.md.
Rules for changes
- Strict input everywhere: unknown fields and duplicate keys are errors; diagnostic codes are stable. A new code takes the next free number and goes into diagnostics.
- Schemas come from Rust types. A change to a delivered contract’s shape needs a new version, and the older versions keep their meaning.
- A new feature goes behind
model/1.0orrun/1.0; the storedrules-runrequests must keep replaying byte for byte (stored_requests.rs,static_direct_defaults.rs). - A new numerical policy or selector gets its own sampler identity and an
exact-law check before any timing.
validation/merge/check_laws.pyruns the law gate against the committed references. - Declare targets, sizes, seeds and tolerances before running; keep failed rows; never loosen a rule after seeing a result.
- Profile with Static Direct, then the generated event loop, before adding a specialized kernel (checklist).
- Run
cargo fmt, clippy with-D warnings,cargo test --release --workspace --locked, rustdoc with-D warnings, ruff, and the validation scripts that CI names, each normally and underpython -Owith identical reports.
Approximate methods (tau, binomial, hybrid) carry their own sampler
identities; FSP reports leakage and error terms and never renormalizes.
Importers accept explicit subsets and conventions only. Incomplete ensembles
withhold statistics; wall time and cancellation are outside fixed-work
reproducibility. A successful run is not biological validation.
The Python package is on PyPI (pip install crn-craft) and the crates
crn-craft, crn-craft-rules and crn-craft-cli (cargo install crn-craft-cli --locked) are on crates.io; the diffsol integration and the
job worker build from the repository.
Optimization lessons
Use C1–C4 for runnable calibration,
optional BDF and SQP fitting, MODE and MAP-Elites oscillator searches, and
bounded rules inference. They call the library and the command line. Their
SSA runs use Static Direct with its default selector; C1’s
--include-next-reaction adds a second exact method with its own stream.
Validation separates completed
checks from fitted-model quality.
C5–C10
reconstruct published studies with Python fcmaes ask/tell on the same engine:
count-distribution fitting, joint-count model selection, a virtual reactor,
Fisher experiment design, a PEtab calibration and a 36-parameter fit. Run them
with tutorials/optimization/run.py C5 to C10 (--help lists a chapter’s
options); the shared driver is tutorials/optimization/publications/search.py
(proposal traces, --resume-from replay), the fixtures are pinned in
examples/publication_tutorials/sources.json, and
crn_craft.sensitivities.forward_sensitivities and the retained argument of
crn_craft.prepare_fsp are the engine features they use. C7, C9 and C10 need
the optional crn-diffsol concentrations interface
(contracts).