lmcell reference
Complete reference for lmcell 0.1.4: the context object, every host type and method with its validation rules, matrix layouts, enumerated string values, limits, CLI flags, exit codes, the result envelope and the vendored lmcode_std_v3 standard library. Signatures are taken from the embedded schema and the host source.
Context objects
| Name | Type | Role |
|---|---|---|
| cell | Cell | The only context object: creates simulations and offers scalar helpers |
The schema declares 5 host types with 36 methods, no host functions and one context object. Schema format is 2 and the schema name is lmcell.
Host types
| Type | Obtained from | Methods | Lifetime |
|---|---|---|---|
| Cell | context cell | 5 | Whole program |
| Sim | cell.sim | 10 | Editable until run, then frozen; kept until the process exits |
| CellType | sim.cell_type | 8 | Handle into its Sim; frozen with it |
| Result | sim.run | 9 | Immutable; kept until the process exits |
| Matrix | Result accessors | 4 | Independent copy; kept until the process exits |
Cell methods
| Method | Signature | Behavior |
|---|---|---|
| sim | (int) -> Sim | New simulation builder with the given seed; the seed must be in 0..4294967295 |
| eval | (string) -> float | Evaluate a constant scalar expression; a non-finite result is an error |
| assert_close | (float, float, float) -> void | Error unless the absolute difference of the first two values is within the third; all three must be finite and the tolerance nonnegative |
| assert_true | (bool) -> void | Error assert_true failed when the value is false |
| (string) -> void | Write the text and a newline to stderr |
Expression names accepted by eval
| Kind | Names |
|---|---|
| Constants | pi, e |
| Functions | abs, acos, asin, atan, atan2, ceil, cos, cosh, exp, floor, ln, log, log10, max, min, mod, pow, sign, sin, sinh, sqrt, tan, tanh |
Sim methods
Every Sim method except run returns the same Sim, so calls chain. After run every builder call fails with simulation already run; builders are frozen.
| Method | Signature | Parameters | Rules |
|---|---|---|---|
| domain | (float, float, float, float, float) -> Sim | xmin, xmax, ymin, ymax, voxel_size | Bounds ordered, spacing positive, both lengths whole multiples of the spacing. Default -100, 100, -100, 100, 20 |
| substrate | (string, float, float, float, float) -> Sim | name, diffusion, decay, initial, boundary | Unique nonempty name other than neighbors; diffusion, decay and initial nonnegative; boundary nonnegative or -1 for no flux |
| edge | (string, string, float) -> Sim | substrate, side, value | Substrate already declared; side xmin, xmax, ymin or ymax; value nonnegative or -1 for no flux; a single-row domain has no y edges; at most 128 edge calls |
| diffusion_dt | (float) -> Sim | dt | Positive; largest diffusion and exchange substep |
| cell_type | (string) -> CellType | name | Unique nonempty name |
| seed | (string, int, float, float) -> Sim | type, count, x, y | Known type; count 0..100000; point inside the domain (checked at run) |
| scatter | (string, int, float, float, float, float) -> Sim | type, count, xmin, xmax, ymin, ymax | Known type; ordered bounds inside the current domain |
| seed_disk | (string, int, float, float, float) -> Sim | type, count, x, y, radius | Known type; nonnegative radius; disk inside the current domain |
| record | (float) -> Sim | interval | Positive interval in minutes |
| run | (float, float) -> Result | duration, max_dt | Duration nonnegative, max_dt positive; validates everything, runs, freezes the builder |
CellType methods
Every CellType method returns the same CellType.
| Method | Signature | Parameters | Rules |
|---|---|---|---|
| cycle | (float) -> CellType | rate | Nonnegative division rate per minute (one-phase live cycle) |
| death | (float) -> CellType | rate | Nonnegative apoptosis rate per minute |
| radius | (float) -> CellType | r | Cell radius in micrometers; must be positive at run |
| motility | (float, float) -> CellType | speed, persistence_time | Speed nonnegative, persistence positive |
| chemotaxis | (string, float) -> CellType | substrate, bias | Declared substrate (checked at run); bias in 0..1 |
| exchange | (string, float, float) -> CellType | substrate, uptake, secretion | Nonnegative rates; one call per substrate, a repeat is an error; at most 32 per type |
| rule | (string, string, string, float, float) -> CellType | signal, effect, target, half_max, hill | Effect increases or decreases; half_max nonnegative; hill positive |
| rule_toward | (string, string, float, float, float) -> CellType | signal, target, saturation, half_max, hill | Saturation nonnegative; half_max nonnegative; hill positive |
Enumerated string values
| Parameter | Accepted values |
|---|---|
| edge side | xmin, xmax, ymin, ymax |
| rule effect | increases, decreases |
| rule target | cycle entry, apoptosis, migration speed (the host also accepts cycle rate and death rate as spellings of the first two) |
| rule signal | Any declared substrate name, or neighbors |
| boundary and edge value | -1 for no flux, otherwise a nonnegative fixed concentration |
Result methods
| Method | Signature | Returns |
|---|---|---|
| live | () -> int | Live cells at the end of the run |
| live_of | (string) -> int | Live cells of one type at the end; unknown type is an error |
| substrate | (int) -> string | Substrate name by zero-based index |
| counts | () -> Matrix | time, live for every step |
| type_counts | () -> Matrix | time, then live cells per type for every step |
| cells | () -> Matrix | x, y, type_index, alive for every cell at the end |
| profiles | () -> Matrix | x, y, then each substrate for every voxel at the end |
| history | () -> Matrix | time, x, y, type_index, alive at each recorded time |
| profile_history | () -> Matrix | time, x, y, substrates at each recorded time |
Matrix methods
| Method | Signature | Behavior |
|---|---|---|
| rows | () -> int | Number of rows |
| cols | () -> int | Number of columns |
| get | (int, int) -> float | Value at zero-based row and column; out of range is an error |
| save_csv | (string) -> void | Write the matrix as CSV: no header, comma separated, LF line ends, 17 significant digits, classic locale; overwrites |
Limits
| Quantity | Limit | Error text |
|---|---|---|
| Seed | 0..4294967295 | seed must be in [0,4294967295] |
| Substrates | 32 | substrate limit exceeded |
| Cell types | 32 | cell type limit exceeded |
| Rules | 1000 | rule limit exceeded |
| Edge calls | 128 | edge limit exceeded |
| Seeded cells | 100000 | cell count limit exceeded |
| Population during a run | 100000 | cell population limit exceeded |
| Voxels; steps; voxels × steps × substeps | 1000000; 1000000; 200000000 | domain/time resource limit exceeded |
| Rate × step | 0.1 | rate*dt must not exceed 0.1; reduce dt |
| Recorded profile values | 20000000 | profile history resource limit exceeded |
| Host objects per kind | 10000 | host object limit exceeded |
| Simulations per process | 1 | lmcell supports one PhysiCell simulation per process |
| Total memory | 4096 MiB default | memory budget exceeded, naming LMCELL_MAX_MEMORY_MB |
CLI flags
usage: lmcell --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
| Flag | Behavior |
|---|---|
| --version | Print lmcell and the version |
| --notices | Print embedded third-party notices |
| --lmcode-schema | Print all signatures as text |
| --lmcode-schema --json | Print the exact embedded schema JSON bytes |
| --lmcode-signatures | Print all signatures as text: 1 context line, 206 standard signatures and 36 host methods |
| --lmcode FILE [FILE ...] | Load all compiled programs, then run them in order, stopping at the first failure |
| --dry-run | Before or after --lmcode: load and verify only; no simulation and no file writes. Given twice, or contradicting real-mode invocation metadata, it is a usage error |
| Environment variable | Meaning |
|---|---|
| LMCELL_MAX_MEMORY_MB | Total memory budget in MiB for a --lmcode run, default 4096; anything but a positive whole number is a usage error |
| LMCODE_INVOCATION_FILE | Set by run_lmcode to pass invocation metadata such as dry mode; not set by hand |
Exit codes and result frame
| Exit | Phase | Meaning |
|---|---|---|
| 0 | none | Success, also for --version, --notices and the schema flags |
| 2 | cli | Usage or invocation metadata error; code CLI_USAGE |
| 3 | load, run | Bytecode could not be read or verified, or a program raised a host error |
| 4 | app | Application or output failure (error code APP_FAIL) |
A --lmcode invocation ends with exactly one result frame on stdout. This is the real frame for a missing file, which exits 3:
lmcell --lmcode missing.dslb
LMCODE_RETURN_BEGIN
{"ok":false,"phase":"load","code":"LOAD_BAD_BYTECODE","message":"cannot read missing.dslb"}
LMCODE_RETURN_END
| Envelope field | Content |
|---|---|
| ok | true or false |
| result | Value set by lmcode_return_set or the fields set by lmcode_return_put; null when unset |
| phase | On failure: cli, load, run or app |
| code | On failure: for example CLI_USAGE, LOAD_BAD_BYTECODE, RUN_HOST |
| message, line, column | On failure: host message with the block line and column |
Standard library (lmcode_std_v3)
lmcell 0.1.4 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 93bddf1dadff84791ea90e17d81a7af85a842f40. The library is registered by default, needs no import and is callable in any lmcell block next to the cell 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 lmcell vendors are the former lmcode_std_rest_v1 module: 5 functions and 15 RestExchange methods, together with 10 standard interfaces. lmcell does not ship them yet; it picks them up when it syncs its pinned lmcode-cpp SDK and publishes a release. Until then a lmcell program that calls rest_route or declares a RestGet handler does not compile against the lmcell 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 |