Skip to main content

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

Project description

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 target views — starting with a generated ModelingToolkit (Julia) model script.

authoring (ExprTk INI)  --parse-->  AST  --normalize-->  canonical IR (JSON)
                                                          |
                                          emit julia  --> ModelingToolkit .jl
                                          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

# 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).

Project details


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.1.tar.gz (108.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.1-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apc_model_parser-0.2.1.tar.gz
  • Upload date:
  • Size: 108.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apc_model_parser-0.2.1.tar.gz
Algorithm Hash digest
SHA256 4cd38caf0f900abf22ec9681a8a4c1c6ab6ba43217175c846e7429fd62ab236b
MD5 d6b36d1eccbd84069d1ed359ba33da39
BLAKE2b-256 c3ce8a228d46e5858a1c9e2be24f27da6f9badb056397d9f222aecae0f515291

See more details on using hashes here.

Provenance

The following attestation bundles were made for apc_model_parser-0.2.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for apc_model_parser-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8379446c9ae7be96355b16b077f19da8c93867d379a47a6ad91f4eba1d13b112
MD5 f1d130c71d0179d36435305b2bb1835a
BLAKE2b-256 c58ba264f4e6e6c3608540370f21b668d989d98f254573944aa1a1bbad0ff861

See more details on using hashes here.

Provenance

The following attestation bundles were made for apc_model_parser-0.2.1-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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page