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

NameTypePurpose
bioBioThe 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

TypeMethodsRole
Bio5Entry point
Model19Reaction network builder and solver front end; builder methods return the Model so calls chain
Result13Matrix with named columns: time, species in creation order, then parameters in identifier order

Bio methods

CallReturnsPurpose
bio.model(string name)ModelCreate an empty model
bio.load_sbml(string path)ModelImport a model from the supported SBML subset
bio.assert_close(float a, float b, float absolute_tolerance)voidStop the run unless a and b agree within the absolute tolerance
bio.assert_true(bool condition)voidStop the run unless the condition holds
bio.print(string text)voidScript output

Model methods

CallReturnsPurpose
model.compartment(string id, float size)ModelFixed, positive compartment volume
model.species(string id, string compartment, float initial)ModelSpecies with an initial concentration
model.param(string id, float value)ModelKinetic parameter
model.reaction(string id, string equation, string rate)ModelStoichiometry 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)ModelAdd a reverse rate to an existing reaction
model.mass_action(string id, string equation, string k)ModelMass-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)ModelThe same with a mass-action reverse rate (added in 0.1.1)
model.rule(string id, string expression)ModelAssignment rule
model.rate_rule(string id, string expression)ModelDifferential rule
model.set(string id, float value)ModelChange an initial species value, a parameter or a compartment size (compartments from 0.1.1)
model.get(string id)floatQuery the same values
model.set_state(Result result)ModelRestart from the last row of a result, for example before a dose (added in 0.1.1)
model.tol(float rtol, float atol)ModelConfigure solver error control
model.validate()ModelValidate the network
model.simulate(float t0, float t1, int points)ResultCVODE BDF time course
model.steady_state()ResultSteady state with residual verification
model.ssa(float t1, int points, int seed)ResultGillespie direct simulation with an integer seed
model.sensitivity(string parameter, float t0, float t1, int points, float relative_step)ResultCentral finite-difference derivatives
model.save_sbml(string path)voidWrite 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

CallReturnsPurpose
result.value(string id, int row)floatNamed value at a zero-based row
result.final(string id)floatNamed value in the last row
result.rows()intNumber of rows
result.cols()intNumber of columns
result.column(int index)stringColumn name
result.get(int row, int col)floatIndexed value
result.max(string id)floatSampled maximum of a column
result.time_of_max(string id)floatFirst time of the maximum
result.min(string id)floatSampled minimum (added in 0.1.1)
result.integral(string id)floatTrapezoid area under a column, for example drug exposure AUC (added in 0.1.1)
result.crossing(string id, float level)floatFirst time a column reaches a level, linearly interpolated (added in 0.1.1)
result.append(Result next)ResultJoin consecutive runs; a jump at the joint (a dose) keeps both rows (added in 0.1.1)
result.save_csv(string path)voidComma-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

CLI flags

usage: lmbio --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
FlagBehavior
--versionPrint the version
--noticesPrint the embedded third-party notices (SUNDIALS, pugixml, toolchain runtimes)
--lmcode-schemaPrint the schema; with --json print the embedded schema JSON. Any other extra argument is a usage error, exit 2
--lmcode-signaturesPrint 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 variableMeaning
LMBIO_MAX_MEMORY_MBTotal 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

ExitMeaning
0Success, also for --version, --notices and the schema flags
2Usage error: unknown or missing flags, no file, or an invalid LMBIO_MAX_MEMORY_MB value; the usage text goes to stderr
3Bytecode 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

GroupSignaturesPurpose
String17Byte-string search, slicing, case, split, replace, numeric parsing and glob match
Encoding4Base64 and hexadecimal encode and decode
Math16Integer and float overloads of abs, ceil, floor, max, min, pow, round and sqrt
File5Unrestricted whole-file byte read, write, append, existence test and LF line split
Collection constructors15Create empty lists, maps, queues, stacks and priority queues of int, float and string
JSON and templates2Parse JSON text into a Json value; render a text template from a Json value
Result sink24Set the value that run_lmcode returns as result: one value, or named fields
Collection and Json methods123Methods of the 16 standard types listed below
Total20683 function signatures plus 123 method signatures

Standard functions

GroupFunctionSignatures
Stringstr_contains(string, string) -> bool
Stringstr_ends_with(string, string) -> bool
Stringstr_find(string, string) -> int
Stringstr_is_float(string) -> bool
Stringstr_is_int(string) -> bool
Stringstr_len(string) -> int
Stringstr_lower(string) -> string
Stringstr_match(string, string) -> bool
Stringstr_repeat(string, int) -> string
Stringstr_replace(string, string, string) -> string
Stringstr_split(string, string) -> StrList
Stringstr_starts_with(string, string) -> bool
Stringstr_substr(string, int, int) -> string
Stringstr_to_float(string) -> float
Stringstr_to_int(string) -> int
Stringstr_trim(string) -> string
Stringstr_upper(string) -> string
Encodingstr_base64_encode(string) -> string
Encodingstr_base64_decode(string) -> string
Encodingstr_hex_encode(string) -> string
Encodingstr_hex_decode(string) -> string
Mathmath_abs(int) -> int; (float) -> float
Mathmath_ceil(int) -> int; (float) -> float
Mathmath_floor(int) -> int; (float) -> float
Mathmath_max(int, int) -> int; (float, float) -> float
Mathmath_min(int, int) -> int; (float, float) -> float
Mathmath_pow(int, int) -> int; (float, float) -> float
Mathmath_round(int) -> int; (float) -> float
Mathmath_sqrt(int) -> int; (float) -> float
Filefile_append(string, string) -> void
Filefile_exists(string) -> bool
Filefile_lines(string) -> StrList
Filefile_read(string) -> string
Filefile_write(string, string) -> void
Collection constructorsfloat_list() -> FloatList
Collection constructorsfloat_map() -> FloatMap
Collection constructorsfloat_pq() -> FloatPQ
Collection constructorsfloat_queue() -> FloatQueue
Collection constructorsfloat_stack() -> FloatStack
Collection constructorsint_list() -> IntList
Collection constructorsint_map() -> IntMap
Collection constructorsint_pq() -> IntPQ
Collection constructorsint_queue() -> IntQueue
Collection constructorsint_stack() -> IntStack
Collection constructorsstr_list() -> StrList
Collection constructorsstr_map() -> StrMap
Collection constructorsstr_pq() -> StrPQ
Collection constructorsstr_queue() -> StrQueue
Collection constructorsstr_stack() -> StrStack
JSON and templatesjson_parse(string) -> Json
JSON and templatestemplate_render(string, Json) -> string
Result sinklmcode_return_null() -> void
Result sinklmcode_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 sinklmcode_return_put_null(string) -> void
Result sinklmcode_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

TypeMethodSignature
FloatListadd(float) -> FloatList
FloatListat(int) -> float
FloatListclear() -> FloatList
FloatListcontains(float) -> bool
FloatListindex_of(float) -> int
FloatListlen() -> int
FloatListset(int, float) -> FloatList
FloatMaplen() -> int
FloatMaphas(string) -> bool
FloatMapget(string) -> float
FloatMapget_or(string, float) -> float
FloatMapset(string, float) -> FloatMap
FloatMapkey_at(int) -> string
FloatMapremove(string) -> bool
FloatMapclear() -> FloatMap
FloatMapkeys() -> StrList
FloatMapvalues() -> FloatList
FloatPQpush(float, float) -> FloatPQ
FloatPQpop() -> float
FloatPQpeek() -> float
FloatPQlen() -> int
FloatPQempty() -> bool
FloatPQclear() -> FloatPQ
FloatQueuepush(float) -> FloatQueue
FloatQueuepop() -> float
FloatQueuepeek() -> float
FloatQueuelen() -> int
FloatQueueempty() -> bool
FloatQueueclear() -> FloatQueue
FloatQueueat(int) -> float
FloatStackpush(float) -> FloatStack
FloatStackpop() -> float
FloatStackpeek() -> float
FloatStacklen() -> int
FloatStackempty() -> bool
FloatStackclear() -> FloatStack
FloatStackat(int) -> float
IntListadd(int) -> IntList
IntListat(int) -> int
IntListclear() -> IntList
IntListcontains(int) -> bool
IntListindex_of(int) -> int
IntListlen() -> int
IntListset(int, int) -> IntList
IntMaplen() -> int
IntMaphas(string) -> bool
IntMapget(string) -> int
IntMapget_or(string, int) -> int
IntMapset(string, int) -> IntMap
IntMapkey_at(int) -> string
IntMapremove(string) -> bool
IntMapclear() -> IntMap
IntMapkeys() -> StrList
IntMapvalues() -> IntList
IntPQpush(int, float) -> IntPQ
IntPQpop() -> int
IntPQpeek() -> int
IntPQlen() -> int
IntPQempty() -> bool
IntPQclear() -> IntPQ
IntQueuepush(int) -> IntQueue
IntQueuepop() -> int
IntQueuepeek() -> int
IntQueuelen() -> int
IntQueueempty() -> bool
IntQueueclear() -> IntQueue
IntQueueat(int) -> int
IntStackpush(int) -> IntStack
IntStackpop() -> int
IntStackpeek() -> int
IntStacklen() -> int
IntStackempty() -> bool
IntStackclear() -> IntStack
IntStackat(int) -> int
Jsonkind() -> string
Jsonlen() -> int
Jsonat(int) -> Json
Jsonget(string) -> Json
Jsonhas(string) -> bool
Jsonkeys() -> StrList
Jsonas_string() -> string
Jsonas_int() -> int
Jsonas_float() -> float
Jsonas_bool() -> bool
Jsonto_json() -> string
StrListadd(string) -> StrList
StrListat(int) -> string
StrListclear() -> StrList
StrListcontains(string) -> bool
StrListindex_of(string) -> int
StrListjoin(string) -> string
StrListlen() -> int
StrListset(int, string) -> StrList
StrMapclear() -> StrMap
StrMapget(string) -> string
StrMapget_or(string, string) -> string
StrMaphas(string) -> bool
StrMapkey_at(int) -> string
StrMaplen() -> int
StrMapremove(string) -> bool
StrMapset(string, string) -> StrMap
StrMapkeys() -> StrList
StrMapvalues() -> StrList
StrPQpush(string, float) -> StrPQ
StrPQpop() -> string
StrPQpeek() -> string
StrPQlen() -> int
StrPQempty() -> bool
StrPQclear() -> StrPQ
StrQueuepush(string) -> StrQueue
StrQueuepop() -> string
StrQueuepeek() -> string
StrQueuelen() -> int
StrQueueempty() -> bool
StrQueueclear() -> StrQueue
StrQueueat(int) -> string
StrStackpush(string) -> StrStack
StrStackpop() -> string
StrStackpeek() -> string
StrStacklen() -> int
StrStackempty() -> bool
StrStackclear() -> StrStack
StrStackat(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.

InterfaceSignatureRole
RestGet(RestExchange exchange) -> voidHandler for GET routes
RestPost(RestExchange exchange) -> voidHandler for POST routes
RestPut(RestExchange exchange) -> voidHandler for PUT routes
RestDelete(RestExchange exchange) -> voidHandler for DELETE routes
RestPatch(RestExchange exchange) -> voidHandler for PATCH routes
RestHead(RestExchange exchange) -> voidHandler for HEAD routes
RestOptions(RestExchange exchange) -> voidHandler for OPTIONS routes
RestHandler(RestExchange exchange) -> voidGeneric handler bound by rest_route to an annotation name
CliCommand(RestExchange exchange) -> voidHandler for a command dispatched by rest_cli
CliOption(RestExchange exchange) -> voidHandler for an option dispatched by rest_cli
FunctionSignatureBehavior
rest_config(string, string) -> voidStore 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) -> voidRegister method, path template and handler annotation; templates accept {param} and {rest...} or :param and :rest... placeholders
rest_serve() -> voidRequest serving after the program body; routes are frozen from this call on
rest_stop() -> voidStop serving
rest_cli(StrList) -> stringStateless CLI mode: dispatch an argument vector to options, commands and REST routes and return the response text
RestExchange methodSignatureBehavior
method() -> stringRequest method
path() -> stringRequest path
query(string) -> stringQuery parameter value, empty when absent
has_query(string) -> boolWhether a query parameter is present
param(string) -> stringRoute template parameter value, empty when absent
header(string) -> stringRequest header value; repeated headers are joined with a comma and a space
has_header(string) -> boolWhether a request header is present
body() -> stringRequest body bytes
status(int) -> voidSet the response status; values outside 200..599 are a host error
set_header(string, string) -> voidSet a response header; Content-Length, Connection and Transfer-Encoding are managed by the server
send(string) -> voidSet the response body
json(string) -> voidSet the response body and the Content-Type application/json
get(string) -> stringRead a shared state value, empty when absent
set(string, string) -> voidWrite a shared state value
increment(string) -> intIncrement a shared named counter and return it

See also