Library Reference
This page lists the current native workflow surface and the frozen pure-Python oracle used for differential testing.
Workflow
| Function | Purpose | Returns |
|---|---|---|
adapt(raw, adapter, *, mode="strict", target=None, source_key=None, max_candidates=None, workers=1) |
Adapt one planner payload | list[dict] |
ingest(raw, adapter, task, *, mode="strict", max_candidates=None, workers=1) |
Adapt and collect in-memory input | NativePredictions |
ingest_file(raw_path, adapter, task_path, *, mode="strict", max_candidates=None, workers=1) |
Read, adapt, and collect in Rust | NativePredictions |
score(predictions, task, stocks, *, match_level="full", acceptable_route_match="prefix", execution_stats=None, workers=1) |
Consume predictions and score them | NativeEvaluation |
analyze(evaluation, *, ks=..., prefix_depths=..., n_boot=10000, seed=42, workers=1) |
Calculate metrics and intervals | dict |
analyze_file(evaluation_path, *, ..., execution_stats_path=None) |
Read and analyze an evaluation in Rust | dict |
evaluate(raw_path, benchmark_path, stock_path, output_dir, *, ...) |
Evaluate raw planner output and write release artifacts | timing and throughput dict |
| Function | Purpose | Returns |
|---|---|---|
adapters::adapt_candidates_with_workers(...) |
Adapt one planner payload | Result<Vec<Candidate>> |
adapt::ingest(...) |
Adapt and collect an in-memory Value |
Result<Predictions> |
adapt::ingest_file(...) |
Stream, adapt, and collect an artifact | Result<Predictions> |
score::score_owned(...) |
Consume predictions and score them | Result<Evaluation> |
analyze::analyze(...) |
Calculate metrics and intervals | Result<AnalysisReport> |
evaluate::evaluate_files(...) |
Evaluate raw planner output and write release artifacts | Result<EvaluationRunStats> |
| Function | Purpose | Returns |
|---|---|---|
adapt_route(raw_route, adapter) |
Adapt one raw route | Route | None |
adapt_routes(raw_payload, adapter) |
Keep successful routes | list[Route] |
adapt_candidates(raw_payload, adapter) |
Preserve ranked failures | list[Candidate] |
collect_candidates(candidates, task) |
Map candidates onto targets | dict[str, list[Candidate]] |
ingest_candidates(raw_payload, adapter, task) |
Adapt and collect | dict[str, list[Candidate]] |
score(predictions, task, constraint_checkers=...) |
Score Pydantic candidates | Evaluation |
analyze(evaluation, ks=..., n_boot=10000) |
Calculate metrics | AnalysisReport |
Adapter names are stable lowercase strings: aizynthfinder, askcos, directmultistep, dreamretroer, molbuilder, multistepttl, paroutes, retrochimera, retrostar, synllama, synplanner, syntheseus, and ursa.
Native Handles
NativePredictions exposes:
write(path)to write JSON or JSON gzip from Rustto_dict()to create a Python snapshotjson()to create a JSON string
score consumes the prediction payload. Later access through the old handle raises RuntimeError.
NativeEvaluation exposes the same materialization methods plus metric_label(). Analysis borrows the evaluation because its result is small.
Rust callers own Predictions, Evaluation, and AnalysisReport directly and use Serde for explicit serialization.
Core Models
| Model | Purpose |
|---|---|
Route, Molecule, Reaction |
Canonical route tree |
Candidate, FailureRecord |
Adaptation accounting |
Target, Constraint, Task |
Problem definition |
ScoredCandidate, TargetResult, Evaluation |
Scored output |
MetricSummary, RuntimeSummary, AnalysisReport |
Analysis output |
ExecutionStats |
Optional per-target runtime input |
The Python boundary represents individual models as JSON-compatible dictionaries. Corpus-sized prediction and evaluation collections remain native handles.
Producer Integration
| Function | Purpose | Returns |
|---|---|---|
load_task(path, chemistry=False) |
Read and structurally validate a trusted schema-2 task | normalized dict |
validate_task(value, chemistry=True) |
Validate an in-memory task, including target chemistry by default | normalized dict |
write_task(value, path) |
Chemistry-check and write a task | None |
resolve_stock_bindings(value) |
Apply default and per-target constraints | target-to-stock dict |
load_stock(path, representation="smiles") |
Read planner SMILES or scoring InChIKeys | sorted list[str] |
validate_execution_stats(value) |
Validate per-target wall and CPU times | normalized dict |
write_execution_stats(value, path) |
Validate and write execution statistics | None |
create_manifest(action, sources, outputs, root_dir, *, ...) |
Hash producer inputs and outputs | manifest dict |
create_planner_manifest(action, adapter, raw_results_path, sources, root_dir, *, ...) |
Create a project-ingest-compatible planner manifest | manifest dict |
verify_manifest(manifest_path, root_dir, *, lenient=False, ...) |
Check lineage and physical hashes strictly by default | verification dict |
verify_planner_manifest(manifest_path, root_dir, *, ...) |
Check hashes and project-ingest directives | verification dict |
These functions expose retrocast-core schema and provenance behavior to Python runners. They do not recreate the Rust models as Python classes.
Task files have an explicit trust boundary. Ordinary loads check the schema and constraint structure without repeating RDKit work. validate_task checks chemistry unless disabled, and write_task always verifies that every target SMILES is valid and produces the declared InChIKey.
Manifest creation requires every source and output file to exist. An output with content_type="unknown" can omit value, so large planner results are hashed from disk without a second Python-to-Rust serialization. Known content types require either value or an explicit content_hash. Lenient verification remains available only when requested for historical manifests.
Chemistry
| Function | Purpose |
|---|---|
canonicalize_smiles(smiles, remove_mapping=False, ignore_stereo=False) |
Canonicalize with RDKit C++ |
get_inchi_key(smiles, level="full") |
Calculate an InChIKey |
reduce_inchi_key(inchikey, level) |
Reduce to no_stereo or connectivity |
molecular_descriptors(smiles) |
Return heavy atoms, molecular weight, and chiral centers |
| Function | Purpose |
|---|---|
chem::canonicalize(...) |
Canonicalize with the RDKit C++ bridge |
chem::inchi_key(...) |
Calculate an InChIKey |
route::reduce_inchikey(...) |
Reduce an InChIKey to a match level |
chem::descriptors(...) |
Calculate molecular descriptors |
| Function | Purpose |
|---|---|
retrocast.chem.canonicalize_smiles(...) |
Canonicalize with Python RDKit |
retrocast.chem.get_inchi_key(...) |
Calculate an InChIKey |
retrocast.chem.reduce_inchi_key(...) |
Reduce an InChIKey to a match level |
No RDKit object crosses the Rust or Python API. Invalid chemical input raises ValueError in Python and returns EngineError in Rust.
Artifact I/O
task = retrocast.load_task("benchmark.json.gz")
payload = retrocast.read_json("results.json.gz")
retrocast.write_json_gz(payload, "results-copy.json.gz")
predictions.write("candidates.json.gz")
evaluation.write("evaluation.json.gz")
use retrocast_core::io::{read_json, write_json};
let evaluation: Evaluation = read_json(&path)?;
write_json(&output_path, &evaluation)?;
from retrocast.io import save_collected_candidates, save_evaluation
save_collected_candidates(predictions, "candidates.json.gz")
save_evaluation(evaluation, "evaluation.json.gz")
read_json and write_json infer gzip from the path. write_json_gz always uses RetroCast's deterministic, human-readable gzip representation. Native handles write schema-v2 artifacts without first materializing them in Python.
Runtime Identity
print(retrocast.__version__)
print(retrocast.__engine__) # "rust"
print(retrocast.engine_info())
println!("{}", retrocast_core::VERSION);
println!("{}", retrocast_core::chem::version());
print(retrocast.__version__)
engine_info() reports the RetroCast version, RDKit C++, and the linked RDKit version.
Errors
- Python uses
ValueErrorfor invalid chemistry, malformed JSON data, or invalid producer schemas;OSErrorfor missing or unreadable artifacts; andRuntimeErrorfor adapter or workflow failures. - Rust returns
retrocast_core::error::EngineErrorfrom core operations.
See Error Handling for stable failure codes and candidate-level accounting.