The SKIRT project
advanced radiative transfer for astrophysics
pts.simulation.simulation.Simulation Class Reference

An instance of the Simulation class represents all input and output files related to a single performed SKIRT simulation. More...

Public Member Functions

 __init__ (self, prefix="", *, skiFilePath=None, inDirPath=None, outDirPath="", process=None)
 The constructor accepts the following arguments:
 __getattr__ (self, attrname)
 This function allows invoking any SkiFile function directly on a simulation object.
 inDirPath (self)
 This function returns the absolute path to the input directory of the simulation, or None if it is unknown.
 inFilePath (self, name)
 This function returns the absolute path for a simulation input file, given the file's name, or None if the input directory path is unknown.
 instruments (self)
 This function returns a list of Instrument instances for each of the instruments in the simulation, in their order of appearance in the ski file.
 isRunning (self)
 This function returns True if the simulation instance has been created from an asynchronous Skirt.execute() invocation (with "wait=False") and the asynchronous process is still executing.
 logFilePath (self)
 This function returns the absolute path for the simulation log file.
 logFilePaths (self)
 This function returns a list of absolute filepaths for all log files produced by the simulation, including the master log file and any log files produced by parallel (MPI) processes.
 outDirPath (self)
 This function returns the absolute path to the output directory of the simulation.
 outFilePath (self, partialname)
 This function returns the absolute path for a simulation output file, given the file's partial name (the partial name does not include the prefix and the subsequent underscore).
 parameters (self)
 This function returns a SkiFile object representing the parameter file for this simulation.
 prefix (self)
 This function returns the prefix for the simulation, which is used for all output file names.
 probes (self, probeType=None, formType=None)
 This function returns a list of Probe instances for each of the probes in the simulation, in their order of appearance in the ski file.
 skiFilePath (self)
 This function returns the absolute file path of the input ski file for which the simulation was performed (not the parameters.xml file generated by SKIRT), or None if it is unknown.
 status (self)
 This function returns the status of the simulation, based on its process completion state (if available) and the contents of its log file, as one of the following strings:

Protected Attributes

 _inDirPath
 _outDirPath
 _parameters
int _prefix
 _process
str _running
 _skiFilePath

Detailed Description

An instance of the Simulation class represents all input and output files related to a single performed SKIRT simulation.

To create an instance of the class, one specifies the name of the ski file (used as prefix for all output filenames) plus directory paths for the input and output files. The methods of the class allow retrieving all kinds of information about the simulation results.

The code in this class uses ad-hoc knowledge about SKIRT's data formats and naming schemes; for example:

  • SKIRT's hard-coded output file names are used to locate various output files.
  • the structure of the SKIRT parameter file (ski file) is used to determine things like the names of the instruments and probes in the simulation.
  • the format of the log file is used to extract success or error messages.

Constructor & Destructor Documentation

◆ __init__()

pts.simulation.simulation.Simulation.__init__ ( self,
prefix = "",
* ,
skiFilePath = None,
inDirPath = None,
outDirPath = "",
process = None )

The constructor accepts the following arguments:

  • prefix: the name of the ski file for which the simulation was performed (without the directory path and without the .ski filename extension) and which has been used as a prefix for all output file names. If the prefix argument is empty or missing, the skiFilePath argument must be provided so that the prefix can be automatically derived from the (stem of the name of) the specified ski file.
  • skiFilePath: the path of the input ski file for which the simulation was performed (not the parameters.xml file generated by SKIRT). This argument is optional, but if it is omitted, the prefix argument must be present and non-empty.
  • inDirPath: the input path of the simulation. If there were no input files for the simulation, or if access to the input files is not needed, this argument may be omitted.
  • outDirPath: the output path of the simulation. If this argument is missing, the output path is taken to be the current working directory.
  • process: optional subprocess.Popen object that can be queried for completion of a simulation. If the argument is not provided, the completion status is derived from the log file. This argument is provided by the Skirt object when it creates a Simulation instance for a simulation that is being performed in asynchronous mode.

All paths described above are interpreted as described for the pts.utils.absPath() function.

Member Function Documentation

◆ __getattr__()

pts.simulation.simulation.Simulation.__getattr__ ( self,
attrname )

This function allows invoking any SkiFile function directly on a simulation object.

For example, self.instrumentNames() is automatically translated to self.parameters().instrumentNames().

◆ inDirPath()

pts.simulation.simulation.Simulation.inDirPath ( self)

This function returns the absolute path to the input directory of the simulation, or None if it is unknown.

◆ inFilePath()

pts.simulation.simulation.Simulation.inFilePath ( self,
name )

This function returns the absolute path for a simulation input file, given the file's name, or None if the input directory path is unknown.

◆ instruments()

pts.simulation.simulation.Simulation.instruments ( self)

This function returns a list of Instrument instances for each of the instruments in the simulation, in their order of appearance in the ski file.

◆ isRunning()

pts.simulation.simulation.Simulation.isRunning ( self)

This function returns True if the simulation instance has been created from an asynchronous Skirt.execute() invocation (with "wait=False") and the asynchronous process is still executing.

Otherwise, the function returns False. Note that this is not always exactly the same as the result of "status() == 'Running'".

◆ logFilePath()

pts.simulation.simulation.Simulation.logFilePath ( self)

This function returns the absolute path for the simulation log file.

◆ logFilePaths()

pts.simulation.simulation.Simulation.logFilePaths ( self)

This function returns a list of absolute filepaths for all log files produced by the simulation, including the master log file and any log files produced by parallel (MPI) processes.

The list includes only paths for log files that actually exist, and the paths are listed in order of process rank.

◆ outDirPath()

pts.simulation.simulation.Simulation.outDirPath ( self)

This function returns the absolute path to the output directory of the simulation.

◆ outFilePath()

pts.simulation.simulation.Simulation.outFilePath ( self,
partialname )

This function returns the absolute path for a simulation output file, given the file's partial name (the partial name does not include the prefix and the subsequent underscore).

◆ parameters()

pts.simulation.simulation.Simulation.parameters ( self)

This function returns a SkiFile object representing the parameter file for this simulation.

◆ prefix()

pts.simulation.simulation.Simulation.prefix ( self)

This function returns the prefix for the simulation, which is used for all output file names.

◆ probes()

pts.simulation.simulation.Simulation.probes ( self,
probeType = None,
formType = None )

This function returns a list of Probe instances for each of the probes in the simulation, in their order of appearance in the ski file.

The list can be limited to probes of the specified type(s) and/or with the specified assocated form type(s).

◆ skiFilePath()

pts.simulation.simulation.Simulation.skiFilePath ( self)

This function returns the absolute file path of the input ski file for which the simulation was performed (not the parameters.xml file generated by SKIRT), or None if it is unknown.

◆ status()

pts.simulation.simulation.Simulation.status ( self)

This function returns the status of the simulation, based on its process completion state (if available) and the contents of its log file, as one of the following strings:

  • 'NotStarted': the simulation has not (yet) been started.
  • 'Running': the simulation is still running, or at least it seems to be so (for example, the simulation crashed without logging an error message and the Simulation was constructed without a process object).
  • 'Crashed': the simulation ended with a fatal error.
  • 'Finished': the simulation completed properly.

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