Architecture

This document describes the software architecture of the POMMES package. The architecture is designed to be modular, extensible, and centered around the linopy optimization framework.

Overview

The model follows a functional orchestration pattern:

  1. Data Ingestion: Raw configuration and data files are processed into a structured xarray.Dataset.

  2. Orchestration: A central builder initializes the optimization model and coordinates the addition of various system components.

  3. Component Injection: Specialized modules inject their specific variables, constraints, and objective terms into the shared model state.

  4. State Management: A PommesModel, a linopy.Model with a catalogue, serves as the central state: it accumulates the mathematical definitions before solving and records, for each variable and constraint, the stage it belongs to.

Architecture Diagram

The following diagram illustrates the data flow and the interaction between the different modules.

POMMES Architecture Diagram

Core Components

Data Ingestion Layer

The entry point for data is the pommes.io.build_input_dataset module.

  • Inputs:

    • config.yaml: Defines the simulation scope, dimensions (time, area), and active modules.

    • data/*.csv: Contains raw time-series and parameter data.

  • Process:

    • Validates input consistency.

    • Computes derived parameters (e.g., annuities, discount factors).

    • Broadcasts parameters to the required dimensions.

  • Output: A comprehensive xarray.Dataset (referred to as model_parameters) containing all necessary data for the optimization.

Orchestration Layer

The pommes.model.build_model module acts as the conductor.

Responsibilities:
  • Initializes the empty PommesModel.

  • Creates global “safety” variables (load shedding, spillage).

  • Initializes the two fundamental equations of the model:

    • Adequacy Constraint: Ensures supply equals demand at every time step.

    • Objective Function: Defines the minimization of total annualized costs (TOTEX).

  • Conditionally calls specific component modules based on the configuration, each inside with m.module("<name>"): so that the catalogue records which module wrote what.

  • Checks the catalogue against the model once every module has run (m.check()): a variable or a constraint without an entry, or whose dimensions contradict its stage, is a bug in the module that created it and stops the build.

Functional Modules

The model logic is split into specialized modules located in pommes.model.*. These modules are stateless functions that modify the model object in place, through the typed helpers of PommesModel that declare the stage of what they create (see The model and its catalogue). They are categorized into two groups:

1. Energy Balance Components These modules directly influence the physical energy balance of the system. They add terms to the Adequacy Constraint (production, consumption, storage) and the Objective Function (costs).

  • conversion.py: Power generation technologies (renewable, thermal). Handles capacity, dispatch, and ramping.

  • storage.py: Energy storage systems (batteries, hydro). Handles state of charge and cycling.

  • transport.py: Inter-area transmission. Handles power flow between regions.

  • combined.py: Multi-mode technologies (e.g., CHP).

  • net_import.py: Exchanges with external markets/countries.

  • flexible_demand.py: Demand-side response and load shifting.

2. Regulatory & Accounting Layers These modules do not produce or consume energy but impose constraints or add costs to the system. They primarily modify the Objective Function.

  • carbon.py: CO2 emission tracking, quotas, and carbon taxes.

  • turpe.py: Grid usage tariffs (TURPE) and subscription optimization.

  • retrofit_conversion.py: Conversion of an existing conversion asset into another conversion technology (e.g., SMR to SMR with carbon capture).

  • retrofit_combined.py: The same, between combined technologies.

The model and its catalogue

The PommesModel object acts as the shared repository for the mathematical formulation.

  • Decision Variables: Created by each module (e.g., operation_conversion_power, planning_storage_power_capacity).

  • Technical Constraints: Specific limitations added by modules (e.g., ramp rates, max capacity, must-run).

  • Shared Expressions: * operation_adequacy_constraint: All energy modules add their net generation to this constraint through m.add_terms(operation_adequacy_constraint, expression); build_model writes the collected terms once (m.write_terms()), rather than copying the whole row at each lhs +=. * annualised_totex_def: All modules append their investment and operation costs to this expression.

  • The catalogue (m.catalogue, a Catalogue): one entry per variable and per constraint, written when the object is created and never parsed from its name.

Stages

A POMMES model has three stages of variables, and the catalogue records the stage and the role of each one:

Stage

What

Roles

planning

Decided once for the whole horizon, indexed by an investment year (year_dec, year_inv, year_ret); and the annualised planning costs, which the Benders master reads back.

decision (an investment), cost (planning_*_costs), state (the level a sub-period starts and ends at, when a year is cut into sub-periods).

annual

One value per operation year, without an hourly index.

capacity (the installed capacity, defined from the planning decisions alone), cost (an operation cost aggregate, annualised_totex), decision (an annual decision shared by the hours, the TURPE contract power).

operation

The dispatch, indexed by hour.

decision (a power, a level), derived (defined by an equality: the displaced flexible demand, the absolute exchange under TURPE), state (a value at the bound of a window of hours: the initial storage level, the production budget left).

A derived quantity – a net generation, the emissions, the absolute exchange without TURPE – is not a variable: its module writes it as the linear expression it stands for (a DerivedQuantity) into the rows that use it, and declares it with m.add_derived(name). The catalogue lists it apart, in catalogue.derived, with the role derived; derive_solution() computes its values from those of the variables, with the same expression, and model.solution, the solution of solve_benders and save_solution carry them under its name. Write a quantity this way when only one or two rows read it; keep a variable when it has bounds of its own or a row defines it by an inequality.

Constraints have a stage of their own: planning (rows between planning variables only: investment bounds, retrofit caps, a planning cost definition), linking (rows that define an annual variable from the planning ones, operation_*_capacity_def, or bound an annual variable) and operation (rows with an hourly term). A constraint may also carry: defines, the derived variable an equality defines; annual_coupling, when it couples the hours of a whole year (a carbon goal, a yearly ceiling, the conservation of a flexible demand); state_in, the state variable whose incoming value its right-hand side pins.

Who reads it

  • The Benders decomposition (Benders decomposition) keeps in its master every planning variable and the annual capacities (Catalogue.master_variables) with the planning and linking rows, pins in each subproblem the planning decisions and states (fixed_in_subproblem), removes from it the planning rows that define nothing (dropped_from_subproblem), prices the master with the planning costs (planning_cost_variables) and refuses to cut a year by operating condition when a variable is shared_across_conditions.

  • The operation window (Operation window) pins the same planning decisions, removes the pure planning rows and the annual couplings, and finds its states through state_in.

  • The summaries (pommes.io.calculate_summaries) split the costs into planning and operation by stage. The catalogue travels with the solution for that: model.solution carries it in its attributes, save_solution writes it into solution.nc and as catalogue.json, read_solution puts it back on the dataset read from the CSV files, and Catalogue.of_solution reads it. A dataset without it – built by hand, or read from a result written before the catalogue existed – is refused by the summaries, with the way to attach one: that of the model, or the one Catalogue.from_legacy_names(solution) rebuilds from the names of the variables under the rules of 0.10.0, with a warning, so that a result of an earlier version is read without building the model again.

  • The checks of build_model: the investment floors are checked on the planning decisions of the catalogue.

What a solver adds to a built model (benders_fix_*, benders_theta, the cuts, the elastic slacks) is not catalogued: the catalogue describes the model as build_model returns it, and a solver that removes variables or rows afterwards keeps their entries and reads the catalogue for the names the model still has.

Extensibility

This architecture allows for easy extension. To add a new technology or mechanism:

  1. Create a new module in pommes/model/.

  2. Define a function add_new_feature(model: PommesModel, parameters, ...).

  3. Inside the function, create the variables and constraints through the typed helpers, which create the linopy object and its catalogue entry in one step: add_planning_variable, add_annual_variable(role=...), add_operation_variable, add_planning_constraint, add_linking_constraint, add_operation_constraint. Name the derived variable an equality defines (defines=), flag a row that couples the whole year (annual_coupling=True) and the row that pins an incoming state (state_in=). A helper refuses a stage the dimensions contradict (an operation variable without hour, a planning decision without an investment year) and leaves no variable behind; a variable created with add_variables has no entry and fails m.check() at the end of build_model.

  4. Update the shared Adequacy and Objective expressions.

  5. Register the new module in build_model.py, inside with m.module("new_feature"):.

For example, the conversion module declares its installed capacity, its dispatch and its planning decision as:

operation_conversion_power_capacity = m.add_annual_variable(
    name="operation_conversion_power_capacity", role=Role.CAPACITY,
    lower=0, coords=linopy_coords(p.area, p.conversion_tech, p.year_op),
)
operation_conversion_power = m.add_operation_variable(
    name="operation_conversion_power", lower=0, coords=...,
)
planning_conversion_power_capacity = m.add_planning_variable(
    name="planning_conversion_power_capacity", lower=0, coords=...,
)
m.add_linking_constraint(
    -operation_conversion_power_capacity
    + planning_conversion_power_capacity.where(...).sum(...) == 0,
    name="operation_conversion_power_capacity_def",
    defines="operation_conversion_power_capacity",
)

The names follow the planning_ / operation_ convention of the public solution dataset, but nothing reads the stage off them any more: the Benders master, the operation window, the summaries and the checks ask the catalogue.