smif.model.sector_model module¶
This module acts as a bridge to the sector models from the controller
The SectorModel
exposes several key methods for running wrapped
sector models. To add a sector model to an instance of the framework,
first implement SectorModel
.
Utility Methods¶
A number of utility methods are included to ease the integration of a SectorModel wrapper within a System of Systems model. These include:
get_region_names(region_set_name)
- gets a list of region namesget_interval_names(interval_set_name)
- gets a list of interval names
Key Functions¶
This class performs several key functions which ease the integration of sector models into the system-of-systems framework.
The user must implement the various abstract functions throughout the class to
provide an interface to the sector model, which can be called upon by the
framework. From the model’s perspective, SectorModel
provides a bridge
from the sector-specific problem representation to the general representation
which allows reasoning across infrastructure systems.
The key functions include:
- converting input/outputs to/from geographies/temporal resolutions
- converting control vectors from the decision layer of the framework, to asset Interventions specific to the sector model
- returning scaler/vector values to the framework to enable measurements of performance, particularly for the purposes of optimisation and rule-based approaches
Summary¶
Classes:
SectorModel |
A representation of the sector model with inputs and outputs |
SectorModelBuilder |
Build the components that make up a sectormodel from the configuration |
Reference¶
-
class
smif.model.sector_model.
SectorModel
(name)[source]¶ Bases:
smif.model.Model
A representation of the sector model with inputs and outputs
Implement this class to enable integration of the wrapped simulation model into a system-of-system model.
Parameters: name (str) – The unique name of the sector model Notes
Implement the various abstract functions throughout the class to provide an interface to the simulation model, which can then be called upon by the framework.
The key methods in the SectorModel class which need to be overridden are:
A number of utility methods are included to ease the integration of a SectorModel wrapper within a System of Systems model. These include:
get_region_names(region_set_name)
- Get a list of region namesget_interval_names(interval_set_name)
- Get a list of interval names
For example, within the implementation of the simulate method, call:
self.get_region_names('lad')
to return a list of region names defined in the region register at runtime.
-
add_input
(name, spatial_resolution, temporal_resolution, units)[source]¶ Add an input to the sector model
The inputs should be specified in a list. For example:
- name: electricity_price spatial_resolution: GB temporal_resolution: annual units: £/kWh
Parameters: - name (str) –
- spatial_resolution (
smif.convert.area.RegionSet
) – - temporal_resolution (
smif.convert.interval.IntervalSet
) – - units (str) –
-
add_output
(name, spatial_resolution, temporal_resolution, units)[source]¶ Add an output to the sector model
Parameters: - name (str) –
- spatial_resolution (
smif.convert.area.RegionSet
) – - temporal_resolution (
smif.convert.interval.IntervalSet
) – - units (str) –
-
intervention_names
¶ The names of the interventions
Returns: A list of the names of the interventions Return type: list
-
initialise
(initial_conditions)[source]¶ Implement this method to set up the model system
This method is called as the SectorModel is constructed, and prior to establishment of dependencies and other data links.
Parameters: initial_conditions (list) – A list of past Interventions, with build dates and locations as necessary to specify the infrastructure system to be modelled.
-
before_model_run
(data)[source]¶ Implement this method to conduct pre-model run tasks
Parameters: data (smif.data_layer.DataHandle) – Access parameter values (before any model is run, no dependency input data or state is guaranteed to be available)
-
simulate
(data)[source]¶ Implement this method to run the model
Parameters: data (smif.data_layer.DataHandle) – Access state, parameter values, dependency inputs Notes
See docs on
smif.data_layer.DataHandle
for details of how to access inputs, parameters and state and how to set results.interval
- should reference an id from the interval set corresponding to the output parameter, as specified in model configuration
region
- should reference a region name from the region set corresponding to the output parameter, as specified in model configuration
To obtain simulation model data in this method, use the data_handle methods such as:
parameter_value = data.get_parameter('my_parameter_name')
Other useful methods are
get_base_timestep_data(input_name)
,get_previous_timestep_data(input_name)
,get_parameter(parameter_name)
,get_data(input_name, timestep=None)
,get_parameters()
andget_results(output_name, model_name=None, modelset_iteration=None, decision_iteration=None, timestep=None)
.
-
extract_obj
(results)[source]¶ Implement this method to return a scalar value objective function
This method should take the results from the output of the
simulate()
method, process the results, and return a scalar value which can be used as a component of the objective function by the decision layerParameters: results (dict) – A nested dict of the results from the simulate()
methodReturns: A scalar component generated from the simulation model results Return type: float
-
get_region_names
(region_set_name)[source]¶ Get the unordered list of region names for
region_set_name
Returns: A list of region names Return type: list
-
get_regions
(region_set_name)[source]¶ Get the list of regions for
region_set_name
Returns: A list of GeoJSON-style dicts Return type: list
-
class
smif.model.sector_model.
SectorModelBuilder
(name, sector_model=None)[source]¶ Bases:
object
Build the components that make up a sectormodel from the configuration
Parameters: - name (str) – The name of the sector model
- sector_model (smif.model.SectorModel, default=None) – The sector model object
Returns: Return type: SectorModel
Examples
Call
SectorModelBuilder.construct()
to populate aSectorModel
object andSectorModelBuilder.finish()
to return the validated and dependency-checked system-of-systems model.>>> builder = SectorModelBuilder(name, secctor_model) >>> builder.construct(config_data) >>> sos_model = builder.finish()
-
construct
(sector_model_config, timesteps)[source]¶ Constructs the sector model
Parameters: sector_model_config (dict) – The sector model configuration data
-
add_parameters
(parameter_config)[source]¶ Add parameter configuration to sector model
Parameters: parameter_config (list) – A list of dicts with keys name
,description
,absolute_range
,suggested_range
,default_value
,units
,parent
-
add_interventions
(intervention_list)[source]¶ Add interventions to the sector model
Parameters: intervention_list (list) – A list of dicts of interventions
-
static
intervention_state_from_data
()[source]¶ Unpack an intervention from the initial system to extract StateData