Python
Parse DIPL text or load a source, DIPfile project, or DIPH5 snapshot.
Basic examples
Parse a small parameter model and read a derived value:
from scinumtools3.dip import DIP
parser = DIP()
parser.add_string(
"distance float = 12 m\n"
"duration float = 3 s\n"
"speed float = ({?distance} / {?duration}) m/s\n"
)
env = parser.parse()
print(env["speed"].value, env["speed"].units) # 4.0 m*s-1
Override an input before evaluation:
from scinumtools3.dip import DIP
parser = DIP()
parser.add_string("simulation.steps int = 100")
parser.add_override_string("simulation.steps = 200")
env = parser.parse()
print(env["simulation.steps"].value) # 200
Common workflows
Task |
Call chain |
Result |
|---|---|---|
Load one artifact |
|
|
Compose live inputs |
|
|
Apply overrides before evaluation |
|
|
Read a known path |
|
|
Discover values by path or tag |
|
|
Describe or preview changes |
|
|
Persist or export |
|
DIPH5 or generated parameter file |
Generate a report |
|
Report file |
Compare snapshots |
|
|
Run an adapter |
|
Written paths and optional DIPH5 snapshot |
from scinumtools3.dip import (
DIP, ExportFormat, PreviewOverride, PreviewOverrideKind,
compare_diph5, describe, preview, render_comparison,
)
env = DIP.load("DIPfile") # Environment
speed = env["physics.speed"] # Cursor
print(speed.value, speed.units)
print(env.select_paths("?physics.", tags_all=["runtime"]))
print(describe(env, "physics.speed").value_text)
candidate = preview(
"parameters.dip",
[PreviewOverride(PreviewOverrideKind.Text, "physics.speed = 3 m/s")],
) # PreviewResult
print(candidate.candidate_valid, candidate.comparison.changed)
env.save("run.diph5")
env.generate(ExportFormat.JSON, "parameters.json")
changes = compare_diph5("before.diph5", "run.diph5")
print(render_comparison(changes, max_details=10))
DIP.load() and the parser calls return native Python objects; no manual
cleanup is required. Invalid DIPL, missing paths, and failed writes raise
exceptions. Use diagnostic_from_exception(error) when structured parser
diagnostics are needed.
See the Python binding guide and Python API reference for environments, cursors, adapters, comparison, and reports.
DIPL developer tools. The Python binding evaluates DIPL through the native
parser, so invalid input raises a parse error. It does not currently expose
standalone formatter, validator, or linter helpers. Use snt dip format,
snt dip validate, and snt dip lint, or the C++ tooling API, for those
workflows.
Current limitations and differences
Compared with the canonical C++ implementation:
Python wraps parsing, inspection, callbacks, adapters, persistence, and reports, but does not wrap the C++
EditSession,ArchiveEditSession,SetupSession, orExperimentclasses.Original block retention can be requested through
DIP.load(..., retain_block_inputs=True). The Pythonparse()method only exposes the dependency-graph recording option.Standalone formatter, validator, and linter helpers are not exposed. Parsing still validates the model. Use
snt dip format,snt dip validate,snt dip lint, or the C++ tooling API for those operations.
Binding reference
This is a lookup index, not a sequence to read from top to bottom. Use Common workflows above to choose a task, then find the exact Python name for that task below. Properties are shown without parentheses; callable names include their arguments. The linked API reference documents complete signatures and result fields.
Parser and input registration
DIP()andDIP.load(path, record_dependency_graph=False, retain_block_inputs=False).add_string(source_code),add_file(path, source_name=""), andadd_source(source_name, source_file).add_project(project_file)andadd_unit(name, unit).add_schema_string(name, source_code)andadd_schema_file(name, source_file).add_override_string(source_code)andadd_override_file(source_file).add_function_value(name, callback)andadd_function_nodes(name, callback).parse(record_dependency_graph=False),to_string(), and the context manager methodsenter()andexit().
Environment and persistence
env[path]returns aCursor.env.nodes,env.size,env.schemas,env.schema_manifest,env.source_manifest, andenv.output_plan.env.applied_schemas(path)andenv.contributing_schema(path).env.select(...),env.select_paths(...),env.request_group(...), andenv.request_value(path, to_units="", as_numpy=False).env.load(file),env.save(file),env.generate(format, file), andenv.generate_report(format, file, ...).ExportFormatvaluesCPP,C,FORTRAN,RUST,R,JULIA,JSON,TOML, andYAML.ReportFormatvaluesTEX,PDF,MARKDOWN,RST,HTML,TYPST,TEXT, andJSONwhere report support is built.generate_reportkeywordsinput_label,intro_file,tex_compiler,title,author,date,version, andinclude_cheatsheet.env.to_string(),str(env), andrepr(env).
Cursor traversal
cursor[name]andcursor[index];name in cursortests a named child.children(),entries(),entry_names(),elements(),items(), andhas_item(name).Properties
path,kind,node_type,shape,value,units,metadata,provenance,link_source, andlink_target.to_numpy()andto_string().
Selected value nodes
Properties
name,node_type,dtype,value,units,shape,tags,schema_id,override,metadata,link_source, andlink_target.to_numpy()andto_string().
Inspection
detect_artifact(path),open_artifact(path, record_dependency_graph=False), andreload_artifact(env, path, ...).inspect_value(env, path),inspect_values(env), andinspect_capabilities(env, path).inspect_dependency_graph(env),inspect_table(env, path), andinspect_tables(env).read_value_slice(env, path, ranges, as_numpy=False).describe(env, path, max_value_elements=16),list_descriptions(env, query="?", ...),schema_hierarchy(env),override_contract(env, path), andpreview(input, overrides, ...).diagnostic_from_exception(error)returns the structured diagnostic attached to a DIP exception, when present.ValueNode,ValueNodeData,CursorEntry,PathKind,ArtifactKind,ValueChangeKind,ValueChange,ValueInspection, andInspectionCapabilities.CompositionKind,OperationType,CompositionNode,CompositionGraph,DependencyEventKind,DependencyEdge,DependencyEvent, andDependencyGraph.TableColumnInspection,TableInspection,SourceLocation,DiagnosticSeverity, andDiagnostic.SemanticDescription,OverrideTargetKind,OverrideContract,SemanticList,SchemaMemberInspection,MetadataConstraintInspection,SchemaDefinitionInspection,SchemaApplicationInspection,SchemaValueAssociation, andSchemaHierarchyInspection.PreviewOverrideKind,PreviewOverride, andPreviewResult.
Comparison, adapters, and command facade
compare(before, after, options),compare_diph5(before, after, options), andrender_comparison(result, max_details=50).ComparisonOptionsfieldsscopeandmax_array_examples;ComparisonScope.EffectiveandFull.Adapter,AdapterContext,OutputPlan,resolve_output_plan,run_adapter,run_adapter_project, andrun_adapter_snapshot.Adapter.plan(env, context),plan_resolved(env, outputs, context), anddescribe_outputs(env, outputs).AdapterContext.add_text(path, text),add_binary(path, data), andadd_stream(path, callback).OutputPlan.add_node,replace_node,add_value,replace_value,select, andmappings;OutputMappingexposesid,target,key,source_path,rule,origin,replacements,dependencies,active,value, andvalue_node.ExistingOutputPolicy.Reject,ReplaceRegistered, andSyncRegistered.scinumtools3.api.dip.DIPParse()providesargument_add(add_type, values),argument_request(path),argument_load(file),argument_save(file),argument_generate(format, file),argument_tags(tags),argument_print(),argument_value(type=""), andexecute() -> str.DIPCompare(before, after)providesset_options(options),set_max_details(count),compare() -> ComparisonResult, andexecute() -> str.