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

continuo.parse(path)[source]

Load a .mod file (macro expansion, parsing, IR) into a Model.

Parameters:

path (str | Path)

Return type:

Model

continuo.parse_string(source, *, base_dir=None)[source]

Load model source given as a string into a Model.

Parameters:
Return type:

Model

The Model object

class continuo.api.Model(model)[source]

Bases: object

A loaded model: its symbol table and the solver entry points.

Parameters:

model (ir.Model)

steady_state(*, exogenous=None)[source]

Compute the steady state at the given exogenous configuration.

Parameters:

exogenous (dict[str, float] | None)

Return type:

dict[str, float]

simul(*, horizon=None, intervals=None, scheme=None)[source]

Run the perfect-foresight simulation, returning a Solution.

horizon / intervals / scheme override the model’s simulate command.

Parameters:
  • horizon (float | None)

  • intervals (int | None)

  • scheme (str | None)

Return type:

Solution

The Solution object

class continuo.io.solution.Solution(segments, names, diagnostics=<factory>, converged=True)[source]

Bases: object

A solved path over [0, T], glued from one or more segments.

Parameters:
to_dataframe()[source]

Return the path as a time-indexed pandas.DataFrame.

to_xarray()[source]

Return the path as an xarray.Dataset over the time coordinate.

A Solution aggregates one or more Segment records (one per active belief — see The shocks block):

class continuo.io.solution.Segment(start_time, times, path, names, info_set, terminal_ss, iterations)[source]

Bases: object

One realised segment of the path and the regime it was solved under.

Parameters:

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: Exception

A macro-layer error, optionally carrying a source position.

The expression layer raises these without a position; the expansion driver attaches file/line as it unwinds.

Parameters:
  • message (str)

  • file (str | None)

  • line (int | None)

exception continuo.ir.IRError(message, pos=None)[source]

Bases: Exception

A semantic error, optionally carrying a source position.

pos refers 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)

exception continuo.codegen.CodegenError(message, pos=None)[source]

Bases: Exception

A lowering error, optionally carrying a source position.

Parameters:
  • message (str)

  • pos (SourcePos | None)

exception continuo.solve.SolveError[source]

Bases: Exception

A numerical solve failure.