fluxopt.results
¶
Classes:
| Name | Description |
|---|---|
Result |
Optimization result with solution variables and model data. |
Result
dataclass
¶
Result(
solution: Dataset,
data: ModelData,
duals: Dataset = Dataset(),
expressions: Dataset = Dataset(),
)
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
|
Every quantity the model names, evaluated at this
solution. A named expression is evaluated against a solve, so it
can only be had here — carrying them is what makes a |
Dataset()
|
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. |
expression |
One quantity the model names, at this solution. |
save |
Write the result as a directory. |
load |
Read a result written by :meth: |
Attributes:
| Name | Type | Description |
|---|---|---|
objective |
float
|
Objective function value. |
objective_weights |
dict[str, float]
|
Effect weights the objective was minimized with (provenance). |
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 |
objective_weights
property
¶
Effect weights the objective was minimized with (provenance).
Includes the built-in penalty effect (auto-added at 1.0 unless
named in objective). Empty for results saved before
this field existed.
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.
Reconstructed from flow rates and coefficients — the model carries no per-timestep effect variables (temporal closure).
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
expression
¶
One quantity the model names, at this solution.
Whatever the program declares under expressions: — including
anything a caller added through optimize(math=...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The expression's name in the program. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
Naming what this Result does carry, since a model that declared it and a Result that kept it are different things. |
Source code in src/fluxopt/results.py
save
¶
Write the result as a directory.
The solution and the named quantities are labelled N-dimensional
arrays, so they stay netCDF; the model data is tables and goes to
parquet under model/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
Directory to write into. Created if absent. |
required |
Source code in src/fluxopt/results.py
load
classmethod
¶
Read a result written by :meth:save.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | Path
|
The directory :meth: |
required |
Raises:
| Type | Description |
|---|---|
OSError
|
If the directory holds no solution. |