Version: dev

return_code

Stable type · Simulation

Tier: stable · Kind: type · Topic: Simulation

JuliaTypeScriptPythonRustGo
not exportedoutside profileReturnCodeReturnCodeoutside profile

Julia

Julia does not export this type.

TypeScript

Not available in TypeScript. TypeScript is outside the simulation capability profile (Julia, Python, Rust): build an RHS and integrate it; TypeScript and Go are deliberately non-simulating.

Python

class ReturnCode(str, Enum)
ReturnCode.Success = 'Success'
ReturnCode.MaxIters = 'MaxIters'
ReturnCode.Unstable = 'Unstable'
ReturnCode.Terminated = 'Terminated'
ReturnCode.Failure = 'Failure'

The SciML ReturnCode vocabulary (API_SPEC §4, esm-libraries-spec §2.5.3), which is how a run reports its outcome in every simulating binding.

A caller distinguishes “ran to tspan[1]” from “stopped early, here is why” by comparing retcode, never by reading prose.

  • Success — the integration reached the end of tspan.
  • MaxIters — the maxiters budget on right-hand-side evaluations ran out first.
  • Unstable — the trajectory left the domain the model can evaluate (a non-finite derivative or state).
  • Terminated — a continuous event stopped the run early.
  • Failure — the solver, the build, or the model reported an error.

Subclassing str keeps a code printable and JSON-serializable (str(ReturnCode.Success) == "ReturnCode.Success", .value == "Success") without making it a bare string at comparison sites.

Source

Example (simulate)

doc = earthsci_ast.load_path(FIXTURES / "decay.esm")
prob = earthsci_ast.esm_problem(doc, (0.0, 10.0))

half_life = math.log(2) / 0.1
sol = earthsci_ast.solve(prob, saveat=[0.0, half_life, 10.0])
assert sol.retcode == earthsci_ast.ReturnCode.Success

# A solution is indexed by variable name.
n = sol["N"]
print("N at t = 0, ln 2 / λ, 10:", n)
assert math.isclose(n[1], 50.0, rel_tol=1e-3)
assert math.isclose(n[-1], 100.0 * math.exp(-1.0), rel_tol=1e-3)

# Observed variables are read the same way.
assert math.isclose(sol["half_life"][-1], half_life, rel_tol=1e-9)

From docs/api/examples/python/simulate.py

Rust

pub enum ReturnCode {
    Success,
    MaxIters,
    Unstable,
    Terminated,
    Failure,
}

impl ReturnCode { pub fn is_success(self) -> bool }

impl ReturnCode { pub fn name(self) -> &'static str }

Why a solve stopped — the SciML ReturnCode vocabulary (esm-libraries-spec.md §2.5.3).

This REPLACES reading SolutionMetadata ’s step and evaluation counters as a proxy for whether a run finished. The counters remain, as informative statistics; the answer to “did it reach tspan.1” is this enum and nothing else, and a caller never has to parse an error message to get it.

Source · Rust docs

Go

Not available in Go. Go is outside the simulation capability profile (Julia, Python, Rust): build an RHS and integrate it; TypeScript and Go are deliberately non-simulating.