lmbio reference
Every host type, method, flag and exit code of lmbio, taken from schema/lmbio.dsl.json, cpp/main.cpp and the README of the repository at main (version 0.1.3).
Context objects
| Name | Type | Purpose |
|---|---|---|
| bio | Bio | The only context object: creates or imports models and provides assertions and output |
The schema declares no host functions; everything is a method on bio, a Model or a Result.
Host types
| Type | Methods | Role |
|---|---|---|
| Bio | 5 | Entry point |
| Model | 19 | Reaction network builder and solver front end; builder methods return the Model so calls chain |
| Result | 13 | Matrix with named columns: time, species in creation order, then parameters in identifier order |
Bio methods
| Call | Returns | Purpose |
|---|---|---|
| bio.model(string name) | Model | Create an empty model |
| bio.load_sbml(string path) | Model | Import a model from the supported SBML subset |
| bio.assert_close(float a, float b, float absolute_tolerance) | void | Stop the run unless a and b agree within the absolute tolerance |
| bio.assert_true(bool condition) | void | Stop the run unless the condition holds |
| bio.print(string text) | void | Script output |
Model methods
| Call | Returns | Purpose |
|---|---|---|
| model.compartment(string id, float size) | Model | Fixed, positive compartment volume |
| model.species(string id, string compartment, float initial) | Model | Species with an initial concentration |
| model.param(string id, float value) | Model | Kinetic parameter |
| model.reaction(string id, string equation, string rate) | Model | Stoichiometry such as A + B -> 2 C and a rate expression such as k*A*B; empty sides give sources and sinks |
| model.reversible(string id, string reverse_rate) | Model | Add a reverse rate to an existing reaction |
| model.mass_action(string id, string equation, string k) | Model | Mass-action law k*V*A^2 for ODEs and propensity k*A*(A-1) for SSA from one call (added in 0.1.1) |
| model.mass_action_reversible(string id, string equation, string kf, string kr) | Model | The same with a mass-action reverse rate (added in 0.1.1) |
| model.rule(string id, string expression) | Model | Assignment rule |
| model.rate_rule(string id, string expression) | Model | Differential rule |
| model.set(string id, float value) | Model | Change an initial species value, a parameter or a compartment size (compartments from 0.1.1) |
| model.get(string id) | float | Query the same values |
| model.set_state(Result result) | Model | Restart from the last row of a result, for example before a dose (added in 0.1.1) |
| model.tol(float rtol, float atol) | Model | Configure solver error control |
| model.validate() | Model | Validate the network |
| model.simulate(float t0, float t1, int points) | Result | CVODE BDF time course |
| model.steady_state() | Result | Steady state with residual verification |
| model.ssa(float t1, int points, int seed) | Result | Gillespie direct simulation with an integer seed |
| model.sensitivity(string parameter, float t0, float t1, int points, float relative_step) | Result | Central finite-difference derivatives |
| model.save_sbml(string path) | void | Write supported semantics as SBML L3V2 MathML |
Expression strings
Kinetic laws and rules are expression strings. They support arithmetic, powers, scientific notation and common elementary functions; the README names exp, log, sin, sqrt, min, max, sign and floor among them.
Result methods
| Call | Returns | Purpose |
|---|---|---|
| result.value(string id, int row) | float | Named value at a zero-based row |
| result.final(string id) | float | Named value in the last row |
| result.rows() | int | Number of rows |
| result.cols() | int | Number of columns |
| result.column(int index) | string | Column name |
| result.get(int row, int col) | float | Indexed value |
| result.max(string id) | float | Sampled maximum of a column |
| result.time_of_max(string id) | float | First time of the maximum |
| result.min(string id) | float | Sampled minimum (added in 0.1.1) |
| result.integral(string id) | float | Trapezoid area under a column, for example drug exposure AUC (added in 0.1.1) |
| result.crossing(string id, float level) | float | First time a column reaches a level, linearly interpolated (added in 0.1.1) |
| result.append(Result next) | Result | Join consecutive runs; a jump at the joint (a dose) keeps both rows (added in 0.1.1) |
| result.save_csv(string path) | void | Comma-separated matrix with header |
Enumerated values
The lmbio schema defines no enumerated string values. Reaction equations use the arrow form A + B -> 2 C; either side may be empty.
Limits
- Kinetic laws are reaction extents (substance per time); a concentration species receives stoichiometry times rate divided by compartment volume. SBML hasOnlySubstanceUnits species use amounts.
- Boundary and constant species do not change through reactions. Local kinetic parameters shadow global symbols in their reaction.
- Assignment rules are evaluated in dependency order; cycles and unknown names are errors.
- SBML is a subset with no conformance claim: the reader handles L3V1 and L3V2 fixed compartments, species, parameters, reactions, local parameters, arithmetic MathML and assignment and rate rules. Packages, events, delays, algebraic rules, initial assignments, function definitions, piecewise, dynamic compartments and conversion factors are rejected with a message. Units are not converted or checked.
- There are no events. Doses and other discontinuities are modelled by restarting a run from the previous end state with set_state and append; time-dependent inputs can use min, max, sign and floor in rate expressions, but such models cannot be exported to SBML.
- SSA: species values are molecule counts in unit-volume compartments and rate expressions are propensities. Initial counts and stoichiometric coefficients must be nonnegative integers. Hand-written propensities must include combinatorics, k*X*(X-1) for 2 X ->; mass_action writes them for you. No rules or explicit time dependence. mass_action propensities are not stored in SBML; a reloaded model uses its ODE law for SSA.
- Sensitivities are central finite differences of two extra CVODE runs, not CVODES forward sensitivities: pick a step that dominates solver error or tighten tol.
- Model and result objects live until the host exits; a program may use at most 4096 MiB in total by default (LMBIO_MAX_MEMORY_MB changes it) and stops with a run error, exit 3, beyond that.
CLI flags
usage: lmbio --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
| Flag | Behavior |
|---|---|
| --version | Print the version |
| --notices | Print the embedded third-party notices (SUNDIALS, pugixml, toolchain runtimes) |
| --lmcode-schema | Print the schema; with --json print the embedded schema JSON. Any other extra argument is a usage error, exit 2 |
| --lmcode-signatures | Print the callable signatures |
| --lmcode FILE [FILE ...] | Load every compiled .dslb program, then run them in order, stopping at the first failure |
| --dry-run --lmcode FILE ... | Check bytecode without running the model or writing files |
| Environment variable | Meaning |
|---|---|
| LMBIO_MAX_MEMORY_MB | Total memory budget in MiB, default 4096 on 64-bit and 256 on 32-bit; a program that needs more stops with a run error, exit 3 |
Exit codes
| Exit | Meaning |
|---|---|
| 0 | Success, also for --version, --notices and the schema flags |
| 2 | Usage error: unknown or missing flags, no file, or an invalid LMBIO_MAX_MEMORY_MB value; the usage text goes to stderr |
| 3 | Bytecode load error or run error: a host validation message, a failed assertion or an exceeded memory budget |
Load and run failures are reported with the phase load or run. After a successful dry run or program run the host reports ok.
Standard library (lmcode_std_v3)
lmbio at main (version 0.1.3) vendors the lmcode_std_v3 catalog with 206 canonical signatures: 83 function signatures and 123 method signatures on 16 standard types. The SDK is pinned in sdk.lock to lmcode-cpp commit 20325f7a13cbb8470af88ae3448bf0e04d40e507. The library is registered by default, needs no import and is callable in any lmbio block next to the bio context. The result sink functions are what fill the result field of the run_lmcode envelope.
Function groups
| Group | Signatures | Purpose |
|---|---|---|
| String | 17 | Byte-string search, slicing, case, split, replace, numeric parsing and glob match |
| Encoding | 4 | Base64 and hexadecimal encode and decode |
| Math | 16 | Integer and float overloads of abs, ceil, floor, max, min, pow, round and sqrt |
| File | 5 | Unrestricted whole-file byte read, write, append, existence test and LF line split |
| Collection constructors | 15 | Create empty lists, maps, queues, stacks and priority queues of int, float and string |
| JSON and templates | 2 | Parse JSON text into a Json value; render a text template from a Json value |
| Result sink | 24 | Set the value that run_lmcode returns as result: one value, or named fields |
| Collection and Json methods | 123 | Methods of the 16 standard types listed below |
| Total | 206 | 83 function signatures plus 123 method signatures |
Standard functions
| Group | Function | Signatures |
|---|---|---|
| String | str_contains | (string, string) -> bool |
| String | str_ends_with | (string, string) -> bool |
| String | str_find | (string, string) -> int |
| String | str_is_float | (string) -> bool |
| String | str_is_int | (string) -> bool |
| String | str_len | (string) -> int |
| String | str_lower | (string) -> string |
| String | str_match | (string, string) -> bool |
| String | str_repeat | (string, int) -> string |
| String | str_replace | (string, string, string) -> string |
| String | str_split | (string, string) -> StrList |
| String | str_starts_with | (string, string) -> bool |
| String | str_substr | (string, int, int) -> string |
| String | str_to_float | (string) -> float |
| String | str_to_int | (string) -> int |
| String | str_trim | (string) -> string |
| String | str_upper | (string) -> string |
| Encoding | str_base64_encode | (string) -> string |
| Encoding | str_base64_decode | (string) -> string |
| Encoding | str_hex_encode | (string) -> string |
| Encoding | str_hex_decode | (string) -> string |
| Math | math_abs | (int) -> int; (float) -> float |
| Math | math_ceil | (int) -> int; (float) -> float |
| Math | math_floor | (int) -> int; (float) -> float |
| Math | math_max | (int, int) -> int; (float, float) -> float |
| Math | math_min | (int, int) -> int; (float, float) -> float |
| Math | math_pow | (int, int) -> int; (float, float) -> float |
| Math | math_round | (int) -> int; (float) -> float |
| Math | math_sqrt | (int) -> int; (float) -> float |
| File | file_append | (string, string) -> void |
| File | file_exists | (string) -> bool |
| File | file_lines | (string) -> StrList |
| File | file_read | (string) -> string |
| File | file_write | (string, string) -> void |
| Collection constructors | float_list | () -> FloatList |
| Collection constructors | float_map | () -> FloatMap |
| Collection constructors | float_pq | () -> FloatPQ |
| Collection constructors | float_queue | () -> FloatQueue |
| Collection constructors | float_stack | () -> FloatStack |
| Collection constructors | int_list | () -> IntList |
| Collection constructors | int_map | () -> IntMap |
| Collection constructors | int_pq | () -> IntPQ |
| Collection constructors | int_queue | () -> IntQueue |
| Collection constructors | int_stack | () -> IntStack |
| Collection constructors | str_list | () -> StrList |
| Collection constructors | str_map | () -> StrMap |
| Collection constructors | str_pq | () -> StrPQ |
| Collection constructors | str_queue | () -> StrQueue |
| Collection constructors | str_stack | () -> StrStack |
| JSON and templates | json_parse | (string) -> Json |
| JSON and templates | template_render | (string, Json) -> string |
| Result sink | lmcode_return_null | () -> void |
| Result sink | lmcode_return_put | (string, bool) -> void; (string, float) -> void; (string, FloatList) -> void; (string, FloatMap) -> void; (string, int) -> void; (string, IntList) -> void; (string, IntMap) -> void; (string, Json) -> void; (string, StrList) -> void; (string, StrMap) -> void; (string, string) -> void |
| Result sink | lmcode_return_put_null | (string) -> void |
| Result sink | lmcode_return_set | (bool) -> void; (float) -> void; (FloatList) -> void; (FloatMap) -> void; (int) -> void; (IntList) -> void; (IntMap) -> void; (Json) -> void; (StrList) -> void; (StrMap) -> void; (string) -> void |
Standard types and methods
| Type | Method | Signature |
|---|---|---|
| FloatList | add | (float) -> FloatList |
| FloatList | at | (int) -> float |
| FloatList | clear | () -> FloatList |
| FloatList | contains | (float) -> bool |
| FloatList | index_of | (float) -> int |
| FloatList | len | () -> int |
| FloatList | set | (int, float) -> FloatList |
| FloatMap | len | () -> int |
| FloatMap | has | (string) -> bool |
| FloatMap | get | (string) -> float |
| FloatMap | get_or | (string, float) -> float |
| FloatMap | set | (string, float) -> FloatMap |
| FloatMap | key_at | (int) -> string |
| FloatMap | remove | (string) -> bool |
| FloatMap | clear | () -> FloatMap |
| FloatMap | keys | () -> StrList |
| FloatMap | values | () -> FloatList |
| FloatPQ | push | (float, float) -> FloatPQ |
| FloatPQ | pop | () -> float |
| FloatPQ | peek | () -> float |
| FloatPQ | len | () -> int |
| FloatPQ | empty | () -> bool |
| FloatPQ | clear | () -> FloatPQ |
| FloatQueue | push | (float) -> FloatQueue |
| FloatQueue | pop | () -> float |
| FloatQueue | peek | () -> float |
| FloatQueue | len | () -> int |
| FloatQueue | empty | () -> bool |
| FloatQueue | clear | () -> FloatQueue |
| FloatQueue | at | (int) -> float |
| FloatStack | push | (float) -> FloatStack |
| FloatStack | pop | () -> float |
| FloatStack | peek | () -> float |
| FloatStack | len | () -> int |
| FloatStack | empty | () -> bool |
| FloatStack | clear | () -> FloatStack |
| FloatStack | at | (int) -> float |
| IntList | add | (int) -> IntList |
| IntList | at | (int) -> int |
| IntList | clear | () -> IntList |
| IntList | contains | (int) -> bool |
| IntList | index_of | (int) -> int |
| IntList | len | () -> int |
| IntList | set | (int, int) -> IntList |
| IntMap | len | () -> int |
| IntMap | has | (string) -> bool |
| IntMap | get | (string) -> int |
| IntMap | get_or | (string, int) -> int |
| IntMap | set | (string, int) -> IntMap |
| IntMap | key_at | (int) -> string |
| IntMap | remove | (string) -> bool |
| IntMap | clear | () -> IntMap |
| IntMap | keys | () -> StrList |
| IntMap | values | () -> IntList |
| IntPQ | push | (int, float) -> IntPQ |
| IntPQ | pop | () -> int |
| IntPQ | peek | () -> int |
| IntPQ | len | () -> int |
| IntPQ | empty | () -> bool |
| IntPQ | clear | () -> IntPQ |
| IntQueue | push | (int) -> IntQueue |
| IntQueue | pop | () -> int |
| IntQueue | peek | () -> int |
| IntQueue | len | () -> int |
| IntQueue | empty | () -> bool |
| IntQueue | clear | () -> IntQueue |
| IntQueue | at | (int) -> int |
| IntStack | push | (int) -> IntStack |
| IntStack | pop | () -> int |
| IntStack | peek | () -> int |
| IntStack | len | () -> int |
| IntStack | empty | () -> bool |
| IntStack | clear | () -> IntStack |
| IntStack | at | (int) -> int |
| Json | kind | () -> string |
| Json | len | () -> int |
| Json | at | (int) -> Json |
| Json | get | (string) -> Json |
| Json | has | (string) -> bool |
| Json | keys | () -> StrList |
| Json | as_string | () -> string |
| Json | as_int | () -> int |
| Json | as_float | () -> float |
| Json | as_bool | () -> bool |
| Json | to_json | () -> string |
| StrList | add | (string) -> StrList |
| StrList | at | (int) -> string |
| StrList | clear | () -> StrList |
| StrList | contains | (string) -> bool |
| StrList | index_of | (string) -> int |
| StrList | join | (string) -> string |
| StrList | len | () -> int |
| StrList | set | (int, string) -> StrList |
| StrMap | clear | () -> StrMap |
| StrMap | get | (string) -> string |
| StrMap | get_or | (string, string) -> string |
| StrMap | has | (string) -> bool |
| StrMap | key_at | (int) -> string |
| StrMap | len | () -> int |
| StrMap | remove | (string) -> bool |
| StrMap | set | (string, string) -> StrMap |
| StrMap | keys | () -> StrList |
| StrMap | values | () -> StrList |
| StrPQ | push | (string, float) -> StrPQ |
| StrPQ | pop | () -> string |
| StrPQ | peek | () -> string |
| StrPQ | len | () -> int |
| StrPQ | empty | () -> bool |
| StrPQ | clear | () -> StrPQ |
| StrQueue | push | (string) -> StrQueue |
| StrQueue | pop | () -> string |
| StrQueue | peek | () -> string |
| StrQueue | len | () -> int |
| StrQueue | empty | () -> bool |
| StrQueue | clear | () -> StrQueue |
| StrQueue | at | (int) -> string |
| StrStack | push | (string) -> StrStack |
| StrStack | pop | () -> string |
| StrStack | peek | () -> string |
| StrStack | len | () -> int |
| StrStack | empty | () -> bool |
| StrStack | clear | () -> StrStack |
| StrStack | at | (int) -> string |
Standard REST and CLI interfaces (current catalog, not yet in this host)
The current lmcode_std_v3 catalog in lmcode-cpp has 226 canonical signatures. The 20 signatures beyond the 206 that lmbio vendors are the former lmcode_std_rest_v1 module: 5 functions and 15 RestExchange methods, together with 10 standard interfaces. lmbio does not ship them yet; it picks them up when it syncs its pinned lmcode-cpp SDK and publishes a release. Until then a lmbio program that calls rest_route or declares a RestGet handler does not compile against the lmbio schema.
| Interface | Signature | Role |
|---|---|---|
| RestGet | (RestExchange exchange) -> void | Handler for GET routes |
| RestPost | (RestExchange exchange) -> void | Handler for POST routes |
| RestPut | (RestExchange exchange) -> void | Handler for PUT routes |
| RestDelete | (RestExchange exchange) -> void | Handler for DELETE routes |
| RestPatch | (RestExchange exchange) -> void | Handler for PATCH routes |
| RestHead | (RestExchange exchange) -> void | Handler for HEAD routes |
| RestOptions | (RestExchange exchange) -> void | Handler for OPTIONS routes |
| RestHandler | (RestExchange exchange) -> void | Generic handler bound by rest_route to an annotation name |
| CliCommand | (RestExchange exchange) -> void | Handler for a command dispatched by rest_cli |
| CliOption | (RestExchange exchange) -> void | Handler for an option dispatched by rest_cli |
| Function | Signature | Behavior |
|---|---|---|
| rest_config | (string, string) -> void | Store a configuration key and value; the keys prefix and base_path set the route prefix and max_body_bytes sets the request body limit |
| rest_route | (string, string, string) -> void | Register method, path template and handler annotation; templates accept {param} and {rest...} or :param and :rest... placeholders |
| rest_serve | () -> void | Request serving after the program body; routes are frozen from this call on |
| rest_stop | () -> void | Stop serving |
| rest_cli | (StrList) -> string | Stateless CLI mode: dispatch an argument vector to options, commands and REST routes and return the response text |
| RestExchange method | Signature | Behavior |
|---|---|---|
| method | () -> string | Request method |
| path | () -> string | Request path |
| query | (string) -> string | Query parameter value, empty when absent |
| has_query | (string) -> bool | Whether a query parameter is present |
| param | (string) -> string | Route template parameter value, empty when absent |
| header | (string) -> string | Request header value; repeated headers are joined with a comma and a space |
| has_header | (string) -> bool | Whether a request header is present |
| body | () -> string | Request body bytes |
| status | (int) -> void | Set the response status; values outside 200..599 are a host error |
| set_header | (string, string) -> void | Set a response header; Content-Length, Connection and Transfer-Encoding are managed by the server |
| send | (string) -> void | Set the response body |
| json | (string) -> void | Set the response body and the Content-Type application/json |
| get | (string) -> string | Read a shared state value, empty when absent |
| set | (string, string) -> void | Write a shared state value |
| increment | (string) -> int | Increment a shared named counter and return it |