# Process¶

## Overview¶

A Process is the simplest form of Composition, made up of a lineal sequence of Mechanisms linked by Projections. Processes can be executed on their own, but most commonly they are used to compose a System, which is the most powerful form of Composition in PsyNeuLink. Processes are nevertheless useful, as they define a simpler unit of processing than a System (e.g., for debugging, or for use in multiple Systems), and are used as the unit of learning within a System. The general features of Processes are summarized below, followed by a more detailed description in the sections that follow.

Mechanisms and Projections are composed into a Process by assigning them to the Process’ pathway attribute. Executing a Process executes all of its Mechanisms in the order in which they are listed in its pathway. Projections can be specified among any Mechanisms in a Process, including to themselves, however they must compose a lineal sequence. A Process cannot involve any “branching” (beyond what may be produced by recurrent loops within the Process); that must be done by using a Process to compose each branch, and then composing the Processes into a System. Mechanisms in a Process can project to and receive Projections from Mechanisms in other Processes, however these will not have any effect when the Process is executed; these will only have an effect if all of the Processes involved are members of the same System and the System is executed.

Projections between Mechanisms can be trained by specifying them for learning. Learning can also be specified for the entire Process, in which case all of the Projections among Mechanisms in the Process are trained (see Learning below).

## Creating a Process¶

A Process is created by instantiating the Process class. The Mechanisms to be included are specified in a list in its pathway argument, in the order in which they should be executed by the Process. The Mechanism entries can be separated by Projections used to connect them. If no arguments are provided to the pathway argument, a Process with an empty pathway is created.

## Structure¶

### Pathway¶

A Process is defined by its pathway attribute, which is a list of Mechanisms and Projections, that are executed in the order in which they are specified in the list. Each Mechanism in the pathway must project at least to the next one in the pathway, though it can project to others, and receive recurrent (feedback) Projections from them. However, a pathway cannot include branching patterns beyond any produced by recurrent loops (see Examples below); that is, a Mechanism cannot project to another Mechanism that falls outside the lineal sequence of the pathway To compose more complex, branched, structures, a Process should be created for each “branch”, and these used to compose a System.

The Mechanisms specified in the pathway for a Process must be ProcessingMechanisms, and the projections between Mechanisms in a Process must be MappingProjections. These transmit the output of a Mechanism (the Projection’s sender) to the input of another Mechanism (the Projection’s receiver). Specification of a pathway requires, at the least, a list of Mechanisms. Each of these can be specified directly, or using a tuple that also contains a set of runtime parameters (see below). A Projection between a pair of Mechanisms can be specified by interposing it in the list between the pair. If no Projection is specified between two adjacent Mechanisms in the pathway, and there is no otherwise specified Projection between them, a default MappingProjection is automatically created when the Process is created that projects from the first to the second member of the pair. Specifying the Components of a pathway is described in detail below.

### Mechanisms¶

The Mechanisms of a Process must be listed explicitly in the pathway argument of the Process class, in the order they are to be executed when the Process (or any System to which it belongs) is executed. The first Mechanism in a Process is designated as its ORIGIN Mechanism, and is assigned to its origin_mechanism attribute; it receives as its input any input provided to the Process’ execute or run methods. The last Mechanism listed in the pathway is designated as the TERMINAL Mechanism, and is assigned to its terminal_mechanism attribute; its output_values is assigned as the output of the Process.

Any Mechanism that sends a Projection that closes a recurrent loop within the pathway is designated as INITIALIZE_CYCLE; whenever that Mechanism is initialized, it is assigned the value specified for it in the initial_values argument of the Process’ execute or run methods. Mechanisms that receive a Projection from one designated INITIALIZE_CYCLE are themselves designated as CYCLE. All other Mechanisms in the pathway are designated as INTERNAL.

Note

The origin_mechanism and terminal_mechanism of a Process are not necessarily the ORIGIN and/or TERMINAL Mechanisms of the System(s)to which the Process belongs (see example). The designations of a Mechanism’s status in the Process(es) to which it belongs are listed in its processes attribute.

Mechanisms can be specified in the pathway argument of the Process class in one of two ways:

• MechanismTuple – the first item must be a specification for the Mechanism using any of the ways used to specify a Mechanism; the second must be a set of runtime parameters. Runtime parameters are used for that Mechanism when the Process (or a System to which it belongs) is executed; otherwise they do not remain associated with the Mechanism.

The same Mechanism can appear more than once in a pathway, as one means of generating a recurrent processing loop (another is to specify this in the Projections – see below).

### Projections¶

MappingProjections between Mechanisms in the pathway of a Process can be specified in any of the following ways:

• Inline specification – a MappingProjection specification can be interposed between any two Mechanisms in the pathway list. This creates a Projection from the preceding Mechanism in the list to the one that follows it. It can be specified using any of the ways used to specify a Projection or the matrix parameter of one.
• Tuple learning specification – this can be used in the same way as an inline specification; the first item must a MappingProjection specification that takes the same form as an inline specification, and the second must be a learning specification.
• Stand-alone MappingProjection – when a Projection is created on its own, it can be assigned a sender and/or a receiver Mechanism. If both are in the Process, then that Projection will be used when creating the Process. Stand-alone specification of a MappingProjection between two Mechanisms in a Process takes precedence over any other form of specification; that is, the stand-alone Projection will be used in place of any that is specified between the Mechanisms in a pathway. Stand-alone specification is required to implement MappingProjections between Mechanisms that are not adjacent to one another in the pathway.

### Process input and output¶

The input of a Process is a list or 2d np.array provided as the input argument in its execute method, or the inputs argument of its run method. When a Process is created, a set of ProcessInputStates (listed in its process_input_states attribute) and MappingProjections are automatically created to transmit the Process’ input to its origin_mechanism, as follows:

• otherwise, if the input has more than one item and the origin_mechanism has more than one InputState, but the numbers are not equal, an error message is generated indicating that there is an ambiguous mapping from the Process’ input value to origin_mechanism’s InputStates.

The output of a Process is assigned as the output_values attribute of its TERMINAL Mechanism.

### Learning¶

Learning operates over a learning sequence: a contiguous sequence of ProcessingMechanisms in a Process pathway, and the MappingProjections between them, that have been specified for learning. Learning modifies the matrix parameter of the MappingProjections in the sequence, so that the input to the first ProcessingMechanism in the sequence generates an output from the last ProcessingMechanism that matches as closely as possible the target specified for the sequence (see Learning below for a more detailed description).

Learning can be specified for individual (or subsets of) MappingProjections, or for the entire Process. It is specified for the entire process by assigning a specification for a LearningProjection or LearningSignal specification, or the keyword ENABLED, to the learning argument of the Process’ constructor. Specifying learning for a Process implements it for all MappingProjections in the Process (except those that project from the process_input_states to the origin_mechanism), which are treated as a single learning sequence. Mechanisms that receive MappingProjections for which learning has been specified must be compatible with learning (that is, their function must be compatible with the function of the Learning Mechanism for the MappingProjections they receive (see Learning Function).

The following Components are created for each learning sequence specified for a Process (see figure below):

• a MappingProjection that projects from the last ProcessingMechanism in the sequence to the SAMPLE InputState of the TARGET Mechanism;
• a MappingProjection that projects from the ProcessInputState for the target item to the TARGET InputState of the TARGET Mechanism;

Note

The Components created when learning is specified for individual MappingProjections of a Process (or subsets of them) take effect only if the Process is executed on its own (i.e., using its execute or run methods. For learning to in a Process when it is executed as part of a System, learning must be specified for the entire Process, as described above.

Figure: Learning Components in a Process

## Execution¶

A Process can be executed as part of a System or on its own. On its own, it is executed by calling either its execute or run method. execute executes the Process once (that is, it executes a single TRIAL); run allows a series of TRIALs to be executed.

. _Process_Processing

### Processing¶

When a Process is executed, its input is conveyed to the origin_mechanism (the first Mechanism in the pathway). By default, the input is presented only once. If the origin_mechanism is executed again in the same PASS of execution (e.g., if it appears again in the pathway, or receives recurrent projections), the input is not presented again. However, the input can be “clamped” on using the clamp_input argument of execute or run. After the origin_mechanism is executed, each subsequent Mechanism in the pathway is executed in sequence. If a Mechanism is specified in the pathway using a MechanismTuple, then the runtime parameters are applied and the Mechanism is executed using them (see Mechanism for parameter specification). Finally the output of the terminal_mechanism (the last one in the pathway) is assigned as the output of the Process.

Note

Processes do not use a Scheduler; each Mechanism is executed once, in the order listed in its pathway attribute. To more precisely control the order of, and/or any dependencies in, the sequence of executions, the Process should be used to construct a System, together with Conditions to implement a custom schedule.

The input to a Process is specified in the input argument of either its execute or run method. In both cases, the input for a single TRIAL must be a number, list or ndarray of values that is compatible with the variable of the origin_mechanism. If the execute method is used, input for only a single TRIAL is provided, and only a single TRIAL is executed. The run method can be used for a sequence of TRIALs, by providing it with a list or ndarray of inputs, one for each TRIAL. In both cases, two other types of input can be provided in corresponding arguments of the execute and run methods: a list or ndarray of initial_values, and a list or ndarray of target values. The initial_values are assigned as input to Mechanisms that close recurrent loops (designated as INITIALIZE_CYCLE) at the start of a TRIAL (if initialize is set to True), and/or whenever the Process initialize method is called; target values are assigned as the TARGET input of the target_nodes in each TRIAL of execution, if learning has been specified (see the next setion for how Learning is executed; also, see Run documentation for additional details of formatting Run_Input and Run_Target specifications of the run method).

### Learning¶

If learning has been specified for the Process or any of the projections in its pathway, then the learning Components described above are executed after all of the ProcessingMechanisms in the pathway have executed. The learning Components calculate changes that will be made to matrix of the MappingProjections involved. This requires that a set of target values be provided (along with the inputs) in the targets argument of the Process’ execute or run method, one for each learning sequence. These are used to calculate a learning_signal for each MappingProjection in a learning sequence. This is conveyed by a LearningProjection as a weight_change_matrix to the MappingProjection’s MATRIX ParameterState, that is used to modify the MappingProjection’s matrix parameter when it executes.

Note

The changes to a Projection induced by learning are not applied until the Mechanisms that receive those projections are next executed (see Lazy Evaluation for an explanation of “lazy” updating).

The learning_signals for a learning sequence are calculated, for each sequence, so as to reduce the difference between the value received by the TARGET Mechanism in its SAMPLE InputState (see above) and the target value for the sequence specified in the corresponding item of the target argument of the Process’ execute or run method.

Examples

Specification of Mechanisms in a pathway: The first Mechanism in the example below is specified as a reference to an instance, the second as a default instance of a Mechanism type, and the third in MechanismTuple format, specifying a reference to a Mechanism that should receive my_params at runtime:

mechanism_1 = TransferMechanism()
mechanism_2 = DDM()
some_params = {PARAMETER_STATE_PARAMS:{THRESHOLD:2,NOISE:0.1}}
my_process = Process(pathway=[mechanism_1, TransferMechanism, (mechanism_2, my_params)])


Default Projection specification: The pathway for this Process uses default Projection specifications; as a result, a MappingProjection is automatically instantiated between each of the Mechanisms listed:

my_process = Process(pathway=[mechanism_1, mechanism_2, mechanism_3])


Inline Projection specification using an existing Projection: In this pathway, projection_A is specified as the Projection between the first and second Mechanisms; a default Projection is created between mechanism_2 and mechanism_3:

projection_A = MappingProjection()
my_process = Process(pathway=[mechanism_1, projection_A, mechanism_2, mechanism_3])


Inline Projection specification using a keyword: In this pathway, a RANDOM_CONNECTIVITY_MATRIX is used to specify the Projection between the first and second Mechanisms:

my_process = Process(pathway=[mechanism_1, RANDOM_CONNECTIVITY_MATRIX, mechanism_2, mechanism_3])


Stand-alone Projection specification: In this pathway, projection_A is explicitly specified as a Projection between mechanism_1 and mechanism_2, and so is used as the Projection between them in my_process; a default Projection is created between mechanism_2 and mechanism_3:

projection_A = MappingProjection(sender=mechanism_1, receiver=mechanism_2)
my_process = Process(pathway=[mechanism_1, mechanism_2, mechanism_3])


Process that implements learning: This pathway implements a series of Mechanisms with Projections between them, all of which will be learned using BackPropagation (the default learning algorithm). Note that it uses the Logistic function, which is compatible with BackPropagation:

mechanism_1 = TransferMechanism(function=Logistic)
mechanism_2 = TransferMechanism(function=Logistic)
mechanism_3 = TransferMechanism(function=Logistic)
my_process = Process(pathway=[mechanism_1, mechanism_2, mechanism_3],
learning=ENABLED,
target=[0])


Process with individual Projections that implement learning: This pathway implements learning for two MappingProjections (between mechanism_1 and mechanism_2, and mechanism_3 and mechanism_4). Since they are not contiguous, two learning sequences are created, with TARGET Mechanisms assigned to mechanism_2 and mechanism_4 (that will be listed in my_process.target_nodes):

mechanism_1 = TransferMechanism(function=Logistic)
mechanism_2 = TransferMechanism(function=Logistic)
mechanism_3 = TransferMechanism(function=Logistic)
mechanism_4 = TransferMechanism(function=Logistic)
my_process = Process(pathway=[mechanism_1,
MappingProjection(matrix=(RANDOM_CONNECTIVITY_MATRIX, LEARNING),
mechanism_2,
mechanism_3,
MappingProjection(matrix=(RANDOM_CONNECTIVITY_MATRIX, LEARNING)),
mechanism_4])


## Footnotes¶

lineal: this term is used rather than “linear” to refer to the flow of processing – i.e., the graph structure of the Process – rather than the (potentially non-linear) processing characteristics of its individual Components.

## Class Reference¶

psyneulink.core.components.process.proc(*args, **kwargs)

Factory method

args can be Mechanisms with our without Projections, or a list of them, that conform to the format for the pathway argument of a Process.

kwargs can be any arguments of the Process constructor.

class psyneulink.core.components.process.Process(default_variable=None, size=None, pathway=None, initial_values=None, clamp_input=None, default_projection_matrix='AutoAssignMatrix', learning=None, learning_rate=None, target=None, params=None, name=None, prefs: <function is_pref_set at 0x112721488> = None, context=None)

Process(process_spec=None, default_variable=None, pathway=None, initial_values={}, clamp_input:=None, default_projection_matrix=DEFAULT_PROJECTION_MATRIX, learning=None, learning_rate=None target=None, params=None, name=None, prefs=None

Base class for Process.

componentType

“Process”

pathway

List[ProcessingMechanism, MappingProjection, ProcessingMechanism…] – the ProcessingMechanisms and MappingProjections between them that are executed in the order listed when the Process executes.

process_input_states

List[ProcessInputState] – represent the input to the Process when it is executed. Each ProcessInputState represents an item of the input to a corresponding InputState of the Process’ origin_mechanism (see Process input and output for details).

input

List[value] or ndarray – input to the Process for each TRIAL of execution; it is assigned the value of the input argument in a call to the Process’ execute or run method. Each of its items is assigned as the value of the corresponding ProcessInputState in process_input_states, and each must match the format of the corresponding item of the variable for the Process’ origin_mechanism (see Process input and output for details).

Note

The input attribute of a Process preserves its value throughout the execution of the Process. It’s value is assigned to the variable attribute of the origin_mechanism at the start of execution. After that, by default, that Mechanism’s variable attribute is zeroed. This is so that if the origin_mechanism is executed again in the same TRIAL of execution (e.g., if it is part of a recurrent loop) it does not continue to receive the initial input to the Process. However, this behavior can be modified with the Process’ clamp_input attribute.

clamp_input

Optional[keyword] – determines whether the Process’ input continues to be applied to the origin_mechanism if it is executed again within the same TRIAL. It can take the following values:

initial_values

Dict[ProcessingMechanism, param value] – values used to initialize ProcessingMechanisms designated as INITIALIZE_CYCLE whenever the Process’ initialize method is called. The key for each entry is a ProcessingMechanism, and the value is a number, list or np.array that is assigned to that Mechanism’s value attribute whenever it is initialized. ProcessingMechanisms that are designated as INITIALIZE_CYCLE but not included in the initial_values specification are initialized with the value of their variable attribute (i.e., the default input for that Mechanism).

value

2d np.array – same as the value of the primary OutputState of terminal_mechanism.

output_state

State – the primary OutputState of terminal_mechanism.

output

list – same as the output_values attribute of terminal_mechanism.

mechanism_names

List[str] – the names of the Mechanisms listed in the Mechanisms attribute.

mechanisms

List[Mechanism]all of the Mechanisms in the Process, including those in the pathway and those created for learning.

origin_mechanism

Mechanism – the ORIGIN Mechanism of the Process (see Process Mechanisms for a description).

terminal_mechanism

Mechanism – the TERMINAL Mechanism of the Process (see Process Mechanisms for a description).

learning_mechanisms

MechanismList – all of the LearningMechanism in the Process, listed in learning_mechanisms.data.

target_mechanisms

MechanismList – the TARGET Mechanisms for the Process, listed in target_nodes.data; each is a ComparatorMechanism associated with the last ProcessingMechanism of a learning sequence in the Process;

systems

List[System] – the Systems to which the Process belongs.

learning

Optional[LearningProjection] – indicates whether the Process is configured for learning. If it has a value other than None, then learning has been configured for one or more MappingProjections in the Process; if it is None, none of MappingProjections in the Process has been configured for learning.

Note

The learning attribute of a Process may have a value other than None even if no assignment is made to the learning argument of the process command; this occurs if one or more MappingProjections in the Process are specified individually for learning.

learning_rate

float : default None – determines the learning_rate used for MappingProjections specified for learning in the Process that do not have their learning_rate otherwise specified. If is None, and the Process is executed as part of a System, and the System has a learning_rate specified, then that is the value used. Otherwise, the default value of the learning_rate parameter for the function of the LearningMechanism associated with each MappingProjection is used. If a learning_rate is specified for the LearningSignal or LearningProjection associated with a MappingProjection, that is applied in addition to any specified for the Process or the relevant LearningMechanism.

results

List[OutputState.value] – the return values from a sequence of executions of the Process; its value is None if the Process has not been executed.

name

str – the name of the Process; if it is not specified in the name argument of the constructor, a default is assigned by ProcessRegistry (see Naming for conventions used for default and duplicate names).

prefs

PreferenceSet or specification dict – the PreferenceSet for the Process; if it is not specified in the prefs argument of the constructor, a default is assigned using classPreferences defined in __init__.py (see PreferenceSet for details).

initialize(execution_context=None)

Assign the values specified for each Mechanism in the process’ initial_values attribute. This usually occurs at the beginning of one or a series of executions invoked by a call to the Process execute or run methods.

execute(input=None, target=None, execution_id=None, base_execution_id=None, runtime_params=None, termination_processing=None, termination_learning=None, context=None)

Execute the Mechanisms specified in the process pathway attribute.

Parameters: input (List[value] or ndarray: default zeroes) – specifies the value(s) of the Process’ input for the execution; it is provided as the input to the origin_mechanism and must be compatible (in number and type of items) with its variable attribute (see Process input and output for details). target (List[value] or ndarray: default None) – specifies the target value assigned to each of the target_nodes for the execution. Each item is assigned to the TARGET InputState of the corresponding ComparatorMechanism in target_nodes; the number of items must equal the number of items in target_nodes, and each item of target be compatible with the variable attribute of the TARGET InputState for the corresponding ComparatorMechanism in target_nodes. params (Dict[param keyword: param value] : default None) – a parameter dictionary that can include any of the parameters used as arguments to instantiate the object. Use parameter’s name as the keyword for its entry. Values specified for parameters in the dictionary override any assigned to those parameters in arguments of the constructor. output of Process (ndarray) – the value of the primary OutputState of the terminal_mechanism of the Process.
run(inputs, num_trials=None, initialize=False, initial_values=None, targets=None, learning=None, call_before_trial=None, call_after_trial=None, call_before_time_step=None, call_after_time_step=None)

Run a sequence of executions

Parameters: inputs (List[input] or ndarray(input) : default default_variable for a single execution) – specifies the input used to execute the Process for each TRIAL in a sequence of executions (see Run for formatting requirements and options). Each item of the outermost level (if a nested list) or axis 0 (if an ndarray) is assigned as the input to the Process for the corresponding TRIAL, and therefore must be compatible (in number and type of items) with the variable of the origin_mechanism for the Process. If the number of items is less than num_trials, the inputs are cycled until the number of TRIALSs specified in num_trials has been executed. num_trials (int : default None) – number of TRIALs to execute. If the number exceeds the number of inputs specified, they are cycled until the number of TRIALSs specified in num_trials has been executed. initialize (bool default False) – specifies whether to call the Process initialize method before executing each TRIAL; if it is False, then initialize is called only once, before the first TRIAL executed. initial_values (ProcessingMechanism, List[input] or np.ndarray(input)] : default None) – specifies the values used to initialize ProcessingMechanisms designated as INITIALIZE_CYCLE whenever the Process’ initialize method is called. The key for each entry must be a ProcessingMechanism designated INITIALIZE_CYCLE, and the value must be a number, list or np.array that is compatible with the format of the ProcessingMechanism’s value attribute. ProcessingMechanisms designated as INITIALIZE_CYCLE but not specified in initial_values are initialized with the value of their variable attribute (the default input for that Mechanism). targets (List[input] or np.ndarray(input) : default None) – specifies the target value assigned to each of the target_nodes in each TRIAL of execution. Each item of the outermost level (if a nested list) or axis 0 (if an ndarray) corresponds to a single TRIAL; the number of items must equal the number of items in the inputs argument. Each item is assigned to the TARGET InputState of the corresponding ComparatorMechanism in target_nodes; the number of items must equal the number of items in target_nodes, and each item of target be compatible with the variable attribute of the TARGET InputState for the corresponding ComparatorMechanism in target_nodes. learning (bool : default None) – enables or disables learning during execution. If it is not specified, its current value (from possible prior assignment) is left intact. If True, learning is forced on; if False, learning is forced off. call_before_trial (Function : default None) – called before each TRIAL in the sequence is executed. call_after_trial (Function : default None) – called after each TRIAL in the sequence is executed. call_before_time_step (Function : default None) – called before each TIME_STEP of each trial is executed. call_after_time_step (Function : default None) – called after each TIME_STEP of each trial is executed. .results – list of the values of the primary OutputState for the terminal_mechanism of the Process returned for each execution. List[OutputState.value]
show(options=None)

Print list of all Mechanisms in the process, followed by its ORIGIN and TERMINAL Mechanisms.

class psyneulink.core.components.process.ProcessInputState(owner=None, variable=None, name=None, prefs=None)

Represents inputs and targets specified in a call to the Process’ execute and run methods.

A ProcessInputState is created for each InputState of the origin_mechanism, and for the TARGET InputState of each ComparatorMechanism listed in target_nodes. A MappingProjection is created that projects to each of these InputStates from the corresponding ProcessingInputState. When the Process’ execute or run method is called, each item of its inputs and targets arguments is assigned as the value of a ProcessInputState, which is then conveyed to the corresponding InputState of the origin_mechanism and terminal_mechanisms. See Process input and output for additional details.