smif.model package

Implements a composite scenario/sector model/system-of-systems model

Begin by declaring the atomic units (scenarios and sector models) which make up a the composite system-of-systems model and then add these to the composite. Declare dependencies by using the add_dependency() method, passing in a reference to the source model object, and a pointer to the model output and sink parameter name for the destination model.

Run the model by calling the simulate() method, passing in a dictionary containing data for any free hanging model inputs, not linked through a dependency. A fully defined SosModel should have no hanging model inputs, and can therefore be called using simulate() with no arguments.

Responsibility for passing required data to the contained models lies with the calling class. This means data is only ever passed one layer down. This simplifies the interface, and allows as little or as much hiding of data, dependencies and model inputs as required.

Example

A very simple example with just one scenario:

>>> elec_scenario = ScenarioModel('scenario')
>>> elec_scenario.add_output('demand', 'national', 'annual', 'GWh')
>>> sos_model = SosModel('simple')
>>> sos_model.add_model(elec_scenario)
>>> sos_model.simulate(2010)
{'scenario': {'demand': array([123])}}

A more comprehensive example with one scenario and one scenario model:

>>> elec_scenario = ScenarioModel('scenario')
>>> elec_scenario.add_output('demand', 'national', 'annual', 'GWh')
>>> class EnergyModel(SectorModel):
...   def extract_obj(self):
...     pass
...   def initialise(self):
...     pass
...   def simulate(self, timestep, data):
...     return {self.name: {'cost': data['input'] * 2}}
...
>>> energy_model = EnergyModel('model')
>>> energy_model.add_input('input', 'national', 'annual', 'GWh')
>>> energy_model.add_dependency(elec_scenario, 'demand', 'input', lambda x: x)
>>> sos_model = SosModel('sos')
>>> sos_model.add_model(elec_scenario)
>>> sos_model.add_model(energy_model)
>>> sos_model.simulate(2010)
{'model': {'cost': array([[246]])}, 'scenario': {'demand': array([[123]])}}

Submodules:

Classes:

CompositeModel Override to implement models which contain models.
Model Abstract class represents the interface used to implement the composite SosModel and leaf classes SectorModel and Scenario.

Functions:

element_after Return the element after a given element in a list, or None if the given element is last or not in the list.
element_before Return the element before a given element in a list, or None if the given element is first or not in the list.

Reference

class smif.model.CompositeModel(name)[source]

Bases: smif.model.Model

Override to implement models which contain models.

Inherited by smif.model.sos_model.SosModel and smif.model.model_set.ModelSet

free_inputs

Returns the free inputs not linked to a dependency at this layer

For this composite CompositeModel this includes the free_inputs from all contained smif.model.Model objects

Free inputs are passed up to higher layers for deferred linkages to dependencies.

Returns:
Return type:smif.metadata.MetadataSet
outputs

All model outputs defined at this layer

Returns:
Return type:smif.metadata.MetadataSet
class smif.model.Model(name)[source]

Bases: object

Abstract class represents the interface used to implement the composite SosModel and leaf classes SectorModel and Scenario.

Parameters:
  • name (str) –
  • inputs (smif.metadata.MetaDataSet) –
  • outputs (smif.metadata.MetaDataSet) –
add_dependency(source_model, source_name, sink_name, function=None)[source]

Adds a dependency to the current Model object

Parameters:
  • source_model (smif.composite.Model) – A reference to the source ~smif.composite.Model object
  • source_name (string) – The name of the model_output defined in the source_model
  • sink_name (string) – The name of a model_input defined in this object
add_parameter(parameter_dict)[source]

Add a parameter to the model

Parameters:parameter_dict (dict) – Contains the keys name, description, absolute_range, suggested_range, default_value, units
free_inputs

Returns the free inputs not linked to a dependency at this layer

Free inputs are passed up to higher layers for deferred linkages to dependencies.

Returns:
Return type:smif.metadata.MetadataSet
inputs

All model inputs defined at this layer

Returns:
Return type:smif.metadata.MetadataSet
outputs

All model outputs defined at this layer

Returns:
Return type:smif.metadata.MetadataSet
parameters

A list of parameters

Returns:
Return type:smif.parameters.ParameterList
simulate(data)[source]

Override to implement the generation of model results

Generate results for timestep using data

Parameters:data (smif.data_layer.DataHandle) – Access state, parameter values, dependency inputs.
smif.model.element_after(element, list_)[source]

Return the element after a given element in a list, or None if the given element is last or not in the list.

smif.model.element_before(element, list_)[source]

Return the element before a given element in a list, or None if the given element is first or not in the list.