ctwrap Wrapper

The wrapper module defines a Simulation object that wraps simulation modules.

Usage

Simulation modules specify tasks to be run in a batch job; a simulation module needs to define methods defaults (default parameters) and run (running of batch calculations).

ctwrap defines several pre-configured simulation modules in the ctwrap.modules submodule. As an example, the ctwrap.modules.minimal module is loaded using the module path as:

import ctwrap as cw

sim = cw.Simulation.from_module('ctwrap.modules.minimal')
sim = cw.Simulation.from_module(cw.modules.minimal) # equivalent

Alternatively, a Simulation module defined in my_test.py is loaded as:

sim = cw.Simulation.from_module('my_test.py')

Methods defined within a simulation module can be accessed by pass-through methods Simulation.defaults() and Simulation.new():

defaults = sim.defaults() # load defaults
sim.run(defaults) # run simulation module with default arguments

Class Definition

class ctwrap.wrapper.Simulation(module)[source]

The Simulation class wraps simulation modules into a callable object.

Note

Simulation objects should be instantiated using the from_module() method.

data

Dictionary containing simulation results.

Parameters

module (str) – Handle name or handle to module running the simulation

classmethod from_module(module)[source]

Alternative constructor for Simulation object.

The from_module() method is intended as the main route for the creation of Simulation objects. For example:

# creates a simulation object with the simulation module `minimal`
sim = ctwrap.Simulation.from_module(ctwrap.modules.minimal)
Parameters

module (module) – handle name or handle to module running the simulation

Return type

Simulation

restart(restart, config=None)[source]

Run the simulation module’s restart method.

Return type

bool

run(config=None, restart=None, **kwargs)[source]

Run the simulation module’s run method.

This run() method is used to call the simulation module’s run method. If a simulation object sim was created with simulation module minimal, then calls this run() method calls run method in simulation module minimal. A simple usage example is:

sim.run()
Parameters
  • config (Optional[Dict[str, Any]]) – Configuration used for simulation

  • restart (Optional[Any]) – Data used for restart

  • **kwargs – Optional parameters passed to the simulation

Return type

bool

defaults()[source]

Pass-through returning simulation module defaults as a dictionary

Return type

Dict[str, Any]