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

NameTypeRole
cellCellThe 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

TypeObtained fromMethodsLifetime
Cellcontext cell5Whole program
Simcell.sim10Editable until run, then frozen; kept until the process exits
CellTypesim.cell_type8Handle into its Sim; frozen with it
Resultsim.run9Immutable; kept until the process exits
MatrixResult accessors4Independent copy; kept until the process exits

Cell methods

MethodSignatureBehavior
sim(int) -> SimNew simulation builder with the given seed; the seed must be in 0..4294967295
eval(string) -> floatEvaluate a constant scalar expression; a non-finite result is an error
assert_close(float, float, float) -> voidError 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) -> voidError assert_true failed when the value is false
print(string) -> voidWrite the text and a newline to stderr

Expression names accepted by eval

KindNames
Constantspi, e
Functionsabs, 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.

MethodSignatureParametersRules
domain(float, float, float, float, float) -> Simxmin, xmax, ymin, ymax, voxel_sizeBounds ordered, spacing positive, both lengths whole multiples of the spacing. Default -100, 100, -100, 100, 20
substrate(string, float, float, float, float) -> Simname, diffusion, decay, initial, boundaryUnique nonempty name other than neighbors; diffusion, decay and initial nonnegative; boundary nonnegative or -1 for no flux
edge(string, string, float) -> Simsubstrate, side, valueSubstrate 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) -> SimdtPositive; largest diffusion and exchange substep
cell_type(string) -> CellTypenameUnique nonempty name
seed(string, int, float, float) -> Simtype, count, x, yKnown type; count 0..100000; point inside the domain (checked at run)
scatter(string, int, float, float, float, float) -> Simtype, count, xmin, xmax, ymin, ymaxKnown type; ordered bounds inside the current domain
seed_disk(string, int, float, float, float) -> Simtype, count, x, y, radiusKnown type; nonnegative radius; disk inside the current domain
record(float) -> SimintervalPositive interval in minutes
run(float, float) -> Resultduration, max_dtDuration nonnegative, max_dt positive; validates everything, runs, freezes the builder

CellType methods

Every CellType method returns the same CellType.

MethodSignatureParametersRules
cycle(float) -> CellTyperateNonnegative division rate per minute (one-phase live cycle)
death(float) -> CellTyperateNonnegative apoptosis rate per minute
radius(float) -> CellTyperCell radius in micrometers; must be positive at run
motility(float, float) -> CellTypespeed, persistence_timeSpeed nonnegative, persistence positive
chemotaxis(string, float) -> CellTypesubstrate, biasDeclared substrate (checked at run); bias in 0..1
exchange(string, float, float) -> CellTypesubstrate, uptake, secretionNonnegative rates; one call per substrate, a repeat is an error; at most 32 per type
rule(string, string, string, float, float) -> CellTypesignal, effect, target, half_max, hillEffect increases or decreases; half_max nonnegative; hill positive
rule_toward(string, string, float, float, float) -> CellTypesignal, target, saturation, half_max, hillSaturation nonnegative; half_max nonnegative; hill positive

Enumerated string values

ParameterAccepted values
edge sidexmin, xmax, ymin, ymax
rule effectincreases, decreases
rule targetcycle entry, apoptosis, migration speed (the host also accepts cycle rate and death rate as spellings of the first two)
rule signalAny declared substrate name, or neighbors
boundary and edge value-1 for no flux, otherwise a nonnegative fixed concentration

Result methods

MethodSignatureReturns
live() -> intLive cells at the end of the run
live_of(string) -> intLive cells of one type at the end; unknown type is an error
substrate(int) -> stringSubstrate name by zero-based index
counts() -> Matrixtime, live for every step
type_counts() -> Matrixtime, then live cells per type for every step
cells() -> Matrixx, y, type_index, alive for every cell at the end
profiles() -> Matrixx, y, then each substrate for every voxel at the end
history() -> Matrixtime, x, y, type_index, alive at each recorded time
profile_history() -> Matrixtime, x, y, substrates at each recorded time

Matrix methods

MethodSignatureBehavior
rows() -> intNumber of rows
cols() -> intNumber of columns
get(int, int) -> floatValue at zero-based row and column; out of range is an error
save_csv(string) -> voidWrite the matrix as CSV: no header, comma separated, LF line ends, 17 significant digits, classic locale; overwrites

Limits

QuantityLimitError text
Seed0..4294967295seed must be in [0,4294967295]
Substrates32substrate limit exceeded
Cell types32cell type limit exceeded
Rules1000rule limit exceeded
Edge calls128edge limit exceeded
Seeded cells100000cell count limit exceeded
Population during a run100000cell population limit exceeded
Voxels; steps; voxels × steps × substeps1000000; 1000000; 200000000domain/time resource limit exceeded
Rate × step0.1rate*dt must not exceed 0.1; reduce dt
Recorded profile values20000000profile history resource limit exceeded
Host objects per kind10000host object limit exceeded
Simulations per process1lmcell supports one PhysiCell simulation per process
Total memory4096 MiB defaultmemory budget exceeded, naming LMCELL_MAX_MEMORY_MB

CLI flags

usage: lmcell --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
FlagBehavior
--versionPrint lmcell and the version
--noticesPrint embedded third-party notices
--lmcode-schemaPrint all signatures as text
--lmcode-schema --jsonPrint the exact embedded schema JSON bytes
--lmcode-signaturesPrint 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-runBefore 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 variableMeaning
LMCELL_MAX_MEMORY_MBTotal memory budget in MiB for a --lmcode run, default 4096; anything but a positive whole number is a usage error
LMCODE_INVOCATION_FILESet by run_lmcode to pass invocation metadata such as dry mode; not set by hand

Exit codes and result frame

ExitPhaseMeaning
0noneSuccess, also for --version, --notices and the schema flags
2cliUsage or invocation metadata error; code CLI_USAGE
3load, runBytecode could not be read or verified, or a program raised a host error
4appApplication 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 fieldContent
oktrue or false
resultValue set by lmcode_return_set or the fields set by lmcode_return_put; null when unset
phaseOn failure: cli, load, run or app
codeOn failure: for example CLI_USAGE, LOAD_BAD_BYTECODE, RUN_HOST
message, line, columnOn 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

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 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.

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