FlexCostingData¶
- class flexops.costing.flex_costing.FlexCostingData(component)¶
EECO-backed costing block with
opex/capexsub-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
drcontainer) but builds no aggregation, noopex/capexsub-blocks, and no DR constraints here — everything is deferred tocost_process()so the block may be constructed before any units exist (the construction-order invariant).- Raises:
FlexConfigError – If not exactly one of
tariff_file/tariffis given,time_blockis missing, anexport_priceskey has noenergy_pricesentry, 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 chargeunitscolumn); otherwise it is the configuredcurrency. 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/capexblocks, enter operations mode.Overrides the parent
FlowsheetCostingBlockData.cost_process(whoseaggregate_capital_costVar 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 aVardefined by aneq_<name>equalityConstraint.
- 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 negativeprice). 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
quantityis converted to before costing (a rate, e.g.m**3/hr).unit – The unit block this cost is attributed to, or
Nonefor a facility-level cost; recorded for per-unit cost attribution.
- Returns:
The stored
ScalarCostSpec.- Raises:
FlexConfigError – If
namewas 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) thatset_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
unitassociated a power draw with this costing package.Called by
register_power()when a unit is built withcosting_package=set. The record is the explicit unit↔costing association used for capex attribution; power aggregation incost_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
PowerKindof 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
resultsis 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
0in v0 (containers-only); capital is read off the (empty in v0) capex block. This is an independent recomputation — nevervalue(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/exportson the operating breakdown), alongside the netelectricityandfuel. Tariff-billed carriers are left out, as EECO bills them only as a net figure.
- Returns:
The
CostReportbreakdown, whosecurrencynames the basis every value in it is a magnitude in.