pyretis.inout package

The sub-package handles input and output for PyRETIS.

This package is intended for creating various forms of output from the PyRETIS program. It includes writers for simple text-based output and plotters for creating figures. Figures and the text results can be combined into reports, which are handled by the report module.

Package structure

Modules

__init__.py
Imports from the other modules.
checker.py (pyretis.inout.checker)
Functions to check the compatibility and consistency of various input values.
common.py (pyretis.inout.common)
Common functions and variables for the input/output. These functions are mainly intended for internal use and are not imported here.
fileio.py (pyretis.inout.fileio)
A module which defines a generic file class for PyRETIS output files.
settings.py (pyretis.inout.settings)
A module which handles the reading/writing of settings.
simulationio.py (pyretis.inout.simulationio)
A module which handles th reading/writing of the main simulations.
restart.py (pyretis.inout.restart)
A module which handles restart reading/writing.

Sub-packages

analysisio (pyretis.inout.analysisio)
Handles the input and output needed for analysis.
formats (pyretis.inout.formats)
Handles the input and output of different data formats. This includes the configurations and the internal data formats.
plotting (pyretis.inout.plotting)
Handles the plotting needed by the analysis by defining plotting tools, methods and styles.
report (pyretis.inout.report)
Generate reports with results from simulations.

Important classes defined in this package

Important methods defined in this package

generate_report (generate_report())
A function to generate reports from analysis output(s).
parse_settings_file (parse_settings_file())
Method for parsing settings from a given input file.
write_settings_file (write_settings_file())
Method for writing settings from a simulation to a given file.
write_restart_file (write_restart_file())
Method for writing restart information.

Subpackages

pyretis.inout.archive module

Module defining the base classes for the PyRETIS output.

Important classes defined here

PathStorage (PathStorage)
A class for handling storage of external trajectories to an archive. In this case, it is simply a folder based structure.
PathStorageTar (PathStorageTar)
A class for handling storage of external trajectories to an archive format (tar in this case).
class pyretis.inout.archive.PathStorage[source]

Bases: OutputBase

A class for handling storage of external trajectories.

target

Determines the target for this output class. Here it will be a file archive (i.e. a directory based collection of files).

Type:string
archive_acc

Basename for the archive with accepted trajectories.

Type:string
archive_rej

Basename for the archive with rejected trajectories.

Type:string
archive_traj

Basename for a sub-folder containing the actual files for a trajectory.

Type:string
formatters

This dict contains the formatters for writing path data, with default filenames used for them.

Type:dict
out_dir_fmt

A format to use for creating directories within the archive. This one is applied to the step number for the output.

Type:string
__init__()[source]

Set up the storage.

Note that we here do not pass any formatters to the parent class. This is because this class is less flexible and only intended to do one thing - write path data for external trajectories.

__str__()[source]

Return basic info.

archive_acc = 'traj-acc'
archive_name_from_status(status)[source]

Return the name of the archive to use.

archive_rej = 'traj-rej'
archive_traj = 'traj'
formatter_info()[source]

Return info about the formatters.

formatters = {'energy': {'file': 'energy.txt', 'fmt': <pyretis.inout.formats.energy.EnergyPathFormatter object>}, 'order': {'file': 'order.txt', 'fmt': <pyretis.inout.formats.order.OrderPathFormatter object>}, 'traj': {'file': 'traj.txt', 'fmt': <pyretis.inout.formats.path.PathExtFormatter object>}}
out_dir_fmt = '{}'
output(step, data)[source]

Format the path data and store the path.

Parameters:
  • step (integer) – The current simulation step.
  • data (list) – Here, data[0] is assumed to be an object like Path, data[1] a string containing the status of this path and data[2] the path ensemble for which the path was generated.
Returns:

files (list of tuples of strings) – The files added to the archive.

output_path_files(step, data, target_dir)[source]

Write the output files for energy, path and order parameter.

Parameters:
  • step (integer) – The current simulation step.
  • data (list) – Here, data[0] is assumed to be an object like Path and data[1]` a string containing the status of this path.
  • target_dir (string) – The path to where we archive the files.
Returns:

files (list of tuple of strings) – These are the files created. The tuple contains the files as a full path and a relative path (to the given target directory). The form is files[i] = (full_path[i], relative_path[i]). The relative path is useful for organizing internally in archives.

target = 'file-archive'
write(towrite, end='\n')[source]

We do not need the write method for this object.

class pyretis.inout.archive.PathStorageTar[source]

Bases: PathStorage

A class for handling storage of external trajectories.

Here, we collect the external trajectories into tar archives.

__str__()[source]

Return basic info.

static _add_to_archive(archive_file, files)[source]

Add some files to an archive file.

Parameters:
  • archive_file (string) – The path to the archive file to create.
  • files (list of tuples) – The path(s) to the file(s) to add with names to create internally in the archive. That is, the form is: file[i] = (source[i], target[i]) where target[i] will be used as the archive name for file source[i].
Returns:

add (boolean) – True if we added files to the archive.

archive_acc = 'traj-acc.tar'
archive_rej = 'traj-rej.tar'
output(step, data)[source]

Format the path data and store the path.

Parameters:
  • step (integer) – The current simulation step.
  • data (list) – Here, data[0] is assumed to be an object like Path, data[1] a string containing the status of this path and data[2] the path ensemble for which the path was generated.
Returns:

files (list of tuples of strings) – The files added to the archive.

pyretis.inout.archive.add_to_tar_file(tar_file, files, file_mode='a')[source]

Open a tar file and add some files.

Parameters:
  • tar_file (string) – The path to the tar file to create.
  • files (list of tuples) – The path(s) to the file(s) to add with names to create internaly in the tar file. That is: file[i] = (source[i], target[i]) where target[i] will be used as the archname for source[i].
  • file_mode (string) – Determines how we try to open the tar file.
Returns:

out (boolean) – True if we managed to write to the file.

pyretis.inout.archive.generate_traj_names(path, target_dir)[source]

Generate new file names for moving copying paths.

Parameters:
  • path (object like PathBase) – This is the path object we are going to store.
  • target_dir (string) – The location where we are moving the path to.
Returns:

files (list of tuples of strings) – The files to add and the file names to use internally for storing. That is: file[i] = (source[i], target[i]) where target[i] is the internal storage name.

pyretis.inout.common module

This file contains common functions for the input/output.

It contains some slave functions that are used in the in/output function of PyRETIS.

Important classes defined here

OutputBase (OutputBase)
A base class for handling the output.

Important methods defined here

check_python_version (check_python_version())
A method that will give warnings when we use older and possibly unsupported Python versions.
create_backup (create_backup())
A function to handle the creation of backups of old files.
make_dirs (make_dirs())
Create directories (for path simulation).
create_empty_ensembles (create_ensembles())
A method to prepare the ensembles inputs in settings
simplify_ensemble_name (simplify_ensemble_name())
Simplify the name of ensembles for creating directories.
generate_file_name (generate_file_name())
Generate file name for an output task, from settings.
class pyretis.inout.common.OutputBase(formatter)[source]

Bases: object

A generic class for handling output.

formatter

The object responsible for formatting output.

Type:object like py:class:.OutputFormatter
target

Determines where the target for the output, for instance “screen” or “file”.

Type:string
first_write

Determines if we have written something yet, or if this is the first write.

Type:boolean
__init__(formatter)[source]

Create the object and attach a formatter.

__str__()[source]

Return basic info.

formatter_info()[source]

Return a string with info about the formatter.

output(step, data)[source]

Use the formatter to write data to the file.

Parameters:
  • step (int) – The current step number.
  • data (list) – The data we are going to output.
target = None
abstract write(towrite, end='\n')[source]

Write a string to the output defined by this class.

Parameters:
  • towrite (string) – The string to write.
  • end (string, optional) – A “terminator” for the given string.
Returns:

status (boolean) – True if we managed to write, False otherwise.

pyretis.inout.common.add_dirname(filename, dirname)[source]

Add a directory as a prefix to a filename, i.e. dirname/filename.

Parameters:
  • filename (string) – The filename.
  • dirname (string) – The directory we want to prefix. It can be None, in which case we ignore it.
Returns:

out (string) – The path to the resulting file.

pyretis.inout.common.check_python_version()[source]

Give a warning about old python version(s).

pyretis.inout.common.create_backup(outputfile)[source]

Check if a file exist and create backup if requested.

This function will check if the given file name exists and if it does, it will move that file to a new file name such that the given one can be used without overwriting.

Parameters:outputfile (string) – This is the name of the file we wish to create.
Returns:out (string) – This string is None if no backup is made, otherwise, it will just say what file was moved (and to where).

Note

No warning is issued here. This is just in case the msg returned here will be part of some more elaborate message.

pyretis.inout.common.create_empty_ensembles(settings)[source]

Create missing ensembles in the settings.

Checks the input and allocate it to the right ensemble. In theory inouts shall include all these info, but it is not practical.

Parameters:settings (dict) – The current input settings.
Returns:None, but this method might add data to the input settings.
pyretis.inout.common.generate_file_name(basename, directory, settings)[source]

Generate file name for an output task, from settings.

Parameters:
  • basename (string) – The base file name to use.
  • directory (string) – A directory to output to. Can be None to output to the current working directory.
  • settings (dict) – The input settings
Returns:

filename (string) – The file name to use.

pyretis.inout.common.make_dirs(dirname)[source]

Create directories for path simulations.

This function will create a folder using a specified path. If the path already exists and if it’s a directory, we will do nothing. If the path exists and is a file we will raise an OSError exception here.

Parameters:dirname (string) – This is the directory to create.
Returns:out (string) – A string with some info on what this function did. Intended for output.
pyretis.inout.common.name_file(name, extension, path=None)[source]

Return a file name by joining a name and an file extension.

This function is used to create file names. It will use os.extsep to create the file names and os.path.join to add a path name if the path is given. The returned file name will be of form (example for posix): path/name.extension.

Parameters:
  • name (string) – This is the name, without extension, for the file.
  • extension (string) – The extension to use for the file name.
  • path (string, optional) – An optional path to add to the file name.
Returns:

out (string) – The resulting file name.

pyretis.inout.common.simplify_ensemble_name(ensemble, fmt='{:03d}')[source]

Simplify path names for file/directory names.

Here, we are basically translating ensemble names to more friendly names for directories and files that is:

  • [0^-] returns 000,
  • [0^+] returns 001,
  • [1^+] returns 002, etc.
Parameters:
  • ensemble (string) – This is the string to simplify.
  • fmt (string. optional) – This is a format to use for the directories.

pyretis.inout.fileio module

Module defining the base classes for the PyRETIS output.

Important classes defined here

FileIO (FileIO)
A generic class for handling input & output with files.

Important methods defined here

read_some_lines (read_some_lines())
Method to read lines from PyRETIS data files.
class pyretis.inout.fileio.FileIO(filename, file_mode, formatter, backup=True)[source]

Bases: OutputBase

A generic class for handling IO with files.

This class defines how PyRETIS stores and reads data. Formatting is handled by an object like OutputFormatter

filename

Name (e.g. path) to the file to read or write.

Type:string
file_mode

Specifies the mode in which the file is opened.

Type:string
backup

Determines the behavior if we want to write to a file that is already existing.

Type:boolean
fileh

The file handle we are interacting with.

Type:object like io.IOBase
last_flush

The previous time for flushing to the file.

Type:object like datetime.datetime
__del__()[source]

Close the file in case the object is deleted.

__enter__()[source]

Context manager for opening the file.

__exit__(*args)[source]

Context manager for closing the file.

__init__(filename, file_mode, formatter, backup=True)[source]

Set up the file object.

Parameters:
  • filename (string) – The path to the file to open or read.
  • file_mode (string) – Specifies the mode for opening the file.
  • formatter (object like py:class:.OutputFormatter) – The object responsible for formatting output.
  • backup (boolean, optional) – Defines how we handle cases where we write to a file which is already existing.
__iter__()[source]

Make it possible to iterate over lines in the file.

__next__()[source]

Let the file object handle the iteration.

__str__()[source]

Return basic info.

close()[source]

Close the file.

flush()[source]

Flush file buffers to file.

load()[source]

Read blocks or lines from the file.

open()[source]

Open a file for reading or writing.

open_file_read()[source]

Open a file for reading.

open_file_write()[source]

Open a file for writing.

In this method, we also handle the possible backup settings.

output(step, data)[source]

Open file before first write.

target = 'file'
write(towrite, end='\n')[source]

Write a string to the file.

Parameters:
  • towrite (string) – The string to output to the file.
  • end (string, optional) – Appended to towrite when writing, can be used to print a new line after the input towrite.
Returns:

status (boolean) – True if we managed to write, False otherwise.

pyretis.inout.fileio._read_line_data(ncol, stripline, line_parser)[source]

Read data for read_some_lines.().

Parameters:
  • ncol (integer) – The expected number of columns to read. If this is less than 1 it is not yet set. Note that we skip data which appear inconsistent. A warning will be issued about this.
  • stripline (string) – The line to read. Note that we assume that leading and trailing spaces have been removed.
  • line_parser (callable) – A method we use to parse a single line.
pyretis.inout.fileio.read_some_lines(filename, line_parser, block_label='#')[source]

Open a file and try to read as many lines as possible.

This method will read a file using the given line_parser. If the given line_parser fails at a line in the file, read_some_lines will stop here. Further, this method will read data in blocks and yield a block when a new block is found. A special string (block_label) is assumed to identify the start of blocks.

Parameters:
  • filename (string) – This is the name/path of the file to open and read.
  • line_parser (function, optional) – This is a function which knows how to translate a given line to a desired internal format. If not given, a simple float will be used.
  • block_label (string, optional) – This string is used to identify blocks.
Yields:

data (list) – The data read from the file, arranged in dicts.

pyretis.inout.restart module

This module defines how we write and read restart files.

Important methods defined here

read_restart_file (read_restart_file())
A method for reading restart information from a file.
write_restart_file (write_restart_file())
A method for writing the restart file.
write_ensemble_restart (write_ensemble_restart())
A method for writing restart files for path ensembles.
pyretis.inout.restart.read_restart_file(filename)[source]

Read restart info for a simulation.

Parameters:filename (string) – The file we are going to read from.
pyretis.inout.restart.write_ensemble_restart(ensemble, settings_ens)[source]

Write a restart file for a path ensemble.

Parameters:
  • ensemble (dict) – it contains:
    • path_ensemble : object like PathEnsemble The path ensemble we are writing restart info for.
    • ` system` : object like System System is used here since we need access to the temperature and to the particle list.
    • order_function : object like OrderParameter The class used for calculating the order parameter(s).
    • engine : object like EngineBase The engine to use for propagating a path.
  • settings_ens (dict) – A dictionary with the ensemble settings.
pyretis.inout.restart.write_restart_file(filename, simulation)[source]

Write restart info for a simulation.

Parameters:
  • filename (string) – The file we are going to write to.
  • simulation (object like Simulation) – A simulation object we will get information from.

pyretis.inout.screen module

Module defining the base classes for the PyRETIS output.

Important classes defined here

ScreenOutput (FileIO)
A generic class for handling output to the screen.

Important methods defined here

print_to_screen (print_to_screen())
A method used for printing messages to screen.
class pyretis.inout.screen.ScreenOutput(formatter)[source]

Bases: OutputBase

A class for handling output to the screen.

target = 'screen'
write(towrite, end=None)[source]

Write a string to the file.

Parameters:
  • towrite (string) – The string to output to the file.
  • end (string, optional) – Override how the print statements ends.
Returns:

status (boolean) – True if we managed to write, False otherwise.

pyretis.inout.screen.print_to_screen(txt=None, level=None)[source]

Print output to standard out.

This method is included to ensure that output from PyRETIS to the screen is written out in a uniform way across the library and application(s).

Parameters:
  • txt (string, optional) – The text to write to the screen.
  • level (string, optional) – The level can be used to color the output.

pyretis.inout.settings module

This module handles parsing of input settings.

This module defines the file format for PyRETIS input files.

Important methods defined here

parse_settings_file (parse_settings_file())
Method for parsing settings from a given input file.
write_settings_file (write_settings_file())
Method for writing settings from a simulation to a given file.
pyretis.inout.settings._clean_settings(settings)[source]

Clean up input settings.

Here, we attempt to remove unwanted stuff from the input settings.

Parameters:settings (dict) – The current input settings.
Returns:settingsc (dict) – The cleaned input settings.
pyretis.inout.settings._merge_section_text(raw_section)[source]

Merge text for settings that are split across lines.

This method supports keyword settings that are split across several lines. Here we merge these lines by assuming that keywords separate different settings.

Parameters:raw_section (string) – The text we will merge.
pyretis.inout.settings._parse_all_raw_sections(raw_sections)[source]

Parse all raw sections.

This method is helpful for running tests etc.

Parameters:raw_sections (dict) – The dictionary with the raw data in sections.
Returns:settings (dict) – The parsed settings, with one key for each section parsed.
pyretis.inout.settings._parse_raw_section(raw_section, section)[source]

Parse the raw data from a section.

Parameters:
  • raw_section (list of strings) – The text data for a given section which will be parsed.
  • section (string) – A text identifying the section we are parsing for. This is used to get a list over valid keywords for the section.
Returns:

out (dict) – A dict with keys corresponding to the settings.

pyretis.inout.settings._parse_section_default(raw_section)[source]

Parse a raw section.

This is the default parser for sections.

Parameters:raw_section (list of strings) – The text data for a given section which will be parsed.
Returns:setting (dict) – A dict with keys corresponding to the settings.
pyretis.inout.settings._parse_section_heading(raw_section)[source]

Parse the heading section.

Parameters:raw_section (list of strings) – The text data for a given section which will be parsed.
Returns:setting (dict) – A dict with keys corresponding to the settings.
pyretis.inout.settings._parse_sections(inputtxt)[source]

Find sections in the input file with raw data.

This method will find sections in the input file and collect the corresponding raw data.

Parameters:inputtxt (list of strings or iterable file object) – The raw data to parse.
Returns:raw_data (dict) – A dictionary with keys corresponding to the sections found in the input file. raw_data[key] contains the raw data for the section corresponding to key.
pyretis.inout.settings.add_default_settings(settings)[source]

Add default settings.

Parameters:settings (dict) – The current input settings.
Returns:None, but this method might add data to the input settings.
pyretis.inout.settings.add_specific_default_settings(settings)[source]

Add specific default settings for each simulation task.

Parameters:settings (dict) – The current input settings.
Returns:None, but this method might add data to the input settings.
pyretis.inout.settings.fill_up_tis_and_retis_settings(settings)[source]

Make the life of sloppy users easier.

The full input set-up will be here completed.

Parameters:settings (dict) – The current input settings.
Returns:None, but this method might add data to the input settings.
pyretis.inout.settings.parse_settings_file(filename, add_default=True)[source]

Parse settings from a file name.

Here, we read the file line-by-line and check if the current line contains a keyword, if so, we parse that keyword.

Parameters:
  • filename (string) – The file to parse.
  • add_default (boolean) – If True, we will add default settings as well for keywords not found in the input.
Returns:

settings (dict) – A dictionary with settings for PyRETIS.

pyretis.inout.settings.write_settings_file(settings, outfile, backup=True)[source]

Write simulation settings to an output file.

This will write a dictionary to an output file in the PyRETIS input file format.

Parameters:
  • settings (dict) – The dictionary to write.
  • outfile (string) – The file to create.
  • backup (boolean, optional) – If True, we will backup existing files with the same file name as the provided file name.

Note

This will currently fail if objects have made it into the supplied settings.

pyretis.inout.simulationio module

Definition of a class for handling output related to simulations.

Important classes defined here

Task (Task)
Base class for tasks. This is used by SimulationTask and OutputTask.
OutputTask (OutputTask)
A class representing a simulation output task.

Important methods defined here

get_task_type (get_task_type())
Do additional handling for a path task.
get_file_mode (get_file_mode())
Determine if we should append or backup existing files.
task_from_settings (task_from_settings())
Create output task from simulation settings.

Important variables defined here

OUTPUT_TASKS (OUTPUT_TASKS)
A dictionary defining the different output tasks known to PyRETIS.
pyretis.inout.simulationio.OUTPUT_TASKS = {'cross': {'filename': 'cross.txt', 'formatter': <class 'pyretis.inout.formats.cross.CrossFormatter'>, 'result': ('cross',), 'target': 'file', 'when': 'cross-file'}, 'energy': {'filename': 'energy.txt', 'formatter': <class 'pyretis.inout.formats.energy.EnergyFormatter'>, 'result': ('thermo',), 'target': 'file', 'when': 'energy-file'}, 'order': {'filename': 'order.txt', 'formatter': <class 'pyretis.inout.formats.order.OrderFormatter'>, 'result': ('order',), 'target': 'file', 'when': 'order-file'}, 'path-energy': {'filename': 'energy.txt', 'formatter': <class 'pyretis.inout.formats.energy.EnergyPathFormatter'>, 'result': ('path', 'status'), 'target': 'file', 'when': 'energy-file'}, 'path-order': {'filename': 'order.txt', 'formatter': <class 'pyretis.inout.formats.order.OrderPathFormatter'>, 'result': ('path', 'status'), 'target': 'file', 'when': 'order-file'}, 'path-traj-ext': {'filename': 'traj.txt', 'result': ('path', 'status', 'pathensemble'), 'target': 'file-archive', 'when': 'trajectory-file', 'writer': <class 'pyretis.inout.archive.PathStorage'>}, 'path-traj-int': {'filename': 'traj.txt', 'formatter': <class 'pyretis.inout.formats.path.PathIntFormatter'>, 'result': ('path', 'status'), 'target': 'file', 'when': 'trajectory-file'}, 'pathensemble': {'filename': 'pathensemble.txt', 'formatter': <class 'pyretis.inout.formats.pathensemble.PathEnsembleFormatter'>, 'result': ('pathensemble',), 'target': 'file', 'when': 'pathensemble-file'}, 'pathensemble-retis-screen': {'formatter': <class 'pyretis.inout.formats.txt_table.RETISResultFormatter'>, 'result': ('pathensemble',), 'target': 'screen', 'when': 'screen'}, 'pathensemble-screen': {'formatter': <class 'pyretis.inout.formats.txt_table.PathTableFormatter'>, 'result': ('pathensemble',), 'target': 'screen', 'when': 'screen'}, 'thermo-file': {'filename': 'thermo.txt', 'formatter': <class 'pyretis.inout.formats.txt_table.ThermoTableFormatter'>, 'result': ('thermo',), 'target': 'file', 'when': 'energy-file'}, 'thermo-screen': {'formatter': <class 'pyretis.inout.formats.txt_table.ThermoTableFormatter'>, 'result': ('thermo',), 'target': 'screen', 'when': 'screen'}, 'traj-txt': {'filename': 'traj.txt', 'formatter': <class 'pyretis.inout.formats.snapshot.SnapshotFormatter'>, 'result': ('system',), 'target': 'file', 'when': 'trajectory-file'}, 'traj-xyz': {'filename': 'traj.xyz', 'formatter': <class 'pyretis.inout.formats.snapshot.SnapshotFormatter'>, 'result': ('system',), 'target': 'file', 'when': 'trajectory-file'}}

Define a set of known output tasks.

The output tasks are defined as dictionaries with the following keys:

  • targetstring

    “file” or “screen”, defines where the task writes to.

  • filenamestring

    A default file name for an output file if writing to a file.

  • resulttuple of strings

    Determines what item from the result dictionary we are outputting.

  • whenstring

    Determines what input setting from the “output” section is used to define the output frequency. Default values are defined by the output section, see: py:mod:pyretis.inout.settings.settings.

  • formatterobject like OutputFormatter

    Selects the formatter for the output.

  • writerobject like OutputBase

    Selects the writer for the output.

  • settingstuple of strings, optional

    A dict with additional settings which can be passed to the formatter if needed. These settings can, for instance, be defined in the output section of the input file.

The writer can be defined explicitly, or via the formatter. If a formatter is given, then the generic FileIO will be used. If no formatter is given, then the writer is assumed to be given.

class pyretis.inout.simulationio.OutputTask(name, result, writer, when)[source]

Bases: Task

A base class for simulation output.

This class will handle an output task for a simulation. The output task consists of one object which is responsible for formatting the output data and one object which is responsible for writing that data, for instance to the screen or to a file.

target

This string identifies what kind of output we are dealing with. This will typically be either “screen” or “file”.

Type:string
name

This string identifies the task, it can, for instance, be used to reference the dictionary used to create the writer.

Type:string
result

This string defines the result we are going to output.

Type:tuple of strings
writer

This object will handle the actual outputting of the result.

Type:object like OutputBase
when

Determines if the task should be executed.

Type:dict
__init__(name, result, writer, when)[source]

Initialise the generic output task.

Parameters:
  • name (string) – This string identifies the task, it can, for instance, be used to reference the dictionary used to create the writer.
  • result (list of strings) – These strings define the results we are going to output.
  • writer (object like IOBase) – This object will handle formatting of the actual result and output to screen or to a file.
  • when (dict) – Determines when the output should be written. Example: {‘every’: 10} will be executed at every 10th step.
__str__()[source]

Print information about the output task.

output(simulation_result)[source]

Output given results from simulation steps.

This will output the task using the result found in the simulation_result which should be the dictionary returned from a simulation object (e.g. object like Simulation) after a step.

Parameters:simulation_result (dict) – This is the result from a simulation step.
Returns:out (boolean) – True if the writer wrote something, False otherwise.
task_dict()[source]

Return a dict with info about the task.

class pyretis.inout.simulationio.Task(when)[source]

Bases: object

Base representation of a “task”.

A task is just something that is supposed to be executed at a certain point. This class will just set up functionality that is common for output tasks and for simulation tasks.

when

Determines when the task should be executed.

Type:dict
__init__(when)[source]

Initialise the task.

Parameters:when (dict, optional) – Determines if the task should be executed.
execute_now(step)[source]

Determine if a task should be executed.

Parameters:step (dict of ints) – Keys are ‘step’ (current cycle number), ‘start’ cycle number at start ‘stepno’ the number of cycles we have performed so far.
Returns:out (boolean) – True of the task should be executed.
task_dict()[source]

Return basic info about the task.

property when

Return the “when” property.

pyretis.inout.simulationio.get_file_mode(settings)[source]

Determine if we should append or backup existing files.

This method translates the backup settings into a file mode string. We assume here that the file is opened for writing.

Parameters:settings (dict) – The simulation settings.
Returns:file_mode (string) – A string representing the file mode to use.
pyretis.inout.simulationio.get_task_type(task, engine)[source]

Do additional handling for a path task.

The path task is special since we do very different things for external paths. The set-up required to do this is handled here.

Parameters:
  • task (dict) – Settings related to the specific task.
  • engine (object like EngineBase) – This object is used to determine if we need to do something special for external engines. If no engine is given, we do not do anything special.
Returns:

out (string) – The task type we are going to be creating for.

pyretis.inout.simulationio.task_from_settings(task, settings, directory, engine, progress=False)[source]

Create output task from simulation settings.

Parameters:
  • task (dict) – Settings for creating a task. This dict contains the type and name of the task to create. It can also contain overrides to the default settings in OUTPUT_TASKS.
  • settings (dict) – Settings for the simulation.
  • directory (string) – The directory to write output files to.
  • engine (object like EngineBase) – This object is used to determine if we need to do something special for external engines. If no engine is given, we do not do anything special.
  • progress (boolean, optional) – For some simulations, the user may select to display a progress bar. We will then just disable the other screen output.
Returns:

out (object like OutputTask) – An output task we can use in the simulation.

pyretis.inout.checker module

This module checks that the inputs are meaningful.

Main methods defined here

check_ensemble (check_ensemble())
Function to check the ensemble settings.
check_interfaces (check_interfaces())
Function to check engine set-up.
check_for_bullshitt (check_for_bullshitt())
Function to compare nested dicts and lists.
check_engine (check_engine())
Function to check engine set-up.
pyretis.inout.checker.check_engine(settings)[source]

Check the engine settings.

Checks that the input engine settings are correct, and automatically determine the ‘internal’ or ‘external’ engine setting.

Parameters:settings (dict) – The current input settings.
pyretis.inout.checker.check_ensemble(settings)[source]

Check that the ensemble input parameters are complete.

Parameters:settings (dict) – The settings needed to set up the simulation.
pyretis.inout.checker.check_for_bullshitt(settings)[source]

Do what is stated.

Just for the input settings.

Parameters:settings (dict) – The current input settings.
pyretis.inout.checker.check_interfaces(settings)[source]

Check that the interfaces are properly defined.

Parameters:settings (dict) – The current input settings.