Skip to content

The Domain Model

James Dunkerley edited this page Nov 20, 2026 · 2 revisions

Home · Architecture

In short

  • The domain model lives in tz_ps_models and depends only on numpy and pydantic.
  • A network is a named collection of components on one shared time axis, and each component holds its attributes as constants, series or curves.
  • A framework declares the component types and their attributes, and also holds the registry of installed frameworks.
  • Project, Network and ComponentHandle in tz_ps_conductor are the Python API over the model. The Python API describes them.

The types

tz_ps_models holds plain pydantic models and no I/O. The diagram shows the core types and how the Python API wraps them. Each class lists only its main members.

classDiagram
    direction LR
    class Framework {
        <<Protocol>>
        +name
        +component_types
        +build_component(data)
    }
    class ComponentType {
        +name
        +url_token
        +parameter_types
    }
    class ParameterType {
        +name
        +value_type
        +kind
    }
    class NetworkModel {
        +name
        +framework_name
        +timesteps
        +components
    }
    class ComponentModel {
        +name
        +component_type
        +parameters
    }
    class Parameter {
        +attribute
        +value_kind
        +values
    }
    class Network {
        +add_component()
        +save()
        +solve()
    }
    class Project {
        +get_network(name)
        +save_network(network)
        +list_versions(name)
    }
    class ComponentHandle {
        +set()
        +clear()
    }
    Framework "1" o-- "*" ComponentType
    ComponentType "1" *-- "*" ParameterType
    NetworkModel "1" *-- "*" ComponentModel
    ComponentModel "1" *-- "*" Parameter
    NetworkModel ..> Framework : framework_name
    ComponentModel ..> ComponentType : component_type
    Network o-- NetworkModel
    Network ..> Project : saves through
    ComponentHandle o-- ComponentModel
Loading

Network and components

  • A NetworkModel is a named collection of components, unique by ComponentKey (component type and name).
  • It has one shared timesteps axis.
  • components is a computed, sorted view.
  • timesteps and series values are positional and are never sorted.

Values

  • A component holds each attribute as a Parameter with a ValueKind:
    • a constant: one value;
    • a series: one value per timestep;
    • a curve: values at breakpoints in x_values.
  • Values are numpy float arrays (FloatArray), so a large series never becomes a list of Python floats.
  • A component does not know the timesteps. The check that a series has one value per timestep runs at the network boundary, in NetworkModel.validate_values(), which a save and a solve call.

Frameworks and the component registry

  • Framework is the contract a framework package implements.
  • It also holds the registry of installed frameworks (Framework.register, Framework.get).
  • A framework declares its ComponentTypes. Each has ParameterTypes that say:
    • the value type;
    • whether the attribute takes a series or a curve;
    • whether it is an input or an output;
    • what it references.
  • tz_ps_models loads no entry points itself. The composition root installs discovery with Framework.set_discovery.

Strict when built, lenient when loaded

  • Built: Network(name, framework) and an import refuse a framework nothing registers, with UnknownFrameworkError.
  • Loaded: a stored network loads on whatever framework it names. get_framework_or_fallback answers a generic framework, and its components become plain ComponentModels.
  • So a saved network stays readable on a host without its framework.

Identifiers

Type What it is
VersionId A str subclass for a stored version's id, with the sentinel VersionId.LATEST. Compare with ==.
VersionInfo A version's number, title, parent, and what authored it: a run, an import, a restore, a copy or a workflow step.
NetworkRef Project, network name and an optional version. A run's input names one.
SeriesIdentity Component type, component name and attribute: the one name for a series everywhere.
ObjectKey A validated str subclass for an object store key.

Constraints, statistics and measures

  • A network carries constraints. A CustomConstraint is a name and an expression.
  • A network carries derived_values. A DerivedValue is a name, an expression and a unit label.
  • The glossary calls a derived value a custom statistic, and a measure a built-in statistic.
  • Measures are declared in the shared catalogue, tz_ps_expressions/measures.py, where each Measure names the frameworks that provide it.
  • Framework.measure_keys declares the fields a run's measures may be grouped and filtered by.
  • A solve stores measures in the run values table described by tz_ps_models/run_values.py.
  • Snapshot weightings are a mapping from a weighting name to one number per timestep.

Results

A solve's outputs are values on a network version, with the objective in NetworkModel.metadata.

Clone this wiki locally