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
Simulationobjects should be instantiated using thefrom_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
-
run(config=None, restart=None, **kwargs)[source]¶ Run the simulation module’s
runmethod.This
run()method is used to call the simulation module’s run method. If a simulation objectsimwas created with simulation moduleminimal, then calls thisrun()method callsrunmethod in simulation moduleminimal. A simple usage example is:sim.run()
- Parameters
config (
Optional[Dict[str,Any]]) – Configuration used for simulationrestart (
Optional[Any]) – Data used for restart**kwargs – Optional parameters passed to the simulation
- Return type
bool
-