Skip to main content

model-parser

Convert process-model definitions to and from a canonical intermediate representation (IR).

model-parser is the Advanced Process Control toolbox component that owns the model scaffold contract and the transformations around it. It parses an authoring format (today: the ExprTk-style INI used by the MPC / simulation toolchain) into a normalized, backend-independent canonical IR, and lowers that IR into generated Julia and Python model views.

authoring (ExprTk INI)  --parse-->  AST  --normalize-->  canonical IR (JSON)
                                                          |
                                          emit julia      --> ModelingToolkit .jl
                                          emit julia-rhs  --> numerical f!/outputs! .jl
                                          emit python     --> numerical functions .py
                                          emit cpp        --> (planned) realtime C++

The IR is the single semantic contract. Adding a backend means writing one lower + one export, not an N×N mesh of view-to-view translators. See docs/design/model-parser.md for the authoritative product specification and docs/decisions/ for the design decision records.

Why two languages?

Concern Home Why
CLI, AST, IR, JSON Schema, validators, codegen Python (this package) Parsing & orchestration strength; no symbolic runtime needed to emit code.
IR → MTK System, simulation, analysis, conformance Julia (julia/ModelParserJL) Natural fit for ModelingToolkit; reference for parity tests.

The Python CLI builds and validates the IR and generates Julia code; the Julia package can additionally load an IR directly into an MTK System for in-memory, dynamic workflows. Both consume the same IR. See ADR 0001.

Install

CLI from PyPI (end users)

The package on PyPI is apc-model-parser; the installed command is model-parser.

pipx install apc-model-parser
# or: uv tool install apc-model-parser
model-parser --help

Use pipx or uv tool when you only need the CLI in an isolated environment.

From source (development)

This repository uses uv for environments and tasks.

uv sync --all-groups    # include dev tools (ruff, pytest, mkdocs)
uv run model-parser --help

CLI

# 1. ExprTk INI  ->  canonical IR JSON
uv run model-parser parse examples/models/model_monod_simple.ini -o monod.ir.json

# 2. canonical IR  ->  ModelingToolkit (v11) Julia model
uv run model-parser emit julia monod.ir.json -o monod.jl

# 2a. canonical IR  ->  plain numerical ODE RHS (SciML-style f!)
uv run model-parser emit julia-rhs monod.ir.json -o monod_rhs.jl

# 2b. canonical IR  ->  Python ODE RHS and output functions
uv run model-parser emit python monod.ir.json -o monod.py

# Supporting commands
uv run model-parser validate monod.ir.json --profile julia-analysis
uv run model-parser inspect  monod.ir.json
uv run model-parser diff     monod.ir.json other.ir.json   # semantic IR diff
uv run model-parser bump     monod.ir.json other.ir.json   # suggested SemVer bump
uv run model-parser ast      examples/models/model_monod_simple.ini   # debug tree
uv run model-parser schema   -o schemas/canonical-ir.schema.json      # export schema

parse accepts --from exprtk-ini (default). validate accepts either an IR .json file or an INI file (parsed on the fly). Exit codes: 0 success, 1 validation errors, 2 usage / load failure.

How "stored MTK models" work

The persisted, version-controlled form of a model is the IR JSON plus the generated .jl scriptnot a serialized System object. ModelingToolkit v11 changed System internals significantly (precompilation, removal of defaults, deprecation of @mtkmodel), so serializing the live object is brittle across versions. Regenerating from the IR is the durable path. See ADR 0002 and docs/design/storing-mtk-models.md.

Development

uv sync --all-groups
uv run ruff check .
uv run ruff format --check .
uv run pytest
uv run mkdocs build --strict   # same as CI

Documentation site (after Pages is set to GitHub Actions): https://advanced-process-control.github.io/model-parser/

Scope

In scope: authoring-format parsing, the canonical IR data model + JSON Schema, semantic & profile validation, IR↔backend lowering/codegen.

Out of scope: parameter identification, scenario execution, simulation result storage, controller synthesis, deployment. Those are sibling tools that consume the IR. The parser stays small (see AGENTS.md scope guardrails).

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apc_model_parser-0.2.3.tar.gz (117.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apc_model_parser-0.2.3-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file apc_model_parser-0.2.3.tar.gz.

File metadata

  • Download URL: apc_model_parser-0.2.3.tar.gz
  • Upload date:
  • Size: 117.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for apc_model_parser-0.2.3.tar.gz
Algorithm Hash digest
SHA256 8c08235b4210ae4f03f684c5436db5877fdb678e4d34360f65d51eeed20f499d
MD5 bbfde85bfcdaba9ff3de831fe596f1ab
BLAKE2b-256 30be68f3e5515e2995ea3602572b3685197adfcb9912ba4802f72784e4040d4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for apc_model_parser-0.2.3.tar.gz:

Publisher: release.yml on Advanced-Process-Control/model-parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apc_model_parser-0.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for apc_model_parser-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 908001e2cb4c3559d267a00363a07de0849766d8a7e4c6985e6cc42275e76811
MD5 22f9a7f6650175d78f8282a77a3a0f93
BLAKE2b-256 65220cb5de2b3e42ed66cc3dbe5f2b559746e60485441cb15b28b3030658cbde

See more details on using hashes here.

Provenance

The following attestation bundles were made for apc_model_parser-0.2.3-py3-none-any.whl:

Publisher: release.yml on Advanced-Process-Control/model-parser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 files

0.2.2

2 files

0.2.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page