Python Code

Submodules

cis_interface.backwards module

This module allows for backward compatibility.

cis_interface.backwards.bytes2unicode(b)[source]

Convert from bytes/unicode/str to unicode.

Parameters:b (bytes, unicode, str) – Bytes to be converted into unicode.
Returns:String version of input.
Return type:unicode/str
Raises:TypeError – If supplied type cannot be converted to unicode.
cis_interface.backwards.unicode2bytes(s)[source]

Convert from bytes/unicode/str to a bytes object.

Parameters:s (str, bytes, unicode) – Object to convert to a bytes version.
Returns:Bytes version of input.
Return type:bytes
Raises:TypeError – If supplied type cannot be converted to bytes.

cis_interface.command_line module

cis_interface.command_line.cisrun()[source]
cis_interface.command_line.pprint(*args)[source]
cis_interface.command_line.signal_handler(sigCaught, frame)[source]

cis_interface.config module

This module imports the configuration for cis_interface.

Todo

Remove reference to environment variables for accessing config options.

class cis_interface.config.CisConfigParser(defaults=None, dict_type=<class 'collections.OrderedDict'>, allow_no_value=False)[source]

Bases: ConfigParser.ConfigParser

Config parser that returns None if option not provided on get.

get(section, option, default=None, **kwargs)[source]

Return None if the section/option does not exist.

Parameters:
  • section (str) – Name of section.
  • option (str) – Name of option in section.
  • default (obj, optional) – Value that should be returned if the section and/or option are not found or are an empty string. Defaults to None.
  • **kwargs – Additional keyword arguments are passed to the parent class’s get.
Returns:

String entry if the section & option exist, otherwise default.

Return type:

obj

cis_interface.config.cfg_environment(env=None, cfg=None)[source]

Set environment variables based on config options.

Parameters:
  • env (dict, optional) – Dictionary of environment variables that should be updated. Defaults to os.environ.
  • cfg (cis_interface.config.CisConfigParser, optional) – Config parser with options that should be used to update the environment. Defaults to cis_interface.config.cis_cfg.

cis_interface.runner module

This module provides tools for running models using cis_interface.

class cis_interface.runner.CisRunner(modelYmls, namespace, host=None, rank=0, cis_debug_level=None, rmq_debug_level=None, cis_debug_prefix=None)[source]

Bases: object

This class handles the orchestration of starting the model and IO drivers, monitoring their progress, and cleaning up on exit.

Parameters:
  • modelYmls (list) – List of paths to yaml files specifying the models that should be run.
  • namespace (str) – Name that should be used to uniquely identify any RMQ exchange.
  • host (str, optional) – Name of the host that the models will be launched from. Defaults to None.
  • rank (int, optional) – Rank of this set of models if run in parallel. Defaults to 0.
  • cis_debug_level (str, optional) – Level for CiS debug messages. Defaults to environment variable ‘PSI_DEBUG’.
  • rmq_debug_level (str, optional) – Level for RabbitMQ debug messages. Defaults to environment variable ‘RMQ_DEBUG’.
  • cis_debug_prefix (str, optional) – Prefix for CiS debug messages. Defaults to namespace.
namespace

str – Name that should be used to uniquely identify any RMQ exchange.

host

str – Name of the host that the models will be launched from.

rank

int – Rank of this set of models if run in parallel.

modeldrivers

list – Model drivers associated with this run.

inputdrivers

list – Input drivers associated with this run.

outputdrivers

list – Output drivers associated with this run.

..todo:: namespace, host, and rank do not seem strictly necessary.

closeChannels(force_stop=False)[source]

Stop IO drivers and join the threads.

Parameters:force_stop (bool, optional) – If True, the terminate method is used to stop the drivers. Otherwise, the stop method is used. The stop method will try to exit gracefully while terminate will exit as quickly as possible. Defaults to False.
createDriver(yml)[source]

Create a driver instance from the yaml information.

Parameters:yml (yaml) – Yaml object containing driver information.
Returns:An instance of the specified driver.
Return type:object
do_exits(model)[source]

Perform exists for IO drivers associated with a model.

Parameters:model (dict) – Dictionary of model parameters including any associated IO drivers.
loadDrivers()[source]

Load all of the necessary drivers, doing the IO drivers first and adding IO driver environmental variables back tot he models.

parseModelYaml(modelYml)[source]

Parse supplied yaml, adding yamldir and doing mustache replace.

Parameters:modelYml (str) – Path to yaml file containing model info.
Raises:IOError – If the yaml file cannot be located.
printStatus()[source]

Print the status of all drivers, starting with the IO drivers.

run()[source]

Run all of the models and wait for them to exit.

startDrivers()[source]

Start drivers, starting with the IO drivers.

terminate()[source]

Immediately stop all drivers, beginning with IO drivers.

waitModels()[source]

Wait for all model drivers to finish. When a model finishes, join the thread and perform exits for associated IO drivers.

cis_interface.runner.create_driver(driver, name, args=None, **kwargs)[source]

Dynamically create a driver based on a string and other driver properties.

Parameters:
  • driver (str) – Name of the driver that should be created.
  • name (str) – Name to give the driver.
  • args (object, optional) – Second argument for drivers which take a minimum of two arguments. If None, the driver is assumed to take a minimum of one argument. Defaults to None.
  • **kwargs – Additional keyword arguments are passed to the driver class.
Returns:

Instance of the requested driver.

Return type:

object

cis_interface.runner.get_runner(models, **kwargs)[source]

Get runner for a set of models, getting run information from the environment.

Parameters:
  • models (list) – List of yaml files containing information on the models that should be run.
  • **kwargs – Additonal keyword arguments are passed to CisRunner.
Returns:

Runner for the provided models.

Return type:

CisRunner

Raises:

Exception – If config option ‘namespace’ in ‘rmq’ section not set.

cis_interface.runner.import_driver(driver)[source]

Dynamically import a driver based on a string.

Parameters:driver (str) – Name of the driver that should be imported.
cis_interface.runner.setup_cis_logging(prog, level=None)[source]

Set the log lovel based on environment variable ‘PSI_DEBUG’. If the variable is not set, the log level is set to ‘NOTSET’.

Parameters:
  • prog (str) – Name to prepend log messages with.
  • level (str, optional) – String specifying the logging level. Defaults to None and the environment variable ‘PSI_DEBUG’ is used.
cis_interface.runner.setup_rmq_logging(level=None)[source]

Set the log level for RabbitMQ to value of environment variable ‘RMQ_DEBUG’. If the variable is not set, the log level is set to ‘INFO’.

Parameters:level (str, optional) – String specifying the logging level. Defaults to None and the environment variable ‘RMQ_DEBUG’ is used.

cis_interface.tools module

This modules offers various tools.

cis_interface.tools.ipc_queues()[source]

Get a list of active IPC queues.

Returns:List of IPC queues.
Return type:list
cis_interface.tools.ipcrm(options=[])[source]

Remove IPC constructs using the ipcrm command.

Parameters:options (list) – List of flags that should be used. Defaults to an empty list.
cis_interface.tools.ipcrm_queues(queue_keys=None)[source]

Delete existing IPC queues.

Parameters:queue_keys (list, str, optional) – A list of keys for queues that should be removed. Defaults to all existing queues.
cis_interface.tools.ipcs(options=[])[source]

Get the output from running the ipcs command.

Parameters:options (list) – List of flags that should be used. Defaults to an empty list.
Returns:Captured output.
Return type:list

Module contents

This package provides a framework for integrating models across languages such that they can be run simultaneously, passing input back and forth.