new_modeling_toolkit.core package
Subpackages
- new_modeling_toolkit.core.temporal package
- Submodules
- new_modeling_toolkit.core.temporal.new_temporal module
- new_modeling_toolkit.core.temporal.timeseries module
BooleanTimeseries
FractionalTimeseries
NoDateTimeseries
NumericTimeseries
Timeseries
DST
data
data_dir
freq_
timezone
type
weather_year
add_index()
add_leap_day()
default_factory()
dict()
from_annual_series()
from_csv()
from_dir()
infinity()
model_post_init()
one()
remove_leap_day()
repeat_ts()
resample_down()
resample_month_hour_to_hourly()
resample_month_or_season_hour_to_hourly()
resample_season_hour_to_hourly()
resample_simple_extend_years()
resample_up()
serialize_pd_series()
slice_by_timepoint()
slice_by_year()
to_json()
validate_data()
validate_timezone()
zero()
data_dict
days_in_year
freq
processed_dir
TimeseriesType
- Module contents
- new_modeling_toolkit.core.utils package
- Submodules
- new_modeling_toolkit.core.utils.core_utils module
- new_modeling_toolkit.core.utils.gurobi_utils module
- new_modeling_toolkit.core.utils.pandas_utils module
- new_modeling_toolkit.core.utils.parallelization_utils module
- new_modeling_toolkit.core.utils.pyomo_utils module
- new_modeling_toolkit.core.utils.string_utils module
- new_modeling_toolkit.core.utils.util module
- Module contents
Submodules
new_modeling_toolkit.core.component module
- class Component
Bases:
FromCSVMixIn
- Fields:
name (str | tuple)
- field attr_path: str | pathlib.Path | None = PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/e3-resolve/checkouts/latest/docs/source')
the path to the attributes file
- field include: Annotated[bool, Metadata(category=FieldCategory.BUILD)] = True
Include component in system.
- Constraints:
category = FieldCategory.BUILD
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- construct_investment_rules(model: ModelTemplate, construct_costs: bool)
Constructs the investment-related optimization formulation (decision variables, expressions, constraints, etc.) for the Component.
- Parameters:
model β the Model containing the necessary temporal settings information needed to construct the rules
construct_costs β whether cost-related investment terms should be constructed
- construct_modeling_block(model: ModelTemplate, construct_investment_rules: bool = True, construct_operational_rules: bool = True, construct_costs: bool = True) pyo.Block
Constructs a Pyomo Block containing all decision variables, expressions, parameters, constraints, and sets required for representing this Component as a member of an energy system.
This method assumes that the model argument is an instance of an E3 ModelTemplate which contains some universal time-indexing sets that are used in the construction of decision variables, constraints, etc.
- Parameters:
model β the Model to which the created Block should be attached
construct_investment_rules β whether rules related to investment decisions should be constructed
construct_operational_rules β whether rules related to operational decisions should be constructed
construct_costs β whether cost terms should be constructed
- Returns:
the constructed Pyomo Block
- Return type:
self.formulation_block
- construct_operational_rules(model: ModelTemplate, construct_costs: bool)
Constructs the operations-related optimization formulation (decision variables, expressions, constraints, etc.) for the Component.
- Parameters:
model β the Model containing the necessary temporal settings information needed to construct the rules
construct_costs β whether cost-related operational terms should be constructed
- copy(exclude: list[str] | None = None, include_linkages: bool = False, update: dict[str, Any] | None = None, new_class: Type | None = None)
Copy a component instance (and optionally convert it to a new component class type).
- classmethod dfs_to_csv(*, instances: pd.DataFrame, wb: Book, dir_str: DirStructure, compare_files: bool = True, dry_run: bool = False, save_path_override: pathlib.Path | None = None) None
Save DataFrame into (separate) component CSV files.
- export_component_result_summary(output_dir: Path, results_settings: dict) DataFrame
Loop through all pyomo objects on the formulation block and return all results objects with a labeled doc argument. Loop through all the input attributes on the class object and return all inputs with a title argument in the Field definition.
Concatenate all inputs and results by frequency of index and save to csv. Currently only implemented for non-indexed, annual, hourly, and chrono periods.
- Parameters:
output_dir β path to save summary results as csv
results_settings β dictionary indicating which sets of results to report
Returns: pd.DataFrame of annual results
- export_formulation_block_raw_results(output_dir: Path)
Save raw pyomo components to csv.
- Parameters:
output_dir β raw results directory
- extract_attribute_from_components(component_dict: None | Dict[str, Component], attribute: str)
Takes a dictionary with Components as the values and returns the dictionary with the same keys, but with the desired attribute extracted from the Components.
- Parameters:
component_dict β dictionary of Components
attribute β attribute to extract from each Component
- Returns:
dictionary containing the extracted attributes
- Return type:
component_attributes
- classmethod from_dir(data_path: PathLike, scenarios: list | None = None) dict[str, Component]
Read instances from directory of instances with attribute.csv files.
- Parameters:
data_path β
Returns:
- classmethod from_json(filepath: PathLike) Component
Reads JSON file back to Component object.
- classmethod get_metadata(field_name: str)
Get fieldβs Metadata() from annotation (or return an default Metadata() instance.
- classmethod model_fields_by_category() dict
Create a nested dictionary of model fields by category for UI (if specified in Metadata annotation).
- model_post_init(__context: Any) None
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since thatβs what pydantic-core passes when calling it.
- Parameters:
self β The BaseModel instance.
__context β The context.
- resample_ts_attributes(modeled_years: tuple[int, int], weather_years: tuple[int, int], resample_weather_year_attributes=True, resample_non_weather_year_attributes=True)
Resample timeseries attributes to the default frequencies to make querying via slice_by_timepoint and slice_by_year more consistent later.
Downsample data by comparing against a βcorrect indexβ with the correct default_freq
If data start year > modeled start year, fill timeseries backward
Create a temporary timestamp for the first hour of the year after the modeled end year to make sure we have all the hours, minutes (e.g., 23:59:59) filled in in step (4)
Resample to fill in any data (particularly at end of timeseries) and drop temporary timestamp from (3)
- revalidate()
Abstract method to run additional validations after Linkage.announce_linkage_to_instances.
- sum_attribute_from_components(component_dict: None | Dict[str, Component], attribute: str, timeseries: bool = False, skip_none: bool = False)
Extracts an attribute from all Components in component_dict and sums them. If the attributes are Timeseries objects, use timeseries=True. The skip_none argument will skip any Components for which the desired attribute has no value.
- Parameters:
component_dict β dictionary containing the Components (e.g. System.resources)
attribute β the desired attribute to sum
timeseries β whether or not the attribute is a timeseries
skip_none β whether or not to skip Components for which the attribute is None
- Returns:
the aggregated value across all Components
- Return type:
aggregate
- sum_timeseries_attributes(attributes: List[str], name: str, skip_none: bool = False) None | NumericTimeseries
Sums multiple attributes of the instance which are Timeseries objects.
- Parameters:
attributes β list of attributes to sum
name β name for the resulting Timeseries
skip_none β whether or not to skip attributes if they are None
- Returns:
a Timeseries that is the sum of the input attributes
- Return type:
result
- classmethod to_excel(*, anchor_range: Range, excel_api: ExcelApiCalls, modeled_years_range: list[int] = range(2020, 2051), modeled_years_visible: list | None = None, include: list[str] | None = None, exclude: list[str] | None = None, num_rows: int = 20, add_doc_hyperlinks: bool = True, linkages_to_write: list['LinkageFieldsToWrite'] | None = None, table_name: str)
Create a new user inputs tab in an Excel UI, using E3 Model Template.xlsm.
- class ExpressionContainer
Bases:
VarContainer
- Fields:
max (None | float | new_modeling_toolkit.core.temporal.timeseries.NumericTimeseries)
min (None | float | new_modeling_toolkit.core.temporal.timeseries.NumericTimeseries)
name (str | tuple)
value (None | float | new_modeling_toolkit.core.temporal.timeseries.NumericTimeseries)
- class VarContainer
Bases:
FromCSVMixIn
- Fields:
new_modeling_toolkit.core.custom_constraint module
- class CustomConstraintLHS
Bases:
Component
Note: stylistically, the team chose not to put any Pyomo blocks on linkages, so the workaround for custom constraints was to create a LHS component for the multipliers. In my opinion, this is confusing because making sure that CustomConstraintRHS, CustomConstraintLHS, and CustomConstraintLinkage are all correctly connected is challenging from a user experience standpoint.
- Fields:
attr_path ()
class_name ()
include ()
modeled_year_multiplier (new_modeling_toolkit.core.temporal.timeseries.NumericTimeseries)
name ()
- field additional_index: str | None = None
Additional variable index before the timestamp. Ex: for policy constraints
- field custom_constraints: dict[tuple | str, CustomConstraintLinkage] = {}
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
linkage_order = 2
default_exclude = True
- field modeled_year_multiplier: NumericTimeseries [Optional]
The left hand side annual multiplier of the instance pyomo component as a float. Will be added to the hourly target if applicable.
- field pyomo_component_name: str [Required]
The pyomo component name of the linked component to constrain.
- field weather_year_hourly_multiplier: NumericTimeseries | None [Optional]
The left hand side instance hourly multiplier of the instance pyomo component as a float. Will be multiplied with the annual multiplier if applicable.
- get_lhs_multiplier(index: Tuple[Timestamp], hourly: bool) float
- Parameters:
index β
hourly β bool, True if the RHS is hourly, include both annual and hourly multipliers
Returns: annual LHS component multiplier * hourly LHS component multiplier (if applicable)
- class CustomConstraintRHS
Bases:
Component
- Fields:
- field annual_target: NumericTimeseries [Optional]
The right hand side annual target of the custom constraints as a float. Will be added to the hourly target if applicable.
- field constraint_operator: ConstraintOperator [Required]
RHS {greater than, less than, equal to} sum(LHS)
- field custom_constraints: dict[tuple | str, CustomConstraintLinkage] = {}
Component variables to sum together as the lhs of the custom constraint
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
linkage_order = 1
default_exclude = True
- field weather_year_hourly_target: NumericTimeseries [Optional]
The right hand side hourly target of the custom constraints as a float. Will be added to the annual target if applicable.
- get_rhs_target(index: Tuple[Timestamp]) float
Return the custom constraint RHS target. All RHS have an annual target. If the constraint is indexed hourly as well, add the annual target to the hourly target. :param index: [modeled_year] for annual only or [modeled_year, dispatch_window, timestamp] for hourly
Returns: annual target at model year timestamp + hourly target at weather year hour timestamp (if applicable)
new_modeling_toolkit.core.custom_model module
- class FieldCategory(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- class Metadata(category: 'None | FieldCategory' = None, units: 'pint.Unit | str' = '', excel_short_title: 'str' = '', tools: 'None | set[ModelType]' = None, warning_bounds: 'tuple[float | int | None, float | int | None]' = (None, None), show_year_headers: 'bool' = True, linkage_order: "typing.Literal['from', 'to', 1, 2, 3, None]" = None, default_exclude: 'bool' = False)
Bases:
object
- category: None | FieldCategory = None
- tools: None | set[ModelType] = None
- class ModelType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
new_modeling_toolkit.core.excel module
new_modeling_toolkit.core.from_csv_mix_in module
- class FromCSVMixIn
Bases:
CustomModel
Base class to implement a standard from_csv class method to read from interim data folder.
- Fields:
name ()
- classmethod from_csv(filename: Path, scenarios: List | None = None, data: Dict | None = None, name: str | None = None) FromCSVMixIn
Create Component instance from CSV input file.
The CSV input file must have the following mandatory three-column format, with two optional columns (column order does not matter; however, column header names do matter):
timestamp
attribute
value
unit (optional)
scenario (optional)
[None or timestamp (hour beginning)]
[attribute name]
[value]
[unit name]
[scenario name]
Units
Unit conversion is handled by the
pint
Python package. Expected attribute units are hard-coded in the Python implementation. If the pint package can find an appropiate conversion between the user-specified input of the attribute and the expected unit, it will convert data automatically to the expected unit.For example, if the expected unit is MMBtu (named as million_Btu or MBtu in pint), a user can easily enter data in Btu, and the code will automatically divide the input value by 1e6.
Scenarios
Scenarios are handled via an optional scenario column. Scenario handling is done via some clever pandas DataFrame sorting. In detail:
The
scenario
column is converted to a pd.Categorical, which is an ordered list.The
scenario
columns is sorted based on the Categorical ordering, where values with no scenario tag (None
/NaN
) are lowest-priority.The method
df.groupby.last()
is used to take the last (highest-priority) value (since the dataframe should be sorted from lowest to highest priority scenario tag).Scenario tags that are not listed in scenarios.csv will be ignored completely (dropped from the dataframe).
Duplicate Values
If an attribute is defined multiple times (and for a timeseries, multiple times for the same timestamp), the last value entered in the CSV (i.e., furthest down the CSV rows) will be used.
- Parameters:
filename β Name of CSV input file. Defaults to
attributes.csv
.scenarios β List of optional scenario tags to filter input data in file. Defaults to [].
data β Additional data to add to the instance as named attributes. Defaults to {}.
Referencing Other CSVs for Timeseries Data
To keep the
attributes.csv
shorter, user can optionally enter the value of a timeseries as a file path to another CSV file instead of entering each timestamped data value inattributes.csv
. This is done by using theNone
timestamp and entering a string filepath for the value. Absolute paths are preferred for the sake of being explicit, though relative paths will be parsed relative to the top-levelnew-modeling-toolkit
folder.There are two limitations of this functionality:
It is not currently possible to βmix-and-matchβ timeseries data specified in the attributes.csv file and from other referenced CSV files. You must either (a) input timeseries data in
attributes.csv
with timestamps or (b) use theNone
timestamp and reference a different file.Timeseries data read from another CSV file does not currently benefit scenario-tagging capabilities. The filepath references themselves in
attributes.csv
can be scenario-tagged; however, the other CSV file is just read in as if it were apd.Series
with a DateTimeIndex.
- Returns:
Instance of Component class.
- Return type:
- classmethod from_dataframe(*, input_df: DataFrame, attr_path: Path | None = None, scenarios: list[str] | None = None, data: dict | None = None, name: str | None = None)
Create an instance of the class from an input DataFrame.
The input DataFrame will optionally be filtered by a list of scenarios ordered from lowest to highest priority. At least one of attr_path or name must be specified in order to name the newly created object.
- Parameters:
input_df β the input DataFrame to use to instantiate the class
attr_path β optional path to the CSV from which the input DataFrame was loaded
scenarios β optional list of scenarios used to filter the input DataFrame
data β optional dictionary of attribute data used to override data parsed from the input DataFrame
name β name for the new object
- Returns:
instance of the class
- Return type:
inst
new_modeling_toolkit.core.linkage module
- class AllToPolicy
Bases:
_AllToPolicy
- Fields:
attr_path ()
attribute (Annotated[str | None, Metadata(default_exclude=True)])
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier ()
name ()
- field attribute: Annotated[str | None, Metadata(default_exclude=True)] = None
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- class AnnualEnergyStandardContribution
Bases:
_AllToPolicy
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier (Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')])
name ()
- field multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')] = None
- Constraints:
units =
excel_short_title = %
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- class AssetToAssetGroup
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class AssetToCaisoTxConstraint
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class AssetToELCC
Bases:
Linkage
- Fields:
attr_path ()
attribute (Annotated[Literal['power', 'energy'], Metadata(default_exclude=True)])
class_name ()
include ()
instance_from ()
instance_to ()
multiplier (Annotated[float | None, Metadata(default_exclude=True)])
multiplier_unit (Annotated[str | None, Metadata(default_exclude=True)])
name ()
- field attribute: Annotated[Literal['power', 'energy'], Metadata(default_exclude=True)] = 'power'
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- field multiplier: Annotated[float | None, Metadata(default_exclude=True)] = None
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- field multiplier_unit: Annotated[str | None, Metadata(default_exclude=True)] = None
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- class AssetToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class BiomassResourceToCandidateFuel
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class CandidateFuelToFinalFuel
Bases:
XToFinalFuel
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
out_energy_demand ()
- class CandidateFuelToPollutant
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
gross_emissions_trajectory_override (Optional[ts.NumericTimeseries])
include ()
instance_from ()
instance_to ()
name ()
net_emissions_trajectory_override (Optional[ts.NumericTimeseries])
upstream_emissions_trajectory_override (Optional[ts.NumericTimeseries])
- class CandidateFuelToResource
Bases:
Linkage
Linkage between new_modeling_toolkit.common.fuel.CandidateFuel and new_modeling_toolkit.common.resource.Resource.
Houses the data related to both resources & candidate fuels (e.g., fuel burn coefficients).
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ELCCFacetToSurface
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ELCCReliabilityContribution
Bases:
_AllToPolicy
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier ()
name ()
- class ERMContribution
Bases:
_AllToPolicy
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier (Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')])
name ()
- field multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')] [Optional]
- Constraints:
units =
excel_short_title = %
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- class ElectrolyzerToCandidateFuel
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ElectrolyzerToFuelZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ElectrolyzerToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class EmissionsContribution
Bases:
_AllToPolicy
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
name ()
- field multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='tonne/MWh', units=units.tonne / units.MWh)] = None
- Constraints:
units = metric_ton / megawatt_hour
excel_short_title = tonne/MWh
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- class FinalFuelToAnnualEmissionsPolicy
Bases:
AllToPolicy
Temporary subclass only so that final fuels are correctly linked to annual emissions policies.
- Fields:
attr_path ()
attribute ()
class_name ()
forward_dir_multiplier ()
fully_deliverable ()
include ()
instance_from ()
instance_to ()
multiplier ()
name ()
reverse_dir_multiplier ()
- class FinalFuelToFuelZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FromZoneToPath
Bases:
ZoneToTransmissionPath
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
name ()
to_zone ()
- class FuelConversionPlantToCandidateFuel
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelConversionPlantToFuelZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelConversionPlantToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelStorageToCandidateFuel
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelStorageToFuelZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelStorageToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelZoneToCandidateFuel
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class FuelZoneToElectricZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class HourlyEnergyStandardContribution
Bases:
_AllToPolicy
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier (Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')])
name ()
- field multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')] = None
- Constraints:
units =
excel_short_title = %
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- class HybridStorageResourceToHybridVariableResource
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
paired_charging_constraint_active_in_year (ts.NumericTimeseries)
- field grid_charging_allowed: bool | None = False
If True, hybrid_storageβs power_input must not exceed hybrid_variableβs power_output.
- field paired_charging_constraint_active_in_year: ts.NumericTimeseries [Optional]
If 1, the charging constraint is active in the year. If 0, the charging constraint is not active in the year.
- field pairing_ratio: float | None = None
If specified, ratio of operational capacity of hybrid_variable to that of hybrid_storage resources. Usually set to 1.
- Constraints:
ge = 0
- model_post_init(_ModelMetaclass__context: Any) None
We need to both initialize private attributes and call the user-defined model_post_init method.
- class IncrementalReserveType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- class Linkage
Bases:
Component
A generalized representation of all sorts of connection between either different component instances, or different instances of the same class. By definition and for convenience, the linkage has to be one-directional, even in reality this directionality might not mean much
- Fields:
attr_path ()
class_name ()
include ()
name ()
- field instance_from: component.Component | None = None
- field instance_to: component.Component | None = None
- announce_linkage_to_instances()
Iterate through all linkages in Linkages._instances to append instances as attributes to mapped instances.
- In other words, if we have:
r = Resource(name=βCCGTβ, β¦) f = Fuel(name=βnatural_gasβ, β¦) l = Linkage(instance_from=r, instance_to=f)
- This method will:
Append r.fuels = {βnatural_gasβ: f}
Append f.resource = {βCCGTβ: r}
So that itβs easy to find the necessary attributes from linked instances (e.g., fuel burn associated with a fuel being burned in a certain resource)
- classmethod dfs_to_csv(*, instances: pd.DataFrame, wb: Book, dir_str: DirStructure, compare_files: bool = True, dry_run: bool = False) None
Save DataFrame into (separate) component CSV files.
- dict(**kwargs)
Need to exclude instance_from, instance_to attributes to avoid recursion error when saving to JSON.
- classmethod from_dir(dir_path: PathLike, linkages_df: DataFrame, components_dict: dict[str, Component], linkages_csv_path: Path, scenarios: list = [])
Create Linkage instances based on prescribed CSV files.
- This method relies on one class attribute:
SAVE_PATH: Optional filename for static & dynamic attributes of the Linkage instance
- Parameters:
dir_path β Path to CSV file
instances_from β Dict of Component instances to reference in linkage.
instances_to β Dict of Component instances to reference in linkage.
- model_post_init(_ModelMetaclass__context: Any) None
We need to both initialize private attributes and call the user-defined model_post_init method.
- class LinkageRelationshipType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- class LoadToReserve
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
incremental_requirement_hourly_scalar (ts.FractionalTimeseries)
incremental_requirement_hourly_scalar__type (ts.TimeseriesType)
instance_from ()
instance_to ()
name ()
- class LoadToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ReliabilityContribution
Bases:
_AllToPolicy
- Fields:
attr_path ()
attribute (Annotated[str | None, Metadata(default_exclude=True)])
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier (Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')])
name ()
- field attribute: Annotated[str | None, Metadata(default_exclude=True)] = None
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- field multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='%')] = None
- Constraints:
units =
excel_short_title = %
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- class ReserveToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
incremental_requirement_hourly_scalar (ts.FractionalTimeseries)
incremental_requirement_hourly_scalar__type (ts.TimeseriesType)
instance_from ()
instance_to ()
name ()
- field incremental_requirement_hourly_scalar: ts.FractionalTimeseries [Optional] (alias 'requirement_fraction_of_gross_load')
- class ResourceToFuelZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ResourceToOutageDistribution
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ResourceToPollutant
Bases:
Linkage
Defines the linkage between resources and pollutants. Used if emission factors are set on the resource to pollutant level rather than the resource to fuel to pollutant level.
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ResourceToReserve
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
dependent_on (Annotated[str, Metadata(default_exclude=True)])
include ()
incremental_requirement_annual_scalar (ts.NumericTimeseries)
incremental_requirement_hourly_scalar (ts.NumericTimeseries)
incremental_requirement_hourly_scalar__type (ts.TimeseriesType)
instance_from ()
instance_to ()
max_fraction_of_capacity (Annotated[float, Field(ge=0, le=1)])
name ()
- field dependent_on: Annotated[str, Metadata(default_exclude=True)] = 'setpoint'
Operating reserves are usually related to a resourceβs setpoint (i.e., online head/footroom). Certain resources (e.g., inertia) are only related to online/committed capacity.**Note: RESOLVE cannot currently represent non-spinning reserves.**
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- field exclusive: Annotated[bool, Metadata(default_exclude=True)] = True
- Constraints:
units =
excel_short_title =
warning_bounds = (None, None)
show_year_headers = True
default_exclude = True
- field incremental_requirement_hourly_scalar: ts.NumericTimeseries [Optional] (alias 'incremental_requirement')
- field max_fraction_of_capacity: Annotated[float, Field(ge=0, le=1)] = 0
Max % of a resourceβs online capacity (e.g., committed capacity for unit commitment resources) that can be used to provide operating reserve.
- Constraints:
ge = 0
le = 1
- field scalar_type: IncrementalReserveType = IncrementalReserveType.OPERATIONAL_CAPACITY
- class ResourceToResourceGroup
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ResourceToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ToZoneToPath
Bases:
ZoneToTransmissionPath
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
from_zone ()
include ()
instance_from ()
instance_to ()
name ()
- class TrancheToAsset
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class TransmissionPathToPollutant
Bases:
Linkage
Defines the linkage between transmission paths and pollutants. Used to set emission factors for Tx lines.
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class TxEmissionsContribution
Bases:
EmissionsContribution
- Fields:
attr_path ()
class_name ()
component_type_from_ ()
component_type_to_ ()
include ()
instance_from ()
instance_to ()
multiplier ()
name ()
- field forward_dir_multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='Rate', units=units.tonne / units.MWh)] = None
- Constraints:
units = metric_ton / megawatt_hour
excel_short_title = Rate
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- field reverse_dir_multiplier: Annotated[ts.NumericTimeseries | None, Metadata(excel_short_title='Rate', units=units.tonne / units.MWh)] = None
- Constraints:
units = metric_ton / megawatt_hour
excel_short_title = Rate
warning_bounds = (None, None)
show_year_headers = True
default_exclude = False
- class XToFinalFuel
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- class ZoneToTransmissionPath
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
- classmethod linkage_is_from_zone_xor_to_zone(values)
Validate that exactly one of from_zone and to_zone is set to True.
- class ZoneToZone
Bases:
Linkage
- Fields:
attr_path ()
class_name ()
include ()
instance_from ()
instance_to ()
name ()
new_modeling_toolkit.core.model module
- class ConstraintOperator(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- class ModelTemplate(*args, **kwds)
Bases:
ConcreteModel
,ABC
Canβt make a child class that inherits both from Pydantic and Pyomo, so seems like this is all I can do for now.
- TYPE: ModelType = 'Template'
- property contains_integer_variables: bool
True if integer variables exist in the model
- Type:
Returns
- property integer_variables_list: list[Var]
Return a list of all integer or binary variable components
- return_timepoints_connecting_chrono_periods(modeled_year: Timestamp, chrono_period: Timestamp) Tuple[Tuple[Timestamp, Timestamp, Timestamp], Tuple[Timestamp, Timestamp, Timestamp]]
Return the dispatch window indexes that connect two chrono periods- last timepoint of dispatch_window[t] <-> first timepoint of dispatch_window[t+1]
- Parameters:
modeled_year β pd.Timestamp of model year index
chrono_period β pd.Timestamp of chrono_period[t] index
- Returns: chrono_period_1_index(modeled_year: pd.Timestamp, dispatch_window[t]: pd.Timestamp, last timepoint in dispatch_window[t]),
chrono_period_2_index(modeled_year: pd.Timestamp, dispatch_window[t+1]: pd.Timestamp, first timepoint in dispatch_window[t+1])
- sum_timepoint_component_slice_to_annual(model_component_slice: IndexedComponent_slice)
Computes the βannual sumβ using dispatch-window-weights of a slice of a modeling component that is indexed by DISPATCH_WINDOWS and TIMESTAMPS, among other things. For example, if the power output of a resource is defined as:
block.power_output = pyo.Expression(model.MODELED_YEARS, model.DISPATCH_WINDOWS_AND_TIMESTAMPS, rule=_power_output_rule)
Then the βtotal annual power outputβ as determined using dispatch-window-weights for the 2030 snapshot year can be calculated by doing
sum_timepoint_component_slice_to_annual(block.power_output[2030, :, :])
- Parameters:
model_component_slice β the slice of the component that should be summed
- Returns:
an Expression of the weighted annual sum of the slice
- Return type:
annual_sum
- sum_weather_timestamp_component_slice_to_annual(model_component_slice: IndexedComponent_slice)
Computes the βannual sumβ using a slice of a modeling component that is indexed by WEATHER_PERIODS and WEATHER_TIMESTAMPS. This works similarly to sum_timepoint_component_slice_to_annual, except there is no weighting by dispatch window.
That is, the sum of a weather_timestamp-indexed variable is simply the average value multiplied by number of hours in the modeled year.
- Parameters:
model_component_slice β the slice of the component that should be summed
- Returns:
an Expression of the weighted annual sum of the slice
- Return type:
annual_sum
new_modeling_toolkit.core.three_way_linkage module
- class CustomConstraintLinkage
Bases:
ThreeWayLinkage
- Fields:
- field instance_1: Component | None [Required]
- field instance_2: Component | None [Required]
- field instance_3: Component | None [Required]
- model_post_init(_ModelMetaclass__context: Any) None
We need to both initialize private attributes and call the user-defined model_post_init method.
- return_valid_index(index: Tuple[Timestamp])
Return index of variable to constrain
- Parameters:
index β [modeled_year] for annual only or [modeled_year, dispatch_window, timestamp] for hourly
Returns: (additional index str, modeled year [,dispatch windows, timestamp if hourly constraint],)
- classmethod to_excel(*, anchor_range, excel_api: ExcelApiCalls, **kwargs)
Since instances 1-3 have different names in table headers, need a custom to_excel method for custom constraints.
- property is_annual
Bool. Assumes a variable must be either hourly or annually indexed. Returns: True if variable index does not include hourly timestamps.
- property is_hourly
Bool. Assumes a variable must be either hourly or annually indexed. Returns: True if index includes hourly timestamps.
- class SectorCandidateFuelBlending
Bases:
ThreeWayLinkage
Three-way linkage used to set candidate fuel to final fuel blending by sector.
- Fields:
attr_path ()
blend_override (new_modeling_toolkit.core.temporal.timeseries.FractionalTimeseries | None)
class_name ()
include ()
instance_1 ()
instance_2 ()
instance_3 ()
name ()
- field blend_override: FractionalTimeseries | None = None
- class ThreeWayLinkage
Bases:
Component
A generalized representation of all sorts of connection between either three component instances component instances, or three different instances of the same class. By definition and for convenience, the linkage has to be one-directional, even in reality this directionality might not mean much.
Note that this linkage type should only be used when chained Linkages do not suffice. A specific use case for this linkage type is controlling fuel switching within a given EnergyDemandSubsector instance. Such fuel switching is likely to be idiosyncratic to the instance. An example would be natural gas to hydrogen fuel switching within two industrial subsectors. One subsector may switch to entirely to hydrogen, while one might switch only 5% of natural gas demand. Such a linkage enables control of fuel switching extent within each subsector without a need for extensive preprocessing.
- Fields:
- field instance_1: Component | None [Required]
- field instance_2: Component | None [Required]
- field instance_3: Component | None [Required]
- announce_linkage_to_instances()
Iterate through all linkages in ThreeWayLinkages._instances to append instances as attributes to mapped instances.
- In other words, if we have:
s = EnergyDemandSubsector() f1 = Fuel() f2 = Fuel() three_way_linkage = ThreeWayLinkage(instance_1=s, instance_2=f1, instance_3=f2)
- This method will:
Append s.three_way_linkage_attribute = {(f1.name,f2.name):three_way_linkage}
Append f1.three_way_linkage_attribute = {(s.name,f2.name):three_way_linkage}
Append f2.three_way_linkage_attribute = {(s.name,f1.name):three_way_linkage}
So that itβs easy to find the necessary attributes from linked instances (e.g., fuel switching from one final fuel to another within and energy-only subsector in PATHWAYS)
Note that three-way linkages as attributes under the components they are linking are denoted by a tuple of strings. Further, the attribute name itself cannot be cleanly mapped back to a single instance of a Component subclass because linked components may not be of the same class.
- classmethod dfs_to_csv(*, instances: DataFrame, wb: Book, dir_str: DirStructure, compare_files: bool = True, dry_run: bool = False) None
Save DataFrame into (separate) component CSV files.
- classmethod from_dir(dir_path: PathLike, linkage_pairs: list[tuple[str, str, str]], components_dict: dict[str, Component], scenarios: list = [])
Create Linkage instances based on prescribed CSV files.
- This method relies on one class attribute:
SAVE_PATH: Optional filename for static & dynamic attributes of the Linkage instance
- Parameters:
dir_path β Path to CSV file
instances_1 β Dict of Component instances to reference in linkage.
instances_2 β Dict of Component instances to reference in linkage.
instances_3 β Dict of Component instances to reference in linkage.