carputils
Doxygen code documentation for the python framework controlling openCARP
Public Member Functions | Public Attributes | List of all members
carputils.job.job.Job Class Reference

A sequence of commands plus the tools to execute them. More...

Public Member Functions

def __init__ (self, ID)
 
def register (self, command, delayed=False)
 Register a command to be executed. More...
 
def script (self)
 Generate a bash script running the command sequence. More...
 
def submit (self, argv=None)
 Submit the command sequence to the batch system. More...
 
def bash (self, cmd, message=None, delayed=False, *args, **kwargs)
 Execute an arbitrary command in the shell. More...
 
def mpi (self, cmd, message='Executing MPI Command', *args, **kwargs)
 Execute a command with MPI. More...
 
def bench (self, cmd, simname=None, msg=None, *args, **kwargs)
 Execute a BENCH simulation. More...
 
def carp (self, cmd, simname=None, polling_subdirs=True, *args, **kwargs)
 Execute an openCARP simulation. More...
 
def python (self, cmd, *args, **kwargs)
 Execute a python script. More...
 
def meshtool (self, cmd, *args, stdout=None, stderr=None, **kwargs)
 Execute meshtool. More...
 
def cvstool (self, cmd, stdout=None, stderr=None, *args, **kwargs)
 Execute cvstool. More...
 
def mkdir (self, directory, parents=False, *args, **kwargs)
 Make a directory. More...
 
def cp (self, path_from, path_to, cpdir=False, *args, **kwargs)
 Copy a file. More...
 
def mv (self, path_from, path_to, *args, **kwargs)
 Move a file. More...
 
def rm (self, filename, rmdir=False, *args, **kwargs)
 Remove a file or a directory. More...
 
def link (self, target, link_name=None, *args, **kwargs)
 Make a symbolic link. More...
 
def gunzip (self, filename, *args, **kwargs)
 Unzip a .gz file. More...
 
def meshalyzer (self, geom, *args, **kwargs)
 Run meshalyzer. More...
 

Public Attributes

 ID
 

Detailed Description

A sequence of commands plus the tools to execute them.

A job defines a series of commands that can be executed in different ways. Each job has an ID, which defines where the output of its commands is placed, plus a series of commands that can either be run immediately as they are registered or delayed for later execution in different ways.

A job is instantiated with its ID:

>>> job = Job('2015-11-25_important_sim')

and its ID can then be accessed as an attribute:

>>> print job.ID

2015-11-25_important_sim

Commands are then registered for the job with the :meth:~Job.register method:

>>> from carputils.job.command import ShellCommand
>>> job.register(ShellCommand(['ls', '-l'], 'List directory'))
Defines several types of commands to execute.
Definition: command.py:1

however, for convenience, a number of methods such as :meth:~Job.bash are provided to avoid the need to construct your own commands manually:

>>> job.bash(['ls', '-l'])

On a normal system, commands are executed immeditately once registered (unless the 'delayed' keyword argument is set to True), however on batch systems, commands are stored. The :meth:~Job.script method may then be used to generate a bash script executing the stored commands.

The :meth:~Job.submit method may also be used to automatically generate and submit the job on HPC systems, using the carputils platform.

>>> job.submit()

Users will generally only need to use the convenience submission methods, as the job creation and batch script generation and submission is done automatically by the carputils framework.

Parameters
IDstr The identifier for this job, both the name of the output directory and the identifier on batch systems

Constructor & Destructor Documentation

◆ __init__()

def carputils.job.job.Job.__init__ (   self,
  ID 
)

Member Function Documentation

◆ bash()

def carputils.job.job.Job.bash (   self,
  cmd,
  message = None,
  delayed = False,
args,
**  kwargs 
)

Execute an arbitrary command in the shell.

Parameters
cmdlist Command to be executed
messagestr, optional Descriptive message to display when running command

◆ bench()

def carputils.job.job.Job.bench (   self,
  cmd,
  simname = None,
  msg = None,
args,
**  kwargs 
)

Execute a BENCH simulation.

   Runs a BENCH sim with mpiexec, automatically adding the number of
   processes and command configuration.
Parameters
cmdlist The command to be executed with MPI
simnamestr, optional Name to display when running command, defaults to job ID

◆ carp()

def carputils.job.job.Job.carp (   self,
  cmd,
  simname = None,
  polling_subdirs = True,
args,
**  kwargs 
)

Execute an openCARP simulation.

   Runs an openCARP sim with mpiexec, automatically adding the number of
   processes and debugger/profiler options from the current run
   configuration.
Parameters
cmdlist The command to be executed with MPI
simnamestr, optional Name to display when running command, defaults to job ID

◆ cp()

def carputils.job.job.Job.cp (   self,
  path_from,
  path_to,
  cpdir = False,
args,
**  kwargs 
)

Copy a file.

Parameters
path_fromstr Path of file to copy
path_tostr Path to copy file to

◆ cvstool()

def carputils.job.job.Job.cvstool (   self,
  cmd,
  stdout = None,
  stderr = None,
args,
**  kwargs 
)

Execute cvstool.

Parameters
cmdlist The command to be executed with cvstool

◆ gunzip()

def carputils.job.job.Job.gunzip (   self,
  filename,
args,
**  kwargs 
)

Unzip a .gz file.

Parameters
filenamestr Path of file to unzip

◆ link()

def carputils.job.job.Job.link (   self,
  target,
  link_name = None,
args,
**  kwargs 
)

Make a symbolic link.

Parameters
targetstr Target of link (first arg to 'ln -s')
link_namestr, optional Place to put link (second arg to 'ln -s')

◆ meshalyzer()

def carputils.job.job.Job.meshalyzer (   self,
  geom,
args,
**  kwargs 
)

Run meshalyzer.

Parameters
geomstr Basename of mesh to visualise
argsstr Additional data/display config files to pass as command line arguments to meshalyzer
compsurfbool, optional If True, generate a surface on the fly (default: False)
monitorint Delay in seconds before spawning visualization process after job launched (default: none) Return the spawned process.

◆ meshtool()

def carputils.job.job.Job.meshtool (   self,
  cmd,
args,
  stdout = None,
  stderr = None,
**  kwargs 
)

Execute meshtool.

Parameters
cmdlist The command to be executed with meshtool

◆ mkdir()

def carputils.job.job.Job.mkdir (   self,
  directory,
  parents = False,
args,
**  kwargs 
)

Make a directory.

Parameters
directorystr Path of directory to make
parentsbool, optional True to automatically generate parents (mkdir -p)

◆ mpi()

def carputils.job.job.Job.mpi (   self,
  cmd,
  message = 'Executing MPI Command',
args,
**  kwargs 
)

Execute a command with MPI.

   Runs a command with mpiexec, automatically adding the number of
   processes and debugger/profiler options from the current run
   configuration.
Parameters
cmdlist The command to be executed with MPI
messagestr, optional Descriptive message to display when running command

◆ mv()

def carputils.job.job.Job.mv (   self,
  path_from,
  path_to,
args,
**  kwargs 
)

Move a file.

Parameters
path_fromstr Path of file to move
path_tostr Path to move file to

◆ python()

def carputils.job.job.Job.python (   self,
  cmd,
args,
**  kwargs 
)

Execute a python script.

# FIXME: update documentation

Runs a pythonCARP sim with mpiexec, automatically adding the number of processes and debugger/profiler options from the current run configuration.

Parameters
cmdcallable The function to be executed with python

◆ register()

def carputils.job.job.Job.register (   self,
  command,
  delayed = False 
)

Register a command to be executed.

Parameters
commandcarputils.job.command.Command The command object
delayedbool, optional If True, never execute immediately - instead wait until first non- delayed command before processing the whole series

◆ rm()

def carputils.job.job.Job.rm (   self,
  filename,
  rmdir = False,
args,
**  kwargs 
)

Remove a file or a directory.

Parameters
filenamestr Path of file to remove
rmdirstr Set to True if removing directory

◆ script()

def carputils.job.job.Job.script (   self)

Generate a bash script running the command sequence.

Returns
str The content of the batch script

◆ submit()

def carputils.job.job.Job.submit (   self,
  argv = None 
)

Submit the command sequence to the batch system.

Parameters
argvlist, optional If provided, include the command line in the generated script, for
providence

Member Data Documentation

◆ ID

carputils.job.job.Job.ID

The documentation for this class was generated from the following file: