lmpy

lmpy is a native numerical host for LMScript: linear algebra, statistics, tables, optimisation, differential equations, signal processing, graphs, statistical models and machine learning in one executable, with no Python, R or Docker at run time. A program is an LMScript _lmcode_ block that lmscript type-checks against the lmpy schema and run_lmcode executes, returning checked JSON values.
Install and run
Install the LMScript compiler once; the block declaration downloads the lmpy release binary for your platform (Linux x64 and arm64, macOS x64 and arm64, Windows x64) into the lmscript tool cache and verifies its SHA-256 digest.
npm i -g @lmctl-ai/lmctl
lmscript --check program.lms
lmscript program.lms
The repository examples need lmscript 0.2.460 or newer. This page describes lmpy 0.1.46, the release that install="github:lmctl-ai/lmpy@latest" resolved to when it was written.
Minimal program
p = _lmcode_ cli="lmpy" install="github:lmctl-ai/lmpy@latest";
let q = dist("norm").ppf(0.975);
out.close("normal 97.5% quantile", q, 1.959963984540054, 0.00000000000001);
let x = mat("1 2 3; 0 1 4; 5 6 0").solve(vec(14.0, 14.0, 17.0));
out.close("known linear-system solution", x, vec(1.0, 2.0, 3.0), 0.000000000001);
out.put("quantile", q);
out.put("solution", x);
end _lmcode_
r = run_lmcode(p);
require(r.ok, json_stringify(r));
println(json_stringify(r.result));
lmscript quick.lms
{"values":{"quantile":1.959963984540054,"solution":[1,2,3]},"checks":{"passed":2,"failed":0,"failures":[]}}
Host protocol and flags
| Command or form | What it does |
|---|---|
| _lmcode_ cli="lmpy" install="github:lmctl-ai/lmpy@latest"; ... end _lmcode_ | Declares the host; lmscript reads the binary's embedded schema and compiles the block against it |
| _lmcode_ schema="lmpy.dsl.json"; ... end _lmcode_ | Compiles against a schema file instead of asking a binary |
| run_lmcode(p) | Runs the block on lmpy and returns the decoded frame: ok and result, or ok, phase, code and message |
| lmpy --lmcode FILE [FILE ...] | Host side of run_lmcode: runs compiled bytecode and prints one LMCODE_RETURN_BEGIN / JSON / LMCODE_RETURN_END frame |
| lmpy --dry-run --lmcode FILE [FILE ...] | Loads and validates without running; results are null |
| lmpy --lmcode-schema | Plain-text API summary |
| lmpy --lmcode-schema --json | Exact schema bytes the bytecode binds to |
| lmpy --lmcode-signatures | Canonical signatures, one per line (757 in 0.1.46) |
| lmpy --api-md | Generated API reference as Markdown |
| lmpy --version | Release identity, lmpy X.Y.Z |
| Exit code | Frame phase | Meaning |
|---|---|---|
| 0 | none | Success |
| 2 | cli | Usage error; lmscript compile errors also exit 2 |
| 3 | load, run | Bytecode load error or run-time error |
| 4 | app | out.fail or a failed check |
Signature counts
| Surface | Count in lmpy 0.1.46 |
|---|---|
| Host types | 15: Vec, StrVec, Mat, Opts, Res, Out, Frame, Sparse, Dist, Rng, OdeSol, Interp, Filter, Graph, Estimator |
| Host signatures | 551 lines: the out context, 211 function signatures and 339 methods |
| Standard catalog shipped | lmcode_std_v3 with 206 signatures (str_, math_, file_, collections, Json, encoding, template_render, lmcode_return_) |
| Current lmcode_std_v3 in lmcode-cpp | 226 signatures; the 20 added REST and CLI signatures are not in lmpy 0.1.46 and arrive when lmpy syncs its runtime and releases |
Main objects and functions
| Name | Kind | Create or call | Use |
|---|---|---|---|
| out | context object (Out) | out.put(name, value), out.check(name, bool), out.close(name, got, want, tol), out.close_rel, out.log, out.fail | Record returned values and named checks; a failed check makes the run fail with exit 4 |
| Vec | type | vec(1.0, 2.0), vec("1 2.5 -3"), arange(5), linspace(0.0, 1.0, 5), zeros(n), ones(n), full(n, x) | 1-D float64 array; elementwise +, -, * and methods such as add, mul, sum, mean, std, sort, slice, apply |
| StrVec | type | strs("x1, x2"), split(text, sep) | Names of columns, unknowns and labels |
| Mat | type | mat("1 2; 3 4"), mat(rows, cols), cols(v1, v2), eye(n), diag(v) | Dense matrix; * is the matrix product; solve, lstsq, inv, det, decompositions and matrix functions |
| Opts | type | opts().set("method", "BFGS").set("tol", 0.000001) | Named options for an operation; unknown keys are errors; keys starting with $ bind names in expressions |
| Res | type | returned by operations | Typed result fields: ok(), status(), num, int, vec, mat, res, strs, text, flag, keys, json |
| Frame | type | read_csv(path), csv(text), frame() | Immutable column table: filter, mutate, select, sort, groupby, merge, rolling, resample |
| Sparse | type | sparse(rows, cols), sparse(dense), speye(n), tridiag(n, lower, diagonal, upper) | Sparse matrix with direct and iterative solvers and eigsh |
| Dist, Rng | types | dist("norm"), dist("gamma", opts().set("a", 3.0)), rng(seed) | 31 distribution families with pdf, cdf, ppf, rvs; numpy-compatible seeded random numbers |
| minimize, least_squares, root_scalar, root, quad, linprog | functions | minimize(expr, strs("x, y"), x0, opts) | Optimisation, roots, quadrature and LP/MILP on expression strings |
| ode, OdeSol | function, type | ode(rhs, states, y0, t0, t1, opts) | Initial value problems with events |
| interp, Interp | function, type | interp(kind, x, y) | Linear, cubic, pchip, akima, smoothing and rbf interpolants |
| iir, Filter, welch, find_peaks, fft | functions, type | see reference | Filter design and filtering, spectra, peaks |
| graph, Graph | function, type | graph(directed) | Shortest paths and flows on named nodes |
| ols, glm, arima, acf | functions | ols(frame, "y", strs("x1, x2")) | Regression and time-series models returning Res |
| ml_fit, Estimator | function, type | ml_fit(kind, x, y) | Linear, logistic, SVC, naive Bayes, LDA, kNN, k-means, PCA, scaler |
Detail pages
- Skill: how an agent installs, runs, checks and verifies lmpy programs.
- Guide: concepts, architecture, the value model, expressions and limits.
- Reference: every type, method, function, flag and exit code.
- Quickruns: a first checked program and provider sessions.
- Examples: the example book with release-installed scripts.
- github.com/lmctl-ai/lmpy: source, releases and the generated native/API.md.