fluxopt
¶
Modules:
| Name | Description |
|---|---|
components |
|
constraints |
Constraint builder functions for the optimization model. |
contributions |
Per-contributor effect breakdown. |
elements |
|
model |
|
model_data |
|
results |
|
stats |
Derived statistics from optimization results. |
types |
|
Type Aliases:
| Name | Description |
|---|---|
Variate |
Any input that varies over a subset of the model's variate dims ( |
Classes:
| Name | Description |
|---|---|
Converter |
Conversion between input and output flows. |
Port |
System boundary that imports from or exports to buses. |
Carrier |
Physical energy medium (electricity, heat, gas, …). |
Effect |
A tracked quantity across the optimization horizon (cost, CO₂, …). |
Flow |
A single energy flow on a carrier. |
Investment |
Singular discrete build-timing optimization. |
PiecewiseConversion |
Piecewise-linear conversion linking N flows. |
Sizing |
Capacity optimization parameters. |
Status |
Binary on/off behavior parameters. |
Storage |
Energy storage with level dynamics. |
FlowSystem |
|
Dims |
Shared model coordinates and temporal metadata. |
ModelData |
|
Result |
Optimization result with solution variables and model data. |
IdList |
Frozen, ordered container with access by id (str) or position (int). |
Functions:
| Name | Description |
|---|---|
as_dataarray |
Convert a Variate to a DataArray aligned to given coordinates. |
optimize |
Build data, build model, optimize, return results. |
Variate
¶
Any input that varies over a subset of the model's variate dims (time,
optionally period, eventually scenario).
- Scalar: broadcast to all variate dims.
- 1-D (
list/ndarray): matched to a coord by length (must be unambiguous). - 1-D (
pd.Series): index name selects the dim if set; else matched by length. - 2-D (
pd.DataFrame):index.nameandcolumns.namemust match target dims. - n-D (
xr.DataArray): dims must be a subset of the target; coords must match exactly.
Per-field reach (which dims a particular field can vary over) is documented on
the field itself; as_dataarray enforces that user input only uses dims the
caller declared in coords.
Converter
dataclass
¶
Converter(
id: str,
inputs: list[Flow] | IdList[Flow],
outputs: list[Flow] | IdList[Flow],
conversion_factors: list[dict[str, Variate]] = list(),
conversion: PiecewiseConversion | None = None,
)
Conversion between input and output flows.
Two mutually exclusive modes:
- Linear —
conversion_factors=[{flow_short_id: a_f}, ...], one dict per equation; constraintsum_f(a_f * P_{f,t}) = 0. - Piecewise —
conversion=PiecewiseConversion(...); the solver interpolates between breakpoints, optionally with on/off viaPiecewiseConversion.status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Converter id. |
required |
|
list[Flow] | IdList[Flow]
|
Input flows. |
required |
|
list[Flow] | IdList[Flow]
|
Output flows. |
required |
|
list[dict[str, Variate]]
|
Linear-mode equations. Empty when
|
list()
|
|
PiecewiseConversion | None
|
Piecewise-mode curve. |
None
|
Methods:
| Name | Description |
|---|---|
__post_init__ |
Qualify flow ids and validate mode exclusivity. |
boiler |
Create a boiler converter: fuel * eta = thermal. |
heat_pump |
Create a heat pump converter with source heat. |
power2heat |
Create an electric resistance heater: electrical * eta = thermal. |
chp |
Create a CHP converter with separate electrical and thermal outputs. |
__post_init__
¶
Qualify flow ids and validate mode exclusivity.
Source code in src/fluxopt/components.py
boiler
classmethod
¶
boiler(
id: str, thermal_efficiency: Variate, fuel_flow: Flow, thermal_flow: Flow
) -> Converter
Create a boiler converter: fuel * eta = thermal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Converter id. |
required |
|
Variate
|
Thermal efficiency eta. |
required |
|
Flow
|
Input fuel flow. |
required |
|
Flow
|
Output thermal flow. |
required |
Source code in src/fluxopt/components.py
heat_pump
classmethod
¶
heat_pump(
id: str,
cop: Variate,
electrical_flow: Flow,
source_flow: Flow,
thermal_flow: Flow,
) -> Converter
Create a heat pump converter with source heat.
Two conversion equations
electrical * COP = thermal electrical + source = thermal
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Converter id. |
required |
|
Variate
|
Coefficient of performance. |
required |
|
Flow
|
Input electrical flow. |
required |
|
Flow
|
Input environmental heat flow (air, ground, water). |
required |
|
Flow
|
Output thermal flow. |
required |
Source code in src/fluxopt/components.py
power2heat
classmethod
¶
power2heat(
id: str, efficiency: Variate, electrical_flow: Flow, thermal_flow: Flow
) -> Converter
Create an electric resistance heater: electrical * eta = thermal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Converter id. |
required |
|
Variate
|
Electrical-to-thermal efficiency. |
required |
|
Flow
|
Input electrical flow. |
required |
|
Flow
|
Output thermal flow. |
required |
Source code in src/fluxopt/components.py
chp
classmethod
¶
chp(
id: str,
eta_el: Variate,
eta_th: Variate,
fuel_flow: Flow,
electrical_flow: Flow,
thermal_flow: Flow,
) -> Converter
Create a CHP converter with separate electrical and thermal outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Converter id. |
required |
|
Variate
|
Electrical efficiency. |
required |
|
Variate
|
Thermal efficiency. |
required |
|
Flow
|
Input fuel flow. |
required |
|
Flow
|
Output electrical flow. |
required |
|
Flow
|
Output thermal flow. |
required |
Source code in src/fluxopt/components.py
Port
dataclass
¶
Port(
id: str,
imports: list[Flow] | IdList[Flow] = list(),
exports: list[Flow] | IdList[Flow] = list(),
)
System boundary that imports from or exports to buses.
Methods:
| Name | Description |
|---|---|
__post_init__ |
Qualify flow ids with the port id. |
__post_init__
¶
Carrier
dataclass
¶
Carrier(
id: str,
nodes: list[str] = list(),
unit: str = 'MWh',
color: str | None = None,
description: str = '',
)
Physical energy medium (electricity, heat, gas, …).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Unique identifier used as xarray coordinate. |
required |
|
list[str]
|
Sub-nodes for multi-node balancing. Empty means single-node. |
list()
|
|
str
|
Energy unit label. |
'MWh'
|
|
str | None
|
Optional color for plotting. |
None
|
|
str
|
Human-readable description. |
''
|
Effect
dataclass
¶
Effect(
id: str,
unit: str = '',
maximum: float | None = None,
minimum: float | None = None,
maximum_per_period: float | None = None,
minimum_per_period: float | None = None,
maximum_per_hour: Variate | None = None,
minimum_per_hour: Variate | None = None,
contribution_from: dict[str, Variate] = dict(),
period_weights: list[float] | None = None,
)
A tracked quantity across the optimization horizon (cost, CO₂, …).
One effect is designated as the objective to minimize via the
objective_effects argument of optimize(). Others can be bounded
to enforce budgets (e.g. emission caps).
Effects accumulate contributions from two domains:
- Temporal — per-timestep flow costs, running costs, startup costs.
- Lump — one-time sizing costs and fixed costs.
Cross-effect chains (e.g. CO₂ → cost) are supported via
contribution_from.
See: docs/math/effects.md
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Unique identifier. |
required |
|
str
|
Unit label (e.g. |
''
|
|
float | None
|
Upper bound on weighted total across all periods. |
None
|
|
float | None
|
Lower bound on weighted total across all periods. |
None
|
|
float | None
|
Upper bound applied to each period independently. |
None
|
|
float | None
|
Lower bound applied to each period independently. |
None
|
|
Variate | None
|
Upper bound rate [unit/h], scaled by Δt. |
None
|
|
Variate | None
|
Lower bound rate [unit/h], scaled by Δt. |
None
|
|
dict[str, Variate]
|
Cross-effect factors |
dict()
|
|
list[float] | None
|
Per-period weights ω for total aggregation;
overrides global |
None
|
Flow
dataclass
¶
Flow(
carrier: str,
short_id: str = '',
node: str | None = None,
size: float | Sizing | Investment | None = None,
relative_minimum: Variate = 0.0,
relative_maximum: Variate = 1.0,
fixed_relative_profile: Variate | None = None,
effects_per_flow_hour: dict[str, Variate] = dict(),
status: Status | None = None,
prior_rates: list[float] | None = None,
)
A single energy flow on a carrier.
short_id defaults to carrier (or carrier:node when node
is set). Set explicitly to disambiguate multiple flows on the same
carrier::
Flow('elec') # short_id='elec'
Flow('heat', node='A') # short_id='heat:A'
Flow('elec', short_id='base') # short_id='base'
short_id must be unique within a component. Storage renames
colliding short_ids to charge / discharge before qualification.
id is the qualified form set by the parent component:
component(short_id).
See: docs/math/flows.md
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Carrier this flow connects to. |
required |
|
str
|
Component-local identifier; defaults to |
''
|
|
str | None
|
Sub-node for multi-node carrier balancing. |
None
|
|
float | Sizing | Investment | None
|
Nominal capacity [MW], |
None
|
|
Variate
|
Lower bound as fraction of size. |
0.0
|
|
Variate
|
Upper bound as fraction of size. |
1.0
|
|
Variate | None
|
Fixed profile as fraction of size; sets both lower and upper bounds equal to the profile value. |
None
|
|
dict[str, Variate]
|
Effect coefficients per flow-hour (e.g. €/MWh). |
dict()
|
|
Status | None
|
On/off behavior (semi-continuous, startup costs, durations). |
None
|
|
list[float] | None
|
Flow rates [MW] before the horizon, used for status initial conditions. |
None
|
Methods:
| Name | Description |
|---|---|
__post_init__ |
Default short_id from carrier/node, set id = short_id. |
__post_init__
¶
Default short_id from carrier/node, set id = short_id.
Source code in src/fluxopt/elements.py
Investment
dataclass
¶
Investment(
min_size: float,
max_size: float,
mandatory: bool = True,
lifetime: int | None = None,
prior_size: float = 0.0,
effects_per_size_at_build: dict[str, Variate] = dict(),
effects_fixed_at_build: dict[str, Variate] = dict(),
effects_per_size_recurring: dict[str, Variate] = dict(),
effects_fixed_recurring: dict[str, Variate] = dict(),
)
Singular discrete build-timing optimization.
The solver decides WHEN to build (which period) and at what size.
Once built, capacity is available for lifetime periods.
Size is decided once — no growth or partial retirement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
Minimum capacity if built. |
required |
|
float
|
Maximum capacity. |
required |
|
bool
|
If True, must build exactly once; if False, may build at most once. |
True
|
|
int | None
|
Periods active after build; None = forever. |
None
|
|
float
|
Pre-existing capacity available from period 0. |
0.0
|
|
dict[str, Variate]
|
One-time per-MW costs charged in the build period. |
dict()
|
|
dict[str, Variate]
|
One-time fixed costs charged in the build period. |
dict()
|
|
dict[str, Variate]
|
Recurring per-MW costs charged every active period. |
dict()
|
|
dict[str, Variate]
|
Recurring fixed costs charged every active period. |
dict()
|
PiecewiseConversion
dataclass
¶
PiecewiseConversion(
points: dict[str, list[Variate]] | list[_CurveTuple],
method: PiecewiseMethod = 'auto',
status: Status | None = None,
availability: Variate = 1.0,
)
Piecewise-linear conversion linking N flows.
Wraps :func:linopy.piecewise.add_piecewise_formulation. All flows
share interpolation weights — every operating point lies on the same
piece of the curve.
Two input forms:
-
Dict — equality-only, terse for the common case::
PiecewiseConversion({'fuel': [0, 50, 100], 'Heat': [0, 45, 70]})
-
List of tuples — supports per-flow inequality bounds::
PiecewiseConversion( [ ('fuel', [0, 50, 100]), ('Heat', [0, 45, 70], '>='), ] )
See: docs/math/converters.md
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, list[Variate]] | list[_CurveTuple]
|
Per-flow breakpoints. Either |
required |
|
PiecewiseMethod
|
Formulation. |
'auto'
|
|
Status | None
|
Component-level on/off behavior gating the curve. |
None
|
|
Variate
|
Time-varying scaling of the upper breakpoint. |
1.0
|
Methods:
| Name | Description |
|---|---|
__post_init__ |
Validate normalized breakpoints and bound combinations. |
__post_init__
¶
Validate normalized breakpoints and bound combinations.
Source code in src/fluxopt/elements.py
Sizing
dataclass
¶
Sizing(
min_size: float,
max_size: float,
mandatory: bool = True,
effects_per_size: dict[str, Variate] = dict(),
effects_fixed: dict[str, Variate] = dict(),
)
Capacity optimization parameters.
The solver decides the optimal size within [min_size, max_size].
mandatory=True: continuous, size in [min, max], no binary.mandatory=False: binary indicator gates size: 0 or [min, max].min_size == max_sizewithmandatory=False: binary invest at exact size (yes/no).
See: docs/math/sizing.md
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
Minimum capacity if invested. |
required |
|
float
|
Maximum capacity. |
required |
|
bool
|
If True, must be built (no binary indicator). |
True
|
|
dict[str, Variate]
|
Effect cost per unit size (e.g. €/MW). |
dict()
|
|
dict[str, Variate]
|
Fixed effect cost if built (optional only). |
dict()
|
Status
dataclass
¶
Status(
min_uptime: float | None = None,
max_uptime: float | None = None,
min_downtime: float | None = None,
max_downtime: float | None = None,
effects_per_running_hour: dict[str, Variate] = dict(),
effects_per_startup: dict[str, Variate] = dict(),
)
Binary on/off behavior parameters.
Together with relative bounds, gives semi-continuous behavior:
{0} U [min, max] * size.
See: docs/math/status.md
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float | None
|
Minimum consecutive on-hours. |
None
|
|
float | None
|
Maximum consecutive on-hours. |
None
|
|
float | None
|
Minimum consecutive off-hours. |
None
|
|
float | None
|
Maximum consecutive off-hours. |
None
|
|
dict[str, Variate]
|
Effect cost per running hour. |
dict()
|
|
dict[str, Variate]
|
Effect cost per startup event. |
dict()
|
Storage
dataclass
¶
Storage(
id: str,
charging: Flow,
discharging: Flow,
capacity: float | Sizing | Investment | None = None,
eta_charge: Variate = 1.0,
eta_discharge: Variate = 1.0,
relative_loss_per_hour: Variate = 0.0,
prior_level: float | None = None,
cyclic: bool = True,
relative_minimum_level: Variate = 0.0,
relative_maximum_level: Variate = 1.0,
status: Status | None = None,
)
Energy storage with level dynamics.
Flow ids are qualified as storage(flow). When both flows connect
to the same carrier, they are renamed to charge / discharge::
Storage('bat', Flow('elec'), Flow('elec')) # bat(charge), bat(discharge)
Storage('bat', Flow('elec'), Flow('heat')) # bat(elec), bat(heat)
Level balance::
E_{s,t+1} = E_{s,t} (1 - δ)^Δt + P^c η^c Δt - P^d / η^d Δt
See: docs/math/storage.md
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Storage identifier. |
required |
|
Flow
|
Charging flow. |
required |
|
Flow
|
Discharging flow. |
required |
|
float | Sizing | Investment | None
|
Maximum stored energy [MWh], |
None
|
|
Variate
|
Charging efficiency. |
1.0
|
|
Variate
|
Discharging efficiency. |
1.0
|
|
Variate
|
Self-discharge rate [1/h]. |
0.0
|
|
float | None
|
Initial energy level [MWh]; None = unconstrained. |
None
|
|
bool
|
If True, end level must equal start level. |
True
|
|
Variate
|
Min SOC as fraction of capacity. |
0.0
|
|
Variate
|
Max SOC as fraction of capacity. |
1.0
|
|
Status | None
|
Component-level on/off behavior gating both charging and
discharging. Forbids flow-level |
None
|
Methods:
| Name | Description |
|---|---|
__post_init__ |
Validate carrier match, rename colliding flow ids, and qualify. |
__post_init__
¶
Validate carrier match, rename colliding flow ids, and qualify.
Source code in src/fluxopt/elements.py
FlowSystem
¶
Initialize the flow system optimization model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
ModelData
|
Pre-built model data. |
required |
Methods:
| Name | Description |
|---|---|
build |
Build all variables, constraints, and the objective. |
optimize |
Build, optionally customize, and solve the model. |
solve |
Solve the built model and return results. |
Source code in src/fluxopt/model.py
build
¶
Build all variables, constraints, and the objective.
Source code in src/fluxopt/model.py
optimize
¶
optimize(
objective_effects: str | list[str],
customize: Callable[[FlowSystem], None] | None = None,
*,
solver: str = 'highs',
**kwargs: Any,
) -> Result
Build, optionally customize, and solve the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | list[str]
|
Effect name(s) to minimize. Sum of named effect totals. |
required |
|
Callable[[FlowSystem], None] | None
|
Optional callback to modify the linopy model between build and solve.
Receives |
None
|
|
str
|
Solver backend name. |
'highs'
|
|
Any
|
Passed through to |
{}
|
Source code in src/fluxopt/model.py
Dims
dataclass
¶
Dims(
time: DataArray,
dt: DataArray,
weights: DataArray,
period: DataArray | None = None,
period_weights: DataArray | None = None,
)
Shared model coordinates and temporal metadata.
Owns the time and period dimensions, timestep durations, and weights.
Methods:
| Name | Description |
|---|---|
coords |
Return shared coordinates for variable/DataArray creation. |
to_dataset |
Serialize to xr.Dataset. |
from_dataset |
Deserialize from xr.Dataset. |
build |
Build Dims from a time index and optional periods. |
coords
¶
Return shared coordinates for variable/DataArray creation.
Also the single point of truth for the model's variate dims used by
:func:fluxopt.types.as_dataarray: pick the reach a field supports
(e.g. coords(time=True, period=True) for operational profiles,
coords(period=True) for investment-time fields). When a new
variate dim (e.g. scenario) is added, extend this method once
and every call site picks it up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Include the time coordinate. |
False
|
|
bool
|
Include the period coordinate (no-op in single-period mode). |
False
|
Source code in src/fluxopt/model_data.py
to_dataset
¶
to_dataset() -> Dataset
Serialize to xr.Dataset.
Source code in src/fluxopt/model_data.py
from_dataset
classmethod
¶
Deserialize from xr.Dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Dataset
|
Dataset with dt, weights, and optional period fields. |
required |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
build(
time: TimeIndex,
dt: DataArray,
periods: list[int] | Index | None = None,
period_weights: list[float] | None = None,
) -> Self
Build Dims from a time index and optional periods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
TimeIndex
|
Normalized time index. |
required |
|
DataArray
|
Timestep durations. |
required |
|
list[int] | Index | None
|
Integer period labels for multi-period optimization. |
None
|
|
list[float] | None
|
Explicit weights per period. Inferred from gaps if None. |
None
|
Source code in src/fluxopt/model_data.py
ModelData
dataclass
¶
ModelData(
flows: FlowsData,
carriers: CarriersData,
converters: ConvertersData | None,
effects: EffectsData,
storages: StoragesData | None,
dims: Dims,
piecewise: PiecewiseData | None = None,
)
Methods:
| Name | Description |
|---|---|
to_netcdf |
Write model data as NetCDF groups under |
from_netcdf |
Read model data from NetCDF groups. |
build |
Build ModelData from element objects. |
to_netcdf
¶
Write model data as NetCDF groups under /model/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Output file path. |
required |
|
Literal['w', 'a']
|
Write mode ('w' to overwrite, 'a' to append). |
'a'
|
Source code in src/fluxopt/model_data.py
from_netcdf
classmethod
¶
Read model data from NetCDF groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Input file path. |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If no model data groups found in the file. |
Source code in src/fluxopt/model_data.py
build
classmethod
¶
build(
timesteps: Timesteps,
carriers: list[Carrier],
effects: list[Effect],
ports: list[Port],
converters: list[Converter] | None = None,
storages: list[Storage] | None = None,
dt: float | list[float] | None = None,
periods: list[int] | Index | None = None,
period_weights: list[float] | None = None,
) -> Self
Build ModelData from element objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Timesteps
|
Time index for the optimization horizon. |
required |
|
list[Carrier]
|
Carrier declarations. |
required |
|
list[Effect]
|
Effects to track. |
required |
|
list[Port]
|
System boundary ports. |
required |
|
list[Converter] | None
|
Linear converters. |
None
|
|
list[Storage] | None
|
Energy storages. |
None
|
|
float | list[float] | None
|
Timestep duration in hours. Auto-derived if None. |
None
|
|
list[int] | Index | None
|
Integer period labels for multi-period optimization. |
None
|
|
list[float] | None
|
Explicit weights per period. Inferred from gaps if None. |
None
|
Source code in src/fluxopt/model_data.py
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 | |
Result
dataclass
¶
Result(
solution: Dataset,
data: ModelData,
duals: Dataset = Dataset(),
contributions: Dataset | None = None,
)
Optimization result with solution variables and model data.
Provides access to flow rates, storage levels, effect totals, and investment decisions. Key properties::
result.objective # scalar objective value
result.flow_rates # (flow, time) DataArray
result.flow_rate('id') # single flow time series
result.storage_levels # (storage, time) DataArray
result.effect_totals # (effect,) DataArray
result.effects_temporal # (effect, time) DataArray
result.effects_lump # (effect,) DataArray
result.sizes # (flow,) DataArray — invested sizes
result.storage_capacities # (storage,) DataArray
Per-contributor effect breakdown is available via result.stats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Dataset
|
Solved variable values as xr.Dataset. |
required |
|
ModelData
|
ModelData used to build the optimization. |
required |
|
Dataset
|
Dual values (shadow prices) from the solver. |
Dataset()
|
|
Dataset | None
|
Cached direct per-contributor effect breakdown (no
cross-effect propagation). Surfaced via
|
None
|
Methods:
| Name | Description |
|---|---|
flow_rate |
Get flow rate time series for a single flow. |
storage_level |
Get charge state time series for a single storage. |
to_netcdf |
Write solution and model data to NetCDF. |
from_netcdf |
Read a Result from a NetCDF file. |
from_model |
Extract solution from a solved linopy model. |
Attributes:
| Name | Type | Description |
|---|---|---|
objective |
float
|
Objective function value. |
flow_rates |
DataArray
|
All flow rates as (flow, time) DataArray. |
storage_levels |
DataArray
|
All storage levels as (storage, time) DataArray. |
sizes |
DataArray
|
Optimized flow sizes as (flow,) DataArray. |
storage_capacities |
DataArray
|
Optimized storage capacities as (storage,) DataArray. |
effect_totals |
DataArray
|
Total effect values as (effect,) DataArray. |
effects_temporal |
DataArray
|
Per-timestep effect values as (effect, time) DataArray. |
effects_lump |
DataArray
|
Non-temporal effect values as (effect,) DataArray. |
topology |
dict[Literal['carriers', 'converters'], dict[str, dict[str, list[str]]]]
|
Carrier and converter connectivity derived from model data. |
stats |
StatsAccessor
|
Post-processing statistics accessor. |
plot |
PlotAccessor
|
Plotting accessor (requires |
storage_levels
property
¶
storage_levels: DataArray
All storage levels as (storage, time) DataArray.
storage_capacities
property
¶
storage_capacities: DataArray
Optimized storage capacities as (storage,) DataArray.
effects_temporal
property
¶
effects_temporal: DataArray
Per-timestep effect values as (effect, time) DataArray.
topology
cached
property
¶
Carrier and converter connectivity derived from model data.
Returns a dict with carriers and converters keys, each mapping
element ids to their inputs (flows that produce into the element)
and outputs (flows that consume from it).
flow_rate
¶
storage_level
¶
storage_level(storage_id: str) -> DataArray
to_netcdf
¶
Write solution and model data to NetCDF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Output file path. |
required |
Source code in src/fluxopt/results.py
from_netcdf
classmethod
¶
Read a Result from a NetCDF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Input file path. |
required |
Source code in src/fluxopt/results.py
from_model
classmethod
¶
from_model(model: FlowSystem) -> Result
Extract solution from a solved linopy model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
FlowSystem
|
Solved FlowSystem instance. |
required |
Source code in src/fluxopt/results.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
IdList
¶
Frozen, ordered container with access by id (str) or position (int).
Supports concatenation via +.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Iterable[T]
|
Elements to store. Must have unique ids. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
On duplicate ids. |
Source code in src/fluxopt/types.py
as_dataarray
¶
as_dataarray(
value: Variate,
coords: Mapping[str, Any],
*,
name: str = 'value',
broadcast: bool = True,
) -> DataArray
Convert a Variate to a DataArray aligned to given coordinates.
Pipeline: convert → validate dims → validate coord values → broadcast.
See :data:Variate for accepted inputs. Pandas inputs (Series,
DataFrame) follow the same convention as linopy.as_dataarray: the
axis name attribute selects the corresponding target dim. For
ndarray/list, the dim is selected by length (must be unambiguous).
For DataArray, dims must be a subset of coords and coord values must
match exactly — alignment errors are surfaced loudly, not silently masked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Variate
|
Scalar, list, ndarray, Series, DataFrame, or DataArray. |
required |
|
Mapping[str, Any]
|
Target coordinates, e.g. |
required |
|
str
|
Name for the resulting DataArray. |
'value'
|
|
bool
|
Expand result to span all dimensions in coords. |
True
|
Source code in src/fluxopt/types.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
optimize
¶
optimize(
timesteps: Timesteps,
carriers: list[Carrier],
effects: list[Effect],
ports: list[Port],
objective_effects: str | list[str],
converters: list[Converter] | None = None,
storages: list[Storage] | None = None,
dt: float | list[float] | None = None,
periods: list[int] | None = None,
period_weights: list[float] | None = None,
solver: str = 'highs',
customize: Callable[[FlowSystem], None] | None = None,
**kwargs: Any,
) -> Result
Build data, build model, optimize, return results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Timesteps
|
Time index for the optimization horizon. |
required |
|
list[Carrier]
|
Carrier declarations. |
required |
|
list[Effect]
|
Effects to track (costs, emissions, etc.). |
required |
|
list[Port]
|
System boundary ports with imports/exports. |
required |
|
str | list[str]
|
Effect name(s) to minimize. Sum of named effect totals. |
required |
|
list[Converter] | None
|
Linear converters between carriers. |
None
|
|
list[Storage] | None
|
Energy storages. |
None
|
|
float | list[float] | None
|
Timestep duration in hours. Auto-derived if None. |
None
|
|
list[int] | None
|
Integer period labels for multi-period optimization. |
None
|
|
list[float] | None
|
Explicit weights per period. Inferred from gaps if None. |
None
|
|
str
|
Solver backend name. |
'highs'
|
|
Callable[[FlowSystem], None] | None
|
Optional callback to modify the linopy model between build and solve.
Receives the built FlowSystem; use |
None
|
|
Any
|
Passed through to |
{}
|