lmspace authoring skill

Guidance for authoring, running, and verifying lmscript orbital mechanics and SPICE astronomy programs on the lmspace host.

Purpose

Help write valid, deterministic lmscript programs for lmspace covering two-body Kepler propagation, classical orbital elements, Hohmann and Lambert transfers, symplectic and RK45 N-body integration, and NASA NAIF CSPICE frame and ephemeris queries.

When to use it

Use lmspace when an lmscript workflow needs orbital propagation, trajectory matrices, delta-v transfer budgets, energy and angular momentum invariants, or SPICE coordinate transformations and ephemeris lookups exported to CSV or handed off to plotting and rendering tools.

Install

Install the lmctl toolchain with npm i -g @lmctl-ai/lmctl or download the latest platform binary from GitHub Releases. Linux binaries require dynamic glibc 2.35 or newer (Ubuntu 22.04+); CSPICE N0067 and C++ runtime libraries are linked statically. Declare install="github:lmctl-ai/lmspace@latest" on the _lmcode_ block so run_lmcode resolves or downloads the matching release automatically.

Commands

lmscript orbit.lms
lmspace --version
lmspace --notices
lmspace --lmcode-schema
lmspace --lmcode-schema --json
lmspace --lmcode-signatures
lmspace --dry-run --lmcode FILE [FILE ...]
lmspace --lmcode FILE [FILE ...]

Inputs and outputs

Safety rules

Worked examples

p = _lmcode_ cli="lmspace" install="github:lmctl-ai/lmspace@latest";
let mu = 398600.4418;
let orbit = elements(7000.0, 0.1, 0.2, 0.3, 0.4, 0.5);
let initial = orbit.to_state(mu);
let after_one_orbit = initial.propagate(mu, period(7000.0, mu));
space_assert_close(after_one_orbit.position().x(), initial.position().x(), 0.000001);

let transfer = hohmann(7000.0, 42164.0, mu);
space_assert_close(transfer.get(0, 0), 2.336795782386, 0.000000001);
transfer.save_csv("transfer.csv");

let b1 = space.body("primary", 0.5, -0.5, 0.0, 0.0, 0.0, -0.5, 0.0);
let b2 = space.body("secondary", 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0);
let sys = space.system().add(b1).add(b2);
let traj = sys.propagate(6.283185307179586, 200, 0.005, "symplectic", 0.00000001);
space_assert_close(sys.energy_drift(), 0.0, 0.0001);
traj.save_csv("binary.csv");
end _lmcode_
r = run_lmcode(p);
require(r.ok, "lmspace calculation failed");

Errors and exit codes

Exit 0 indicates that all bytecode slots loaded and completed. Exit 2 reports invalid command-line syntax, contradictory --dry-run metadata, or an invalid LMSPACE_MAX_MEMORY_MB setting. Exit 3 reports bytecode load, schema mismatch, runtime domain errors (non-positive mu, collinear Lambert endpoints, parabolic element conversion, missing SPICE kernel coverage, failed assertion), or memory budget exhaustion. Exit 4 reports application-level failures tagged APP_FAIL or an output failure.

How to verify

  1. Run lmspace --version and lmspace --lmcode-schema --json to confirm the binary and embedded schema matches schema/lmspace.host.json.
  2. Validate compiled bytecode without running numerical integrations or writing files by passing --dry-run --lmcode.
  3. Use space_assert_close(actual, expected, tolerance) to verify orbital periods, delta-v values, round-trip element conversions, and position vectors against finite tolerances.
  4. Check space.energy_drift() or system.energy_drift() after N-body propagation to ensure relative energy drift stays well below 1e-3.