FlexCostingData

class flexops.costing.flex_costing.FlexCostingData(component)

EECO-backed costing block with opex/capex sub-blocks (module docstring).

Example

>>> import pyomo.environ as pyo
>>> from pyomo.environ import units as pyunits
>>> import flexops as fo
>>> m = pyo.ConcreteModel()
>>> m.time_block = fo.TimeBlock(
...     start_date="2025-07-08", end_date="2025-07-09",
...     time_step=1 * pyunits.hr,
... )
>>> m.costing = fo.FlexCosting(
...     time_block=m.time_block, tariff_file="tariff.json",
... )
build() → None

Validate config, load the tariff + DR container, init empty registries.

Loads the tariff and the DR program (into the dr container) but builds no aggregation, no opex/capex sub-blocks, and no DR constraints here — everything is deferred to cost_process() so the block may be constructed before any units exist (the construction-order invariant).

Raises:

FlexConfigError – If not exactly one of tariff_file/tariff is given, time_block is missing, an export_prices key has no energy_prices entry, or a per-period price does not have one value per time point.

build_global_params() → None

Resolve the tariff (if any) and set the base currency.

Called during build(). When a tariff is given the base currency is the tariff sheet’s currency basis (EECO tariffs are dollar-based → USD, from the charge units column); otherwise it is the configured currency. Every operating-cost expression FlexCosting builds is labeled with it. EECO’s own cost expressions are dimensionless dollars, so FlexCosting casts them to this currency (cost_process()).

Also records which utilities the tariff prices, so cost_process() can tell a carrier the tariff covers from one it does not.

build_process_costs() → None

No-op: flex-native process costs are built in cost_process(). Required override from IDAES FlowsheetCostingBlockData.

cost_process() → None

Aggregate energy, build the opex/capex blocks, enter operations mode.

Overrides the parent FlowsheetCostingBlockData.cost_process (whose aggregate_capital_cost Var would collide with the flex-native names): FlexCosting builds its own flex-native Vars/Constraints and does not invoke the parent aggregation machinery. Every derived quantity is a Var defined by an eq_<name> equality Constraint.

initialize_build() → None

No-op: FlexCosting builds only Vars/Constraints/Params, nothing to init. Required override from IDAES FlowsheetCostingBlockData.

register_scalar_cost(name: str, quantity, price: float, quantity_units, *, unit=None) → ScalarCostSpec

Register a non-energy scalar operating cost (never billed via EECO).

Costs an arbitrary time-indexed rate as price × Σ_t quantity[t] × dt — e.g. water withdrawal per m³, chemical dosing per kg, or a product-revenue credit (a negative price). Built entirely in flex-pse; EECO is not involved.

Parameters:
  • name – The cost’s name.

  • quantity – A time-indexed Var/Expression (a rate).

  • price – The signed price per unit quantity, in the currency basis (positive = cost, negative = revenue/credit).

  • quantity_units – The Pyomo units quantity is converted to before costing (a rate, e.g. m**3/hr).

  • unit – The unit block this cost is attributed to, or None for a facility-level cost; recorded for per-unit cost attribution.

Returns:

The stored ScalarCostSpec.

Raises:

FlexConfigError – If name was already registered.

register_sizing_variable(var, capex_constraint=None) → None

Register a sizing Var (and its capex constraint) for the mode toggles.

Parameters:
  • var – A sizing Var (e.g. battery/tank capacity) that set_operations_mode()/set_design_mode() fix/unfix.

  • capex_constraint – The capex-defining constraint the modes (de)activate, or None.

register_unit_power(unit, var, kind: PowerKind) → None

Record that unit associated a power draw with this costing package.

Called by register_power() when a unit is built with costing_package= set. The record is the explicit unit↔costing association used for capex attribution; power aggregation in cost_process() pulls from the model instead, so it does not depend on this being called.

Parameters:
  • unit – The unit block registering the draw.

  • var – The unit’s power-draw Var (kW).

  • kind – The PowerKind of the draw.

relaxation_gap(model, results, *, prev_demand_dict=None) → float

Return how much the in-objective proxy diverges from the reported bill.

Positive means the objective understated the reported bill (EECO dropped a tiered charge); negative means it overstated it.

Parameters:
  • model – The solved model (see report_cost()).

  • results – The solver results returned by solving model.

  • prev_demand_dict – See report_cost().

Returns:

reported bill − in-objective proxy, in the report’s currency.

Raises:

FlexSolverError – If results is not an optimal solve.

report_cost(model, *, prev_demand_dict=None, split_imports_exports: bool = False) → CostReport

Return the reported, categorized cost, evaluated post-solve.

The user-facing reported cost. Operating electricity/fuel are EECO post-hoc evaluations on the realized dispatch; fixed is the config constant; scalar costs are recomputed natively; DR revenue is 0 in v0 (containers-only); capital is read off the (empty in v0) capex block. This is an independent recomputation — never value(model.objective), which is a relaxed/scalarized proxy.

Parameters:
  • model – The solved model (accepted for the documented API; the costing block reads its own components).

  • prev_demand_dict – Optional prior-demand carry, for a future rolling-horizon workflow that is not yet built, so EECO bills only the demand incremental above the running peak, rather than recounting the peak in every window. None (default) bills the horizon standalone.

  • split_imports_exports – If True, also report each natively priced carrier’s import cost and export revenue (imports / exports on the operating breakdown), alongside the net electricity and fuel. Tariff-billed carriers are left out, as EECO bills them only as a net figure.

Returns:

The CostReport breakdown, whose currency names the basis every value in it is a magnitude in.

set_design_mode() → None

Unfix every registered sizing Var and activate its capex constraint.

The design objective is total_cost (operating + capital).

set_operations_mode() → None

Fix every registered sizing Var and deactivate its capex constraint.

The operations objective is aggregate_operating_cost alone. In the sizing registry is empty, so this is a no-op; it is the documented single-model toggle later milestones populate. Idempotent.