Repository navigation
Expression Language ‐ How Its Built
James Dunkerley edited this page Nov 20, 2026
·
3 revisions
Home · Architecture · Backend core
In short
- One language serves two purposes: a custom constraint added to the optimisation, and a derived value (a custom statistic) worked out from a run's results.
- The grammar is one contract in
contracts/grammar/, and a Python parser and a TypeScript parser are generated from it. -
tz_ps_expressionsparses, checks and evaluates. A framework package answers questions about names and never sees the expression text. - The expression language describes the language for a modeller: what to write, with examples.
The contract is contracts/grammar/:
| File | Holds |
|---|---|
Expression.g4 |
An ANTLR grammar. A constraint is expression sense expression; a derived value is one expression |
functions.json |
The function table |
messages.json |
Every error message |
cases.json |
Conformance cases |
Two parsers are generated from it:
- Python, by
make grammar, intotz_ps_expressions/_generated/. - TypeScript, in
frontend-sdk, for the editor.
Both test suites read cases.json, and both word their errors from messages.json. The HTTP API and the contracts describes the generators and the drift checks.
- An expression refers to values as
Type[filters].attribute. - The selection is a list of names, or filters such as
carrier = "wind". - It combines values with arithmetic, and with functions that take
over=to say which dimension to aggregate.
The work is split across three layers:
| Layer | What it does |
|---|---|
tz_ps_models/expressions.py |
Holds the reference types (Quantity, Selection, Filter), the value grid Cells, and the lookup Protocols ConstraintLookup and ValueLookup
|
| A framework package | Implements the lookups. It says what an attribute is and which components a selection matches, and it never sees the expression text |
tz_ps_expressions |
Parses, checks shape and dimensions (list_constraint_problems, list_derived_value_problems), and evaluates (calculate_derived_value) |
Measures are declared in the shared catalogue, tz_ps_expressions/measures.py, where each Measure names the frameworks that provide it.
-
Check.
tz_ps_conductor/expression_checks.pytakes the framework's lookup and calls the shared check.- An error raises
InvalidConstraintsErrororInvalidDerivedValuesError. - The check runs on a model built without its series.
- An error raises
-
Solve. Each solver parses the constraints again and compiles them.
-
tz_ps_solver_pypsacompiles them onto the linopy model. -
tz_ps_files_calliopecompiles them into Calliope maths.
-
-
Read.
tz_ps_conductor/derived_value_results.pyevaluates a derived value over a stored version's inputs, outputs and measures, forProject.calculate_derived_values.
Using the app
Architecture
- Overview
- Python API
- Domain model
- Backend core
- Composition root and config
- Expression language internals
- Storage
- Execution
- Imports and exports
- Workflow engine
- HTTP API and contracts
- Frontend and desktop
- Build, CI and release
Contributing