generic

Module: missions.operations.generic

Use a generic external python script in a process

Specification file Parameters

type

Specifies which operation is used. For this operation you have to use generic.

(obligatory, generic)

code

The code to be executed by this operation. The code MUST contain the definition of the functions “process” and “consolidate”. A typical pattern is to have the code in a separate file and use “exec open(“file_containing_code.py”).read()” for execution.

(obligatory)

configuration_template

Template which determines the parameters that are passed to the “process” function via the config parameter. The template is instantiated based on the given parameter_ranges (see below). For each instantiation, one process is created.

(mandatory if parameter_setting is not used)

parameter_ranges

Parameter range which determines the specific instantiations of the configuration template. The template is instantiated once for each element of the cartesian product of the given ranges (if no constraints are defined)

(mandatory if parameter_setting is not used)

parameter_setting

If you do not use the parameter_ranges, this is a list of dictionaries giving the parameter combinations, you want to test the code on.

(mandatory if parameter_ranges is not used)

constraints

List of strings, where the parameters values are replaced and which is afterwards evaluated to check if is True. If it is not, the parameter is rejected.

(optional, default: [])

Exemplary Call

type: generic

# The code to be executed by this operation
# The code MUST contain the definition of the functions "process" and "consolidate"
# NOTE: We could just directly put the code into this configuration file (instead of loading it from
#       an other file). However, if the functions are not trivial, it's typically more convenient
#       to have the code in a separate file
# NOTE: The | is actually required. Don't remove it!
code: |
    exec open('~/pyspace/pySPACE/run/scripts/mandelbrot_set.py').read()

# The template which determines the parameters that are passed to the "process" function
# via the *config* parameter. The template is instantiated based on the given
# parameter_ranges (see below). For each instantiation, one process is created.
# NOTE: The | is actually required. Don't remove it!
configuration_template: |
    xind : __XIND__
    yind : __YIND__
    xstep : 0.4
    ystep : 0.4
    resolution: 1000

# Parameter range which determines the specific instantiations of the configuration template.
# The template is instantiated once for each element of the cartesian product of the given
# ranges (if no constraints are defined)
parameter_ranges:
    __XIND__ : [0, 1, 2, 3, 4, 5, 6]
    __YIND__ : [0, 1, 2, 3, 4, 5, 6]

Inheritance diagram for pySPACE.missions.operations.generic:

Inheritance diagram of pySPACE.missions.operations.generic

Class Summary

GenericOperation(processes, operation_spec, ...) Generic operation performing computation based on external module
GenericProcess(process_id, ...) Generic process performing computation specified in external module.

Classes

GenericOperation

class pySPACE.missions.operations.generic.GenericOperation(processes, operation_spec, result_directory, code_string, number_processes)[source]

Bases: pySPACE.missions.operations.base.Operation

Generic operation performing computation based on external module

A GenericOperation consists of a set of GenericProcess instances. Each of these processes consists of calling a function “process” defined in an external module for a specific parametrization.

The results of this operation are collected using the consolidate method that produces a consistent representation of the result. Especially it collects not only the data, but also saves information of the in and out coming files and the used specification files.

Objects of this class are typically create using the create factory method based on a operation_spec dictionary. This dictionary in turn is typically create based on a configuration file in YAML syntax. Which parameters need to be specified in this configuration file are listed below. See example_generic_operation.yaml for an example.

Class Components Summary

consolidate() Perform cleanup / consolidation at the end of operation.
create(operation_spec, result_directory[, ...]) Factory method for creating a GenericOperation.
__init__(processes, operation_spec, result_directory, code_string, number_processes)[source]
classmethod create(operation_spec, result_directory, debug=False, input_paths=[])[source]

Factory method for creating a GenericOperation.

Factory method for creating a GenericOperation based on the information given in the operation specification operation_spec.

consolidate()[source]

Perform cleanup / consolidation at the end of operation.

GenericProcess

class pySPACE.missions.operations.generic.GenericProcess(process_id, configuration_template, parameter_setting, result_directory, code_string)[source]

Bases: pySPACE.missions.operations.base.Process

Generic process performing computation specified in external module.

This process calls the function “process” defined

Parameters
process_id:

Globally unique id of this process. Might be used e.g. for creating a file into which the results of this process are stored.

(obligatory)

configuration_template:
 

Template (string) which determines the parameters that are passed to the “process” function contained in the code_string via the config parameter. The template is instantiated based on the given parameter_setting (see below). It must adhere the YAML standard and correspond to a dictionary mapping parameter name to value.

(obligatory)

parameter_setting:
 

Dictionary containing the mapping from parameter name (must be contained in configuration_template string) to parameter value. The specific parameter values define this particular computation.

(obligatory)

result_directory:
 

Directory into which the results of the computation of this function are stored.

(obligatory)

code_string:

A string containing a definition of a python function with the name “process”. Note: We pass the string-definition of the function instead of the function itself since GenericProcess objects are often serializes using pickle. This wouldn’t work when the object would contain a reference to a function object.

(obligatory)

Class Components Summary

__call__() Executes this process on the respective modality.
__init__(process_id, configuration_template, parameter_setting, result_directory, code_string)[source]
__call__()[source]

Executes this process on the respective modality.