Model Drivers

class cis_interface.drivers.ModelDriver.ModelDriver(name, args, is_server=False, client_of=[], with_strace=False, strace_flags=None, with_valgrind=False, valgrind_flags=None, model_index=0, **kwargs)[source]

Base class for Model drivers and for running executable based models.

Parameters:
  • name (str) – Driver name.
  • args (str or list) – Argument(s) for running the model on the command line. This should be a complete command including the necessary executable and command line arguments to that executable.
  • is_server (bool, optional) – If True, the model is assumed to be a server and an instance of cis_interface.drivers.ServerDriver is started. Defaults to False.
  • client_of (str, list, optional) – The names of ne or more servers that this model is a client of. Defaults to empty list.
  • with_strace (bool, optional) – If True, the command is run with strace (on Linux) or dtrace (on OSX). Defaults to False.
  • strace_flags (list, optional) – Flags to pass to strace (or dtrace). Defaults to [].
  • with_valgrind (bool, optional) – If True, the command is run with valgrind. Defaults to False.
  • valgrind_flags (list, optional) – Flags to pass to valgrind. Defaults to [].
  • model_index (int, optional) – Index of model in list of models being run. Defaults to 0.
  • **kwargs – Additional keyword arguments are passed to parent class.
args

list – Argument(s) for running the model on the command line.

process

cis_interface.tools.CisPopen – Process used to run the model.

is_server

bool – If True, the model is assumed to be a server and an instance of cis_interface.drivers.ServerDriver is started.

client_of

list – The names of server models that this model is a client of.

with_strace

bool – If True, the command is run with strace or dtrace.

strace_flags

list – Flags to pass to strace/dtrace.

with_valgrind

bool – If True, the command is run with valgrind.

valgrind_flags

list – Flags to pass to valgrind.

model_index

int – Index of model in list of models being run.

Raises:RuntimeError – If both with_strace and with_valgrind are True.
after_loop()[source]

Actions to perform after run_loop has finished. Mainly checking if there was an error and then handling it.

before_loop()[source]

Actions before loop.

before_start()[source]

Actions to perform before the run starts.

enqueue_output_loop()[source]

Keep passing lines to queue.

graceful_stop()[source]

Gracefully stop the driver.

kill_process()[source]

Kill the process running the model, checking return code.

model_process_complete

bool – Has the process finished or not. Returns True if the process has not started.

run_loop()[source]

Loop to check if model is still running and forward output.

wait_process(timeout=None, key=None, key_suffix=None)[source]

Wait for some amount of time for the process to finish.

Parameters:
  • timeout (float, optional) – Time (in seconds) that should be waited. Defaults to None and is infinite.
  • key (str, optional) – Key that should be used to register the timeout. Defaults to None and set based on the stack trace.
Returns:

True if the process completed. False otherwise.

Return type:

bool

class cis_interface.drivers.PythonModelDriver.PythonModelDriver(name, args, **kwargs)[source]

Class for running Python models.

Parameters:
  • name (str) – Driver name.
  • args (str or list) – Argument(s) for running the model on the command after the call to python.
  • **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
class cis_interface.drivers.MatlabModelDriver.MatlabModelDriver(name, args, **kwargs)[source]

Base class for running Matlab models.

Parameters:
  • name (str) – Driver name.
  • args (str or list) – Argument(s) for running the model in matlab. Generally, this should be the full path to a Matlab script.
  • **kwargs – Additional keyword arguments are passed to parent class’s __init__ method.
started_matlab

bool – True if the driver had to start a new matlab engine. False otherwise.

screen_session

str – Screen session that Matlab was started in.

mlengine

object – Matlab engine used to run script.

mlsession

str – Name of the Matlab session that was started.

Raises:RuntimeError – If Matlab is not installed.
after_loop()[source]

Actions to perform after run_loop has finished. Mainly checking if there was an error and then handling it.

before_start()[source]

Actions to perform before the run loop.

cleanup()[source]

Close the Matlab session and engine.

run_loop()[source]

Loop to check if model is still running and forward output.

start_matlab()[source]

Start matlab session and connect to it.

class cis_interface.drivers.GCCModelDriver.GCCModelDriver(name, args, cc=None, **kwargs)[source]

Class for running gcc compiled drivers.

Parameters:
  • name (str) – Driver name.
  • args (str or list) – Argument(s) for running the model on the command line. If the first element ends with ‘.c’, the driver attempts to compile the code with the necessary interface include directories. Additional arguments that start with ‘-I’ are included in the compile command. Others are assumed to be runtime arguments.
  • cc (str, optional) – C/C++ Compiler that should be used. Defaults to gcc for ‘.c’ files, and g++ for ‘.cpp’ or ‘.cc’ files on Linux or OSX. Defaults to cl on Windows.
  • **kwargs – Additional keyword arguments are passed to parent class.
Attributes (in additon to parent class’s):
compiled (bool): True if the compilation was succesful. False otherwise. cfile (str): Source file. cc (str): C/C++ Compiler that should be used. flags (list): List of compiler flags. efile (str): Compiled executable file.
Raises:
cleanup()[source]

Remove compile executable.

parse_arguments(args)[source]

Sort arguments based on their syntax. Arguments ending with ‘.c’ or ‘.cpp’ are considered source and the first one will be compiled to an executable. Arguments starting with ‘-L’ or ‘-l’ are treated as linker flags. Arguments starting with ‘-‘ are treated as compiler flags. Any arguments that do not fall into one of the categories will be treated as command line arguments for the compiled executable.

Parameters:args (list) – List of arguments provided.
Raises:RuntimeError – If there is not a valid source file in the argument list.
remove_products()[source]

Delete products produced during the compilation process.