Python API¶
The top-level continuo package exposes a small, focused API: a
parser, a model object that wraps the parsed file with its solvers, and
a solution object that wraps the solved path. The remaining modules
(parser, IR, codegen, solve) are public to the extent that their
exceptions are catchable by the user, but their internals are
implementation details.
Entry points¶
The Model object¶
- class continuo.api.Model(model)[source]¶
Bases:
objectA loaded model: its symbol table and the solver entry points.
- Parameters:
model (ir.Model)
- steady_state(*, exogenous=None, solver=None, options=None, nodomain=None)[source]¶
Compute the steady state at the given exogenous configuration.
solverselects the nonlinear algorithm for the numerical path: a preset name ("newton","hybr","kinsol","homotopy", …), aSteadySolverinstance, orNone— which falls back to the model’ssteady(solver=…)directive, then to"auto".optionsconfigures a named preset (e.g.{"strategy": "picard"}forkinsol); when both are omitted, the directive’ssolverandoptionsare used.nodomaindisables the domain change of variable (solve in rawxdespite declared constraints);Nonedefers to the model’ssteady(nodomain)directive, an explicit bool overrides it.
- simul(*, horizon=None, intervals=None, scheme=None, order=None, adapt=None, monitor=None, solver=None, steady_solver=None, steady_solver_options=None)[source]¶
Run the perfect-foresight simulation, returning a
Solution.horizon/intervals/scheme/orderoverride the model’ssimulatecommand;orderselects the collocation order of a multi-stagescheme(the family default whenNone).adaptturns on adaptive mesh refinement to the given error tolerance, driven bymonitor("residual"by default, or"richardson"); both override the directive.solverselects the linear backend: a preset name ("superlu","auto"), aLinearSolverinstance, orNone(the"auto"default).steady_solverselects the nonlinear algorithm for the internal steady-state solves, overriding thesteady(solver=…)directive, andsteady_solver_optionsconfigures it.
The Solution object¶
- class continuo.io.solution.Solution(segments, names, diagnostics=<factory>, converged=True)[source]¶
Bases:
objectA solved path over
[0, T], glued from one or more segments.- Parameters:
A Solution aggregates one or more Segment
records (one per active belief — see The shocks block):
Diagnostics¶
Solution.diagnostics is a free-form dict populated by the solver
with run-level summary information. The keys currently set are:
scheme(str)The discretisation scheme that was used (e.g.
"crank_nicolson"). Matches theschemeargument of thesimulatecommand.segments(int)Number of perfect-foresight segments the orchestrator solved. Equals
1when no surprise revelations split the horizon, and1 + kwhenksurprise reveal times fall inside[0, T].newton_iterations(int)Total Newton iterations summed across all segments. A sudden jump from one run to the next — same model, similar parameters — usually means the new instance is closer to a singularity or the initial guess is poorer; inspect the per-segment counts via
[seg.iterations for seg in sol.segments].equidistribution_ratio(float)A cheap grid-adequacy hint: the
max / meanof the per-interval curvature over the solved path. Near1the grid is well balanced;>> 1flags resolution misallocated relative to where the solution bends, i.e. a candidate for adaptive refinement. See Time grids and adaptive refinement.solver(str)The linear backend that was used (e.g.
"klu","superlu"). See Linear solvers.factorizations/refactorizations(int)How many full factorisations versus cheap refactorisations the backend performed over the run. With the cross-segment warm-start, later segments refactor from the first segment’s factorisation rather than re-analysing, so refactorisations dominate.
refactor_fallbacks(int)How many times a reused factorisation failed (a stale-pivot re-pivot) and was redone from scratch. Normally
0.min_rcond(floatorNone)The worst reciprocal-condition estimate seen over the run, or
Nonewhen the backend exposes none (SuperLU, PARDISO).fill(intorNone)The factorisation fill
nnz(L) + nnz(U), where the backend exposes it (SuperLU, UMFPACK);Noneotherwise.
The same summary is also emitted at logging.INFO level on the
continuo.solve.orchestrator logger, so a caller that configures
logging.basicConfig(level=logging.INFO) will see one line per run
without having to read the dict.
The set of keys may grow in future releases; treat unknown keys as informational and the documented ones as the stable contract.
Exceptions¶
Each pipeline stage raises a dedicated exception so user code can
distinguish where a problem originated. All four inherit from
Exception (not from one another); a CLI-style “any pipeline error”
catch is except (MacroError, LarkError, IRError, CodegenError,
SolveError).
- exception continuo.macro.MacroError(message, *, file=None, line=None)[source]¶
Bases:
ExceptionA macro-layer error, optionally carrying a source position.
The expression layer raises these without a position; the expansion driver attaches
file/lineas it unwinds.
- exception continuo.ir.IRError(message, pos=None)[source]¶
Bases:
ExceptionA semantic error, optionally carrying a source position.
posrefers to the post-macroexpansion source; callers holding the macro line map format it back to the user’s original file.- Parameters:
message (str)
pos (SourcePos | None)