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

This project uses uv for everything.

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 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.1.0.tar.gz (93.9 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.1.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: apc_model_parser-0.1.0.tar.gz
  • Upload date:
  • Size: 93.9 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.1.0.tar.gz
Algorithm Hash digest
SHA256 37f0d79807a1be8373f7f0260898ce46030eccba4f321070086f0b08bf6dd9c3
MD5 ba12aaef8d28f55baa127b5f4cf4e19f
BLAKE2b-256 75b1259c27f0b969bd8f45586357bee7921cf0faafa361513343e08bcf773329

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for apc_model_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b10f2ab4ea64c172788375aaab62fcb7da801b266ee575b7645fc74b3bf60e28
MD5 276da062baa245c95577f1a01af03066
BLAKE2b-256 28a9a0d5439b891e0a15e94a582646d8ddb8275d7aacd9d4c92a0d99b496a0b9

See more details on using hashes here.

Provenance

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