Modules¶
The public Python API of v2: text in, checked documents out; documents in, text out. All of it runs in the DSL
CLI (cli-native, TypeScript): parsing, checking, compiling and decompiling. There is no Python model of a
composite, so a Python tool that builds composites targets the DSL text, where the result is checked, reviewed
and documented (docs/v2/design.md, section 5.3).
compile_text/compile_file:.pblangtext -> parse -> check -> a process-bigraph{"schema", "state"}document or a CompositeSpec mapping. An error-level finding stops the compile (CompileErrorcarries every finding); warnings and infos come back on the result.decompile: a document or a CompositeSpec mapping -> canonical.pblangtext plus sidecar assets.
Documents cross the CLI boundary as JSON in bigraph_schema.json_codec's encoding (numpy arrays tagged), with
tuples tagged as {"__tuple__": true, "data": [...]} so that they survive too.
CompileError
¶
Bases: Exception
The text did not pass the checker; diagnostics holds every finding, errors first.
Source code in process_bigraph_lang/v2/api.py
56 57 58 59 60 61 62 | |
Compiled
dataclass
¶
What compile_text / compile_file return: the artifact and the findings that did not stop the compile.
Source code in process_bigraph_lang/v2/api.py
36 37 38 39 40 41 42 43 44 45 | |
Printed
dataclass
¶
What decompile returns: the .pblang text and its sidecar assets (<name>.assets/...), by path.
Source code in process_bigraph_lang/v2/api.py
48 49 50 51 52 53 | |
compile_file(path, *, registry=None, manifests=None, to='document', strict=False, force=False, addresses='import')
¶
Compile a .pblang file; file(...) references resolve next to it. force compiles despite the checker's
errors (parse errors still stop it): the escape for documents that rely on defaults the checker flags.
Source code in process_bigraph_lang/v2/api.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
compile_text(text, *, registry=None, manifests=None, to='document', strict=False, force=False, assets=None, addresses='import')
¶
Compile v2 text. assets holds the sidecar files file(...) references name, by path.
Source code in process_bigraph_lang/v2/api.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
decompile(mapping, *, name='document', registry=None, manifests=None)
¶
Canonical .pblang text (and sidecar assets) for a document or a CompositeSpec mapping (told apart by keys).
Source code in process_bigraph_lang/v2/api.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
dumps(document)
¶
bigraph_schema.json_codec encoding, plus tuples tagged so that they come back as tuples.
Source code in process_bigraph_lang/v2/api.py
152 153 154 | |
Interface declarations as data: a minimal stage-A describe and the registry the normalizer resolves addresses in.
describe_module imports a Python module once (the publish-time step; authoring never imports) and turns every
step/process class it exposes into an InterfaceDecl: the address in portable local:!module.Class form, the
config_schema, and the ports obtained by calling inputs()/outputs() with the class standing in for self
(ports that depend on an instance are marked dynamic_ports). Types stay in bigraph-schema's own form. The
InterfaceRegistry holds declarations and reads and writes the JSON interface manifest (pbg-interfaces/1, a
format shared with other tools; the earlier pblang-manifest/0 is still read), which the TypeScript checker, printer
and binder consume; render_interfaces has the CLI print the .pblang header file.
ConfigField
dataclass
¶
One entry of a config_schema: the type in bigraph-schema form and its default, when it has one.
Source code in process_bigraph_lang/v2/interfaces.py
37 38 39 40 41 42 | |
InterfaceDecl
dataclass
¶
A process/step interface as a manifest entry: address, config fields, ports (bigraph-schema forms).
Source code in process_bigraph_lang/v2/interfaces.py
45 46 47 48 49 50 51 52 53 54 55 56 57 | |
InterfaceRegistry
dataclass
¶
Declarations by address: the manifest the CLI reads, and what the normalizer resolves edges in.
Source code in process_bigraph_lang/v2/interfaces.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
lookup(address)
¶
By exact address; else by unique short name (local:Name, or a class re-exported from another module).
Source code in process_bigraph_lang/v2/interfaces.py
125 126 127 128 129 130 131 132 133 134 | |
describe_class(cls, module_name=None, name=None)
¶
The declaration of one step/process class.
Source code in process_bigraph_lang/v2/interfaces.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
describe_module(module_name)
¶
Declarations for the step/process classes a module defines or re-exports (classes of its own package only).
Source code in process_bigraph_lang/v2/interfaces.py
66 67 68 69 70 71 72 73 74 75 | |
render_interfaces(decls, module_name)
¶
The .pblang header file of a module's declarations, as the CLI prints it.
Source code in process_bigraph_lang/v2/interfaces.py
141 142 143 144 145 146 147 148 149 150 151 | |
short_name(address)
¶
Name of local:!pkg.mod.Name, local:Name or Name.
Source code in process_bigraph_lang/v2/interfaces.py
60 61 62 63 | |
describe-model for SBML: a model file's interface as data (see docs/v2/design.md, section 5.6).
describe_sbml reads an SBML file with the standard library's XML parser (no libsbml, no process code) and
returns a ModelHeader: the model's time unit, compartments, species (as concentrations unless the species has
only substance units) and parameters, each with its value and its units composed from the model's unit
definitions in a pint-readable spelling, plus the counts a solver cares about (reactions, events, rules) and the
SBML level, version and packages. to_dict is the JSON form (pblang-model/0), which the CLI renders as the
.pblang model header (print_model_header).
describe_sbml(path)
¶
The model header of an SBML file.
Source code in process_bigraph_lang/v2/sbml.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
print_model_header(header)
¶
The .pblang model header: a generated declaration to import, not a composite (rendered by the CLI).
Source code in process_bigraph_lang/v2/sbml.py
169 170 171 172 173 174 175 176 | |
Equivalence of composite documents modulo representation.
Two documents are equivalent when they realize the same composite. normalize_document rewrites a document
into one canonical shape: types are pushed through bigraph-schema (core.access + core.render(defaults=True)),
addresses become protocol:data strings, wires become lists, tuples and arrays become lists, runtime keys
(instance, _contract, the root global_time) are dropped, and the edge entries of the schema half are folded
into the state half. equivalent compares two normalized documents; diff_documents explains a difference.
deep_equal(a, b, *, strict=False, rel_tol=1e-09)
¶
Structural equality that tolerates numpy arrays and float noise.
With strict=False (the normalizer's mode) tuples equal lists and ints equal floats; with strict=True
container types and numeric types must match exactly (the v1 parity tests use this).
Source code in process_bigraph_lang/v2/normalize.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
diff_documents(a, b, core, limit=200, registry=None)
¶
A readable account of how two documents differ after normalization (empty when equivalent).
Source code in process_bigraph_lang/v2/normalize.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
is_edge_node(value)
¶
A step/process node in the state half (its _type says so, or it carries an address).
Source code in process_bigraph_lang/v2/normalize.py
41 42 43 | |
is_site(value)
¶
A template site: {"_type": "site", "_sort": ..., "_default"?: ...}.
Source code in process_bigraph_lang/v2/normalize.py
36 37 38 | |
normalize_document(doc, core, registry=None)
¶
The canonical shape of a document (see the module docstring). core is a bigraph-schema core. With a
registry, an edge's _inputs/_outputs that merely repeat its interface's face are dropped (process-bigraph
merges them with interface(), so they carry no information).
Source code in process_bigraph_lang/v2/normalize.py
49 50 51 52 53 54 55 56 57 58 59 60 | |