smif.controller.scheduler module

Schedulers are used to run models.

The defaults provided allow model runs to be scheduled as subprocesses, or individual models to be called in series.

Future implementations may interface with common schedulers to queue up models to run in parallel and/or distributed.

Summary

Classes:

JobScheduler Run JobGraphs produced by a ModelRun
ModelRunScheduler The scheduler can run instances of smif as a subprocess and can provide information whether the modelrun is running, is done or has failed.

Reference

class smif.controller.scheduler.ModelRunScheduler[source]

Bases: object

The scheduler can run instances of smif as a subprocess and can provide information whether the modelrun is running, is done or has failed.

add(model_run_name, args)[source]

Add a model_run to the Modelrun scheduler.

Parameters:
  • model_run_name (str) – Name of the modelrun
  • args (dict) – Arguments for the command-line interface
  • Exception
  • ---------
  • Exception – When the modelrun was already started

Notes

There is no queuing mechanism implemented, each add will directly start a subprocess. This means that it is possible to run multiple modelruns concurrently. This may cause conflicts, it depends on the implementation whether a certain sector model / wrapper touches the filesystem or other shared resources.

kill(model_run_name)[source]

Kill a Modelrun that is already running

Parameters:model_run_name (str) – Name of the modelrun
get_status(model_run_name)[source]

Get the status from the Modelrun scheduler.

Parameters:model_run_name (str) – Name of the modelrun
Returns:
  • dict (A message containing the status, command-line)
  • output and error that can be directly sent back over
  • the http api.

Notes

Possible status:

unstarted:
Model run was not started
queing:
Model run is waiting to be executed
running:
Model run is running
stopped:
Model run was stopped (killed) by user
done:
Model run was completed succesfully
failed:
Model run completed running with an exit code
class smif.controller.scheduler.JobScheduler[source]

Bases: object

Run JobGraphs produced by a ModelRun

add(job_graph)[source]

Add a JobGraph to the JobScheduler and run directly

Parameters:job_graph (networkx.graph) –
kill(job_graph_id)[source]

Kill a job_graph that is already running - not implemented

Parameters:job_graph_id (int) –
get_status(job_graph_id)[source]

Get job graph status

Parameters:job_graph_id (int) –
Returns:dict
Return type:A message containing the status

Notes

Possible statuses:

unstarted:
Job graph has not yet started
running:
Job graph is running
done:
Job graph was completed succesfully
failed:
Job graph completed running with an exit code