smif.controller.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

Summary

Data:

ModelRun Collects timesteps, scenarios , narratives and a SosModel together
ModelRunner The ModelRunner orchestrates the simulation of a SoSModel over decision iterations and timesteps as provided by a DecisionManager.

Reference

class smif.controller.modelrun.ModelRun[source]

Bases: object

Collects timesteps, scenarios , narratives and a SosModel together

name

The unique name of the model run

Type:str
timestamp

An ISO8601 compatible timestamp of model run creation time

Type:datetime.datetime
description

A friendly description of the model run

Type:str
sos_model

The contained SosModel

Type:smif.model.sos_model.SosModel
scenarios

For each scenario set, a mapping to a valid scenario within that set

Type:dict
narratives

A list of smif.parameters.Narrative objects

Type:list
strategies
Type:dict
status
Type:str
logger
Type:logging.Logger
results
Type:dict
as_dict()[source]

Serialises smif.controller.modelrun.ModelRun

Returns a dictionary definition of a ModelRun which is equivalent to that required by from_dict to construct a new model run

Returns:
Return type:dict
classmethod from_dict(config)[source]

Create a smif.controller.modelrun.ModelRun from a dictionary

validate()[source]

Validate that this ModelRun has been set up with sufficient data to run

model_horizon

Returns the list of timesteps

Returns:A list of timesteps, distinct and sorted in ascending order
Return type:list
run(store, job_scheduler, warm_start_timestep=None, dry_run=False)[source]

Builds all the objects and passes them to the ModelRunner

The idea is that this will add ModelRuns to a queue for asychronous processing

class smif.controller.modelrun.ModelRunner(warm_start=False)[source]

Bases: object

The ModelRunner orchestrates the simulation of a SoSModel over decision iterations and timesteps as provided by a DecisionManager.

solve_model(model_run, job_scheduler, store, dry_run=False)[source]

Solve a ModelRun

This method steps through the model horizon, building a job graph and submitting this to the scheduler at each decision loop.

Parameters:
build_job_graph(model_run, bundle)[source]

Build a job graph

Build and return the job graph for an entire bundle, including before_model_run jobs when the models were not yet initialised.

Constraints: - Bundle must have keys: ‘decision_iterations’ and ‘timesteps’ - Running a bundle runs each (decision iteration, timestep) pair specified by the

combinations of decision iterations and timesteps
  • (decision iteration, timestep) pairs must be unique over an entire model run
  • In a single bundle, timesteps must be a consecutive subset of the model horizon timesteps

The first timestep in each decision iteration of a bundle is either: - the first timestep in the model horizon and initialised from the model run starting

point with scenario data and initial-timestep interventions only
  • or another timestep, picking up from where some previous (timestep, decision iteration) left off, which is explicitly included in the bundle.

If a bundle’s timesteps start from a timestep after the first one in the model horizon, the bundle must provide ‘decision_links’, and bundle must start from the very next timestep available in the model horizon.

Jobs need to be able to identify a point to pick up from, namely the (timestep, decision iteration) which identifies the immediately preceding simulation state.

E.g. request running first two timesteps:

{
    'decision_iterations': [0, 1],
    'timesteps': [0, 1]
}

Run first two timesteps again, with an updated decision:

{
    'decision_iterations': [1, 2],
    'timesteps': [0, 1]
}

Results meet decision requirements, so run next two timesteps, linking this bundle’s decision iterations to previous decision iterations:

{
    'decision_iterations': [3, 4],
    'timesteps': [2, 3],
    'decision_links': {3: 1, 4: 2}
}
Parameters:model_run (smif.controller.modelrun.ModelRun bundle: dict) –
Returns:different operations and timesteps
Return type:networkx.Graph A populated job graph with edges showing dependencies between
static filter_job_graph(modelrun_name, job_graph, complete_jobs)[source]