smif package¶
Submodules¶
smif.decision module¶
The decision module handles the three planning levels
Currently, only pre-specified planning is implemented.
The choices made in the three planning levels influence the set of interventions and assets available within a model run.
The interventions available in a model run are stored in the
InterventionRegister.
When pre-specified planning are declared, each of the corresponding interventions in the InterventionRegister are moved to the BuiltInterventionRegister.
Once pre-specified planning is instantiated, the action space for rule-based and optimisation approaches can be generated from the remaining Interventions in the InterventionRegister.
-
class
smif.decision.Planning(planned_interventions=None)[source]¶ Bases:
objectHolds the list of planned interventions, where a single planned intervention is an intervention with a build date after which it will be included in the modelled systems.
For example, a small pumping station might be built in Oxford in 2045:
{ 'name': 'small_pumping_station', 'build_date': 2045 }
-
planned_interventions¶ list – A list of pre-specified planned interventions
-
names¶ Returns the set of assets defined in the planned interventions
-
timeperiods¶ Returns the set of build dates defined in the planned interventions
-
smif.intervention module¶
This module handles the collection of interventions and assets in a sector. The set of interventions describes the targets of possible physical (or non-physical) decisions which can be made in the sector.
An Asset is the general term for an existing component of an infrastructure system.
The difference between an Intervention and an Asset, is that the latter exists (it has been “built”), whereas the former describes the potential to build an Asset.
The set of assets defines the ‘state’ of the infrastructure system.
Notes
This module implements:
- initialisation of the set of assets from model config (either a collection of yaml
text files, or a database)
- hold generic list of key/values
- creation of new assets by decision logic (rule-based/optimisation solver)
- maintain or derive set of possible assets
- makes the distinction between known-ahead values and build-time values. Location and date are specified at build time, while cost and capacity are a function of time and location.
- serialisation for passing to models
- ease of access to full generic data structure
- output list of assets for reporting
- write out with legible or traceable keys and units for verification and understanding
Terminology
- name:
- A category of infrastructure intervention (e.g. power station, policy) which holds default attribute/value pairs. These names can be inherited by asset/intervention definitions to reduce the degree of duplicate data entry.
- asset:
- An instance of an intervention, which represents a single investment
decisions which will take place, or has taken place.
Historical interventions are defined as initial conditions, while
future interventions are listed as pre-specified planning.
Both historical and future interventions can make use of names to
ease data entry. Assets must have
location,build_dateandnameattributes defined. - intervention:
- A potential asset or investment.
Interventions are defined in the same way as for assets,
cannot have a
build_datedefined.
-
class
smif.intervention.Asset(name='', data=None, sector='')[source]¶ Bases:
smif.intervention.InterventionAn instance of an intervention with a build date.
Used to represent pre-specified planning and existing infrastructure assets and interventions
Parameters: -
build_date¶ The build date of this asset instance (if specified - asset types will not have build dates)
-
-
class
smif.intervention.AssetRegister[source]¶ Bases:
smif.intervention.RegisterRegister each asset type
-
class
smif.intervention.Intervention(name='', data=None, sector='')[source]¶ Bases:
smif.intervention.InterventionContainerAn potential investment to send to the logic-layer
An Intervention, is an investment which has a name (or name), other attributes (such as capital cost and economic lifetime), and location, but no build date.
The set of interventions are defined within each sector, and these are collected into an
InterventionRegisterwhen asmif.controller.SosModelis instantiated by the controller at runtime.Parameters: -
location¶ The location of this asset instance (if specified - asset types may not have explicit locations)
-
-
class
smif.intervention.InterventionContainer(name='', data=None, sector='')[source]¶ Bases:
objectAn container for asset types, interventions and assets.
An asset’s data is set up to be a flexible, plain data structure.
Parameters: -
static
deterministic_dict_to_str(data)[source]¶ Return a reproducible string representation of any dict
Parameters: data (dict) – An intervention attributes dictionary Returns: A reproducible string representation Return type: str
-
get_attributes()[source]¶ Override to return two lists, one containing required attributes, the other containing omitted attributes
Returns: Tuple of lists, one contained required attributes, the other which must be omitted Return type: tuple
-
sector¶ The name of the sector model this asset is used in.
-
static
-
class
smif.intervention.InterventionRegister[source]¶ Bases:
smif.intervention.RegisterThe collection of Intervention objects
An InterventionRegister contains an immutable collection of sector specific assets and decision points which can be decided on by the Logic Layer
- Reads in a collection of interventions defined in each sector model
- Builds an ordered and immutable collection of interventions
- Provides interfaces to
- optimisation/rule-based planning logic
- SectorModel class model wrappers
Key functions:
- outputs a complete list of asset build possibilities (asset type at location) which are (potentially) constrained by the pre-specified planning instructions and existing infrastructure.
- translate a binary vector of build instructions (e.g. from optimisation routine) into Asset objects with human-readable key-value pairs
- translates an immutable collection of Asset objects into a binary vector to pass to the logic-layer.
Notes
Internal data structures
- Intervention_types
- is a 2D array of integers: each entry is an array representing an Intervention type, each integer indexes attribute_possible_values
- attribute_keys
- is a 1D array of strings
- attribute_possible_values
- is a 2D array of simple values, possibly (boolean, integer, float, string, tuple). Each entry is a list of possible values for the attribute at that index.
Invariants
- there must be one name and one list of possible values per attribute
- each Intervention type must list one value for each attribute, and that value must be a valid index into the possible_values array
- each possible_values array should be all of a single type
-
attribute_value_index(attr_idx, value)[source]¶ Get the index of a possible value for a given attribute index
-
numeric_to_intervention(numeric_asset)[source]¶ Convert the numeric representation of an asset back to Asset (with legible key/value data)
Parameters: numeric_asset (list) – A list of integers of length self._attribute_keys Returns: An InterventionobjectReturn type: Intervention Examples
Given a (very minimal) possible state of a register:
>>> register = AssetRegister() >>> register._names = [[1,1,1]] >>> register._attribute_keys = ["name", "capacity", "sector"] >>> register._attribute_possible_values = [ ... [None, "water_treatment_plant"], ... [None, {"value": 5, "units": "ML/day"}], ... [None, "water_supply"] ... ]
Calling this function would piece together the asset:
>>> asset = register.numeric_to_asset([1,1,1]) >>> print(asset) Asset("water_treatment_plant", {"name": "water_treatment_plant", "capacity": {"units": "ML/day", "value": 5}, "sector": "water_supply"})
-
register(intervention)[source]¶ Add a new intervention to the register
Parameters: intervention ( Intervention) –
smif.metadata module¶
Encapsulates the input or output parameters of a sector model, for example:
- name: petrol_price
spatial_resolution: GB
temporal_resolution: annual
units: £/l
- name: diesel_price
spatial_resolution: GB
temporal_resolution: annual
units: £/l
- name: LPG_price
spatial_resolution: GB
temporal_resolution: annual
units: £/l
-
class
smif.metadata.Metadata(name, spatial_resolution, temporal_resolution, units)[source]¶ Bases:
objectAll metadata about a single dataset, typically model input or output
Parameters: - name (str) – The dataset name
- spatial_resolution (
smif.convert.region.RegionSet) – The region set that defines the spatial resolution - temporal_resolution (
smif.convert.interval.IntervalSet) – The interval set that defines the temporal resolution - units (str) – Name of the units for the dataset values
-
class
smif.metadata.MetadataSet(metadata_list)[source]¶ Bases:
objectA container for metadata about model inputs or outputs
Parameters: metadata (list) – A list of dicts like
{ 'name': 'heat_demand' 'spatial_resolution': smif.convert.ResolutionSet 'temporal_resolution': smif.convert.ResolutionSet 'units': 'kW' }
Or, a list of smif.metadata.Metadata
- Metadata(‘heat_demand’,
- smif.convert.area.RegionSet, smif.convert.interval.IntervalSet, ‘kW’)
-
add_metadata(metadata_item)[source]¶ Add an item to the set
Parameters: metadata_item (dict) – A dictionary with keys ‘name’, ‘spatial resolution’, ‘temporal resolution’ and ‘units’
-
add_metadata_object(metadata_object)[source]¶ Add an metadata object to the set
Parameters: metadata_object (Metadata) – A smif.metadata.Metadata instance
-
get_spatial_res(name)[source]¶ The spatial resolution for parameter name
Parameters: name (str) – The name of a model parameter
-
get_temporal_res(name)[source]¶ The temporal resolution for parameter name
Parameters: name (str) – The name of a model parameter
-
get_units(name)[source]¶ The units used for parameter ‘name’
Parameters: name (str) – The name of a model parameter
-
metadata¶ A list of the model parameters
Returns: parameters – A list of smif.Metadata, sorted by nameReturn type: list
-
names¶ A list of the parameter names
-
spatial_resolutions¶ A list of the spatial resolutions
Returns: A list of the spatial resolutions associated with the model parameters Return type: list
smif.modelrun module¶
The Model Run collects scenarios, timesteps, narratives, and model collection into a package which can be built and passed to the ModelRunner to run.
The ModelRunner is responsible for running a ModelRun, including passing in the correct data to the model between timesteps and calling to the DecisionManager to obtain decisions.
ModeRun has attributes: - id - description - sosmodel - timesteps - scenarios - narratives - strategy - status
-
class
smif.modelrun.ModelRun[source]¶ Bases:
object-
model_horizon¶ Returns the list of timesteps
Returns: A list of timesteps, distinct and sorted in ascending order Return type: list
-
name¶ Unique identifier of the ModelRun
-
-
class
smif.modelrun.ModelRunBuilder[source]¶ Bases:
objectBuilds the ModelRun object from the configuration
-
construct(config_data)[source]¶ Set up the whole ModelRun
Parameters: config_data (dict) – A valid system-of-systems model configuration dictionary
-
smif.optimisation module¶
Implements the interface to optimization functionality
This module defines an OptimizerTemplate which lays out the fundamental
steps of any optimization algorithm. To implement your own algorithm, create a
child class which inherits OptimizerTemplate and implement the methods.
-
class
smif.optimisation.OptimizerTemplate[source]¶ Bases:
abc.ABC-
initialize(available_interventions)[source]¶ Setup the optimization problem
Parameters: available_interventions (int) – The number of dimensions
-
optimization_function¶ The function which will be minimized by the algorithm
The optimization function should return a scalar and accept a vector of binary decision variables
-
results¶ The results from a successful optimization
-