• Github
Table of Contents
0.13.0.0
  • Welcome to PsyNeuLink
  • Basics and Primer
  • Quick Reference
  • Core
  • Library
  • Contributors Guide
  • Docs >
  • Condition
Shortcuts

Condition¶

Note

This documentation is mirrored from the graph-scheduler package and often refers to nodes, edges , and graphs. In PsyNeuLink terms, nodes are Mechanisms or Compositions, edges are Projections, and graphs are Compositions. The one exception is during learning, in which Projections may be assigned for execution as nodes to ensure that MappingProjections are updated in the proper order.

Note

This documentation was modified from the original due to environment-specific TimeScale renamings. If there is any confusion, please see the original documentation at https://www.github.com/kmantel/graph-scheduler

Overview¶

Conditions are used to specify when nodes are allowed to execute. Conditions can be used to specify a variety of required conditions for execution, including the state of the node itself (e.g., how many times it has already executed, or the value of one of its attributes), the state of the Scheduler (e.g., how many TIME_STEP s have occurred in the current TRIAL), or the state of other nodes in a graph (e.g., whether or how many times they have executed). This package provides a number of pre-specified Conditions that can be parametrized (e.g., how many times a node should be executed). Custom conditions can also be created, by assigning a function to a Condition that can reference any node or its attributes, thus providing considerable flexibility for scheduling.

Creating Conditions¶

Pre-specified Conditions¶

Pre-specified Conditions can be instantiated and added to a Scheduler at any time, and take effect immediately for the execution of that Scheduler. Most pre-specified Conditions have one or more arguments that must be specified to achieve the desired behavior. Many Conditions are also associated with an owner attribute (a node to which the Condition belongs). Schedulers maintain the data used to test for satisfaction of Condition, independent in different execution contexts. The Scheduler is generally responsible for ensuring that Conditions have access to the necessary data. When pre-specified Conditions are instantiated within a call to the add_condition method of a Scheduler or ConditionSet, the Condition’s owner is determined through context and assigned automatically, as in the following example:

my_scheduler.add_condition(A, EveryNPasses(1))
my_scheduler.add_condition(B, EveryNCalls(A, 2))
my_scheduler.add_condition(C, EveryNCalls(B, 2))

Here, EveryNCalls(A, 2) for example, is assigned the owner B.

Custom Conditions¶

Custom Conditions can be created by calling the constructor for the base class (Condition()) or one of the generic classes, and assigning a function to the func argument and any arguments it requires to the args and/or kwargs arguments (for formal or keyword arguments, respectively). The function is called with args and kwargs by the Scheduler on each PASS through its consideration_queue, and the result is used to determine whether the associated node is allowed to execute on that PASS. Custom Conditions allow arbitrary schedules to be created, in which the execution of each node can depend on one or more attributes of any other node in the graph.

For example, the following script fragment creates a custom Condition in which node_A is scheduled to wait to execute until node_B has “converged” (that is, settled to the point that none of its elements has changed in value more than a specified amount since the previous TIME_STEP):

def converge(node, thresh, context):
    for val in node.parameters.value.get_delta(context):
        if abs(val) >= thresh:
            return False
    return True
epsilon = 0.01
my_scheduler.add_condition(node_A, NWhen(Condition(converge, node_B, epsilon), 1))

In the example, a function converge is defined that references the change in a node’s value. The function is assigned to the standard Condition with node_A and epsilon as its arguments, and composite Condition NWhen (which is satisfied the first N times after its condition becomes true), The Condition is assigned to node_B, thus scheduling it to execute one time when all of the elements of node_A have changed by less than epsilon.

Structure¶

The Scheduler associates every node with a Condition. If a node has not been explicitly assigned a Condition, it is assigned a Condition that causes it to be executed whenever it is under consideration and all its structural parents have been executed at least once since the node’s last execution. Condition subclasses (listed below) provide a standard set of Conditions that can be implemented simply by specifying their parameter(s). There are six types:

  • Generic - satisfied when a user-specified function and set of arguments evaluates to True;

  • Static - satisfied either always or never;

  • Composite - satisfied based on one or more other Conditions;

  • Time-based - satisfied based on the current count of units of time at a specified TimeScale;

  • Node-based - based on the execution or state of other nodes.

  • Convenience - based on other Conditions, condensed for convenience

List of Pre-specified Conditions¶

Note

The optional TimeScale argument in many Conditions specifies the unit of time over which the Condition operates; the default value is TRIAL for all Conditions except those with “Trial” in their name, for which it is RUN.

Generic Conditions (used to construct custom Conditions):

  • While (func, *args, **kwargs) satisfied whenever the specified function (or callable) called with args and/or kwargs evaluates to True. Equivalent to Condition(func, *args, **kwargs)

  • WhileNot (func, *args, **kwargs) satisfied whenever the specified function (or callable) called with args and/or kwargs evaluates to False. Equivalent to Not(Condition(func, *args, **kwargs))

Static Conditions (independent of other Conditions, nodes or time):

  • Always always satisfied.

  • Never never satisfied.

Composite Conditions (based on one or more other Conditions):

  • All (*Conditions) satisfied whenever all of the specified Conditions are satisfied.

  • Any (*Conditions) satisfied whenever any of the specified Conditions are satisfied.

  • Not (Condition) satisfied whenever the specified Condition is not satisfied.

  • NWhen (Condition, int) satisfied the first specified number of times the specified Condition is satisfied.

Time-Based Conditions (based on the count of units of time at a specified TimeScale or Time):

  • TimeInterval ([pint.Quantity, pint.Quantity, pint.Quantity]) satisfied every time an optional amount of absolute time has passed in between an optional specified range

  • TimeTermination (pint.Quantity) satisfied after the given absolute time

  • BeforeTimeStep (int[, TimeScale]) satisfied any time before the specified TIME_STEP occurs.

  • AtTimeStep (int[, TimeScale]) satisfied only during the specified TIME_STEP.

  • AfterTimeStep (int[, TimeScale]) satisfied any time after the specified TIME_STEP has occurred.

  • AfterNTimeSteps (int[, TimeScale]) satisfied when or any time after the specified number of TIME_STEPs has occurred.

  • BeforePass (int[, TimeScale]) satisfied any time before the specified PASS occurs.

  • AtPass (int[, TimeScale]) satisfied only during the specified PASS.

  • AfterPass (int[, TimeScale]) satisfied any time after the specified PASS has occurred.

  • AfterNPasses (int[, TimeScale]) satisfied when or any time after the specified number of PASSes has occurred.

  • EveryNPasses (int[, TimeScale]) satisfied every time the specified number of PASSes occurs.

  • BeforeTrial (int[, TimeScale]) satisfied any time before the specified TRIAL occurs.

  • AtTrial (int[, TimeScale]) satisfied any time during the specified TRIAL.

  • AfterTrial (int[, TimeScale]) satisfied any time after the specified TRIAL occurs.

  • AfterNTrials (int[, TimeScale]) satisfied any time after the specified number of TRIALs has occurred.

  • AtRun (int) satisfied any time during the specified RUN.

  • AfterRun (int) satisfied any time after the specified RUN occurs.

  • AfterNRuns (int) satisfied any time after the specified number of RUNs has occurred.

Node-Based Conditions (based on the execution or state of other nodes):

  • BeforeNCalls (node, int[, TimeScale]) satisfied any time before the specified node has executed the specified number of times.

  • AtNCalls (node, int[, TimeScale]) satisfied when the specified node has executed the specified number of times.

  • AfterCall (node, int[, TimeScale]) satisfied any time after the node has executed the specified number of times.

  • AfterNCalls (node, int[, TimeScale]) satisfied when or any time after the node has executed the specified number of times.

  • AfterNCallsCombined (*nodes, int[, TimeScale]) satisfied when or any time after the specified nodes have executed the specified number of times among themselves, in total.

  • EveryNCalls (node, int[, TimeScale]) satisfied when the specified node has executed the specified number of times since the last time owner has run.

  • JustRan (node) satisfied if the specified node was assigned to run in the previous TIME_STEP.

  • AllHaveRun (*nodes) satisfied when all of the specified nodes have executed at least once.

  • WhenFinished (node) satisfied when the is_finished method of the specified node, given execution_id returns True.

  • WhenFinishedAny (*nodes) satisfied when the is_finished method of any of the specified nodes, given execution_id returns True.

  • WhenFinishedAll (*nodes) satisfied when the is_finished method of all of the specified nodes, given execution_id returns True.

Convenience Conditions (based on other Conditions, condensed for convenience)

  • AtTrialStart satisfied at the beginning of an TRIAL (AtPass(0))

  • AtTrialNStart satisfied on PASS 0 of the specified TRIAL counted using ‘TimeScale`

  • AtRunStart satisfied at the beginning of an RUN

  • AtRunNStart satisfied on TRIAL 0 of the specified RUN counted using ‘TimeScale`

Execution¶

When the Scheduler runs, it makes a sequential PASS through its consideration_queue, evaluating each consideration_set in the queue to determine which nodes should be assigned to execute. It evaluates the nodes in each set by calling the is_satisfied method of the Condition associated with each of those nodes. If it returns True, then the node is assigned to the execution set for the TIME_STEP of execution generated by that PASS. Otherwise, the node is not executed.

Class Reference¶

class psyneulink.core.scheduling.condition.AfterCall(dependency, n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • dependency (node) – the node on which the Condition depends

  • n (int) – the number of executions of dependency after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting executions of dependency

  • (default – TimeScale.TRIAL)

Satisfied when:

  • the node specified in dependency has executed at least n+1 times within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterNCalls(dependency, n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • dependency (node) – the node on which the Condition depends

  • n (int) – the number of executions of dependency after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting executions of dependency

  • (default – TimeScale.TRIAL)

Satisfied when:

  • the node specified in dependency has executed at least n times within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterNCallsCombined(*dependencies, n=None, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • *nodes (nodes) – one or more nodes on which the Condition depends

  • n (int) – the number of combined executions of all nodes specified in dependencies after which the

  • (default (Condition is satisfied) – None)

  • time_scale (TimeScale) – the TimeScale used as basis for counting executions of dependency

  • (default – TimeScale.TRIAL)

Satisfied when:

  • there have been at least n+1 executions among all of the nodes specified in dependencies within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterNPasses(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the number of PASSes after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting PASSes (default: TimeScale.TRIAL)

Satisfied when:

  • at least n PASSes have occurred within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterNConsiderationSetExecutions(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶

AfterNTimeSteps

Parameters
  • n (int) – the number of TIME_STEPs after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • at least n TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterNEnvironmentStateUpdates(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶

AfterNTrials

Parameters
  • n (int) – the number of TRIALs after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • at least n TRIALs have occured within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterPass(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the PASS after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting PASSes (default: TimeScale.TRIAL)

Satisfied when:

  • at least n+1 PASSes have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first PASS is 0, the second PASS is 1, etc.); so, AfterPass(1) is satisfied after PASS 1 has occurred and thereafter (i.e., in PASSes 2, 3, 4, etc.).

class psyneulink.core.scheduling.condition.AtEnvironmentSequence(n)¶

AtRun

Parameters

n (int) – the RUN at which the Condition is satisfied

Satisfied when:

  • exactly n RUNs have occurred.

Notes

  • RUNs are managed by the environment using the Scheduler (e.g. end_environment_sequence ) and are not automatically updated by this package.

class psyneulink.core.scheduling.condition.AfterEnvironmentSequence(n)¶

AfterRun

Parameters

n (int) – the RUN after which the Condition is satisfied

Satisfied when:

  • at least n+1 RUNs have occurred.

Notes

  • RUNs are managed by the environment using the Scheduler (e.g. end_environment_sequence ) and are not automatically updated by this package.

class psyneulink.core.scheduling.condition.AfterNEnvironmentSequences(n)¶

AfterNRuns

Parameters

n (int) – the number of RUNs after which the Condition is satisfied

Satisfied when:

  • at least n RUNs have occured.

Notes

  • RUNs are managed by the environment using the Scheduler (e.g. end_environment_sequence ) and are not automatically updated by this package.

class psyneulink.core.scheduling.condition.AfterConsiderationSetExecution(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶

AfterTimeStep

Parameters
  • n (int) – the TIME_STEP after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • at least n+1 TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScals are zero-indexed (that is, the first TIME_STEP is 0, the second TIME_STEP is 1, etc.); so, AfterTimeStep(1) is satisfied after TIME_STEP 1 has occurred and thereafter (i.e., in TIME_STEPs 2, 3, 4, etc.).

class psyneulink.core.scheduling.condition.AfterEnvironmentStateUpdate(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶

AfterTrial

Parameters
  • n (int) – the TRIAL after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs.

  • (default – TimeScale.RUN)

Satisfied when:

  • at least n+1 TRIALs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TRIAL is 0, the second

TRIAL is 1, etc.); so, AfterPass(1) is satisfied after TRIAL 1 has occurred and thereafter (i.e., in TRIALs 2, 3, 4, etc.).

class psyneulink.core.scheduling.condition.All(*args, **dependencies)¶
Parameters

args – one or more Conditions

Satisfied when:

  • all of the Conditions in args are satisfied.

Notes

  • To initialize with a list (for example):

    conditions = [AfterNCalls(node, 5) for node in node_list]
    

    unpack the list to supply its members as args:

    composite_condition = All(*conditions)
    
class psyneulink.core.scheduling.condition.AllHaveRun(*dependencies, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • *nodes (nodes) – an iterable of nodes on which the Condition depends

  • time_scale (TimeScale) – the TimeScale used as basis for counting executions of dependency

  • (default – TimeScale.TRIAL)

Satisfied when:

  • all of the nodes specified in dependencies have executed at least once within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.Always¶
Parameters

none –

Satisfied when:

  • always satisfied.

class psyneulink.core.scheduling.condition.And(*args, **dependencies)¶
Parameters

args – one or more Conditions

Satisfied when:

  • all of the Conditions in args are satisfied.

Notes

  • To initialize with a list (for example):

    conditions = [AfterNCalls(node, 5) for node in node_list]
    

    unpack the list to supply its members as args:

    composite_condition = All(*conditions)
    
class psyneulink.core.scheduling.condition.Any(*args, **dependencies)¶
Parameters

args – one or more Conditions

Satisfied when:

  • one or more of the Conditions in args is satisfied.

Notes

  • To initialize with a list (for example):

    conditions = [AfterNCalls(node, 5) for node in node_list]
    

    unpack the list to supply its members as args:

    composite_condition = Any(*conditions)
    
class psyneulink.core.scheduling.condition.AtNCalls(dependency, n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • dependency (node) – the node on which the Condition depends

  • n (int) – the number of executions of dependency at which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting executions of dependency

  • (default – TimeScale.TRIAL)

Satisfied when:

  • the node specified in dependency has executed exactly n times within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AtPass(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the PASS at which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting PASSes (default: TimeScale.TRIAL)

Satisfied when:

  • exactly n PASSes have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first ‘PASS’ is pass 0, the second ‘PASS’ is 1, etc.); so, AtPass(1) is satisfied when a single PASS (PASS 0) has occurred, and AtPass(2) is satisfied when two PASSes have occurred (PASS 0 and PASS 1), etc..

class psyneulink.core.scheduling.condition.AtEnvironmentSequenceStart¶

AtRunStart

Satisfied when:

  • at the beginning of an RUN

Notes

  • identical to AtTrial(0)

class psyneulink.core.scheduling.condition.AtEnvironmentSequenceNStart(n)¶

AtRunNStart

Parameters

n (int) – the RUN on which the Condition is satisfied

Satisfied when:

  • on TRIAL 0 of the specified RUN counted using ‘TimeScale`

Notes

  • identical to All(AtTrial(0), AtRun(n))

class psyneulink.core.scheduling.condition.AtConsiderationSetExecution(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶

AtTimeStep

Parameters
  • n (int) – the TIME_STEP at which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • exactly n TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first ‘TIME_STEP’ is pass 0, the second ‘TIME_STEP’ is 1, etc.); so, AtTimeStep(1) is satisfied when a single TIME_STEP (TIME_STEP 0) has occurred, and AtTimeStep(2) is satisfied when two TIME_STEPs have occurred (TIME_STEP 0 and TIME_STEP 1), etc..

class psyneulink.core.scheduling.condition.AtEnvironmentStateUpdate(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶

AtTrial

Parameters
  • n (int) – the TRIAL at which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • exactly n TRIALs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TRIAL is 0, the second TRIAL is 1, etc.); so, AtTrial(1) is satisfied when one TRIAL (TRIAL 0) has already occurred.

class psyneulink.core.scheduling.condition.AtEnvironmentStateUpdateStart¶

AtTrialStart

Satisfied when:

  • at the beginning of an TRIAL

Notes

  • identical to AtPass(0)

class psyneulink.core.scheduling.condition.AtEnvironmentStateUpdateNStart(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶

AtTrialNStart

Parameters
  • n (int) – the TRIAL on which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • on PASS 0 of the specified TRIAL counted using ‘TimeScale`

Notes

  • identical to All(AtPass(0), AtTrial(n, time_scale))

class psyneulink.core.scheduling.condition.BeforeNCalls(dependency, n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • dependency (node) – the node on which the Condition depends

  • n (int) – the number of executions of dependency before which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting executions of dependency

  • (default – TimeScale.TRIAL)

Satisfied when:

  • the node specified in dependency has executed at most n-1 times within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.BeforePass(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the ‘PASS’ before which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting PASSes (default: TimeScale.TRIAL)

Satisfied when:

  • at most n-1 PASSes have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first PASS is 0, the second PASS is 1, etc.); so, BeforePass(2) is satisfied at PASS 0 and PASS 1.

class psyneulink.core.scheduling.condition.BeforeConsiderationSetExecution(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶

BeforeTimeStep

Parameters
  • n (int) – the ‘TIME_STEP’ before which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • at most n-1 TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TIME_STEP is 0, the second TIME_STEP is 1, etc.); so, BeforeTimeStep(2) is satisfied at TIME_STEP 0 and TIME_STEP 1.

class psyneulink.core.scheduling.condition.BeforeEnvironmentStateUpdate(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶

BeforeTrial

Parameters
  • n (int) – the TRIAL before which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • at most n-1 TRIALs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TRIAL is 0, the second TRIAL is 1, etc.); so, BeforeTrial(2) is satisfied at TRIAL 0 and TRIAL 1.

class psyneulink.core.scheduling.condition.Condition(func, *args, **kwargs)¶

Used in conjunction with a Scheduler to specify the condition under which a node should be allowed to execute.

Parameters
  • func (callable) – specifies function to be called when the Condition is evaluated, to determine whether it is currently satisfied.

  • args (*args) – specifies formal arguments to pass to func when the Condition is evaluated.

  • kwargs (**kwargs) – specifies keyword arguments to pass to func when the Condition is evaluated.

owner(node)¶

the node with which the Condition is associated, and the execution of which it determines.

is_satisfied(*args, context=None, execution_id=None, **kwargs)¶

the function called to determine satisfaction of this Condition.

Parameters
  • args (*args) – specifies additional formal arguments to pass to func when the Condition is evaluated. these are appended to the args specified at instantiation of this Condition

  • kwargs (**kwargs) – specifies additional keyword arguments to pass to func when the Condition is evaluated. these are added to the kwargs specified at instantiation of this Condition

Returns

  • True - if the Condition is satisfied

  • False - if the Condition is not satisfied

exception psyneulink.core.scheduling.condition.ConditionError(error_value)¶

None

class psyneulink.core.scheduling.condition.ConditionSet(conditions=None)¶

Used in conjunction with a Scheduler to store the Conditions associated with a node.

Parameters

conditions (Dict[node: Condition]) – specifies an iterable collection of nodes and the Conditions associated with each.

conditions¶

the key of each entry is a node, and its value is the Condition associated with that node. Conditions can be added to the ConditionSet using the ConditionSet’s add_condition method.

Type

Dict[node: Condition]

add_condition(owner, condition)¶

Adds a Condition to the ConditionSet. If owner already has a Condition, it is overwritten with the new one. If you want to add multiple conditions to a single owner, use the composite Conditions to accurately specify the desired behavior.

Parameters
  • owner (node) – specifies the node with which the condition should be associated. condition will govern the execution behavior of owner

  • condition (Condition) – specifies the Condition, associated with the owner to be added to the ConditionSet.

add_condition_set(conditions)¶

Adds a set of Conditions (in the form of a dict or another ConditionSet) to the ConditionSet. Any Condition added here will overwrite an existing Condition for a given owner. If you want to add multiple conditions to a single owner, add a single Composite Condition to accurately specify the desired behavior.

Parameters

conditions (dict[node: Condition], ConditionSet) –

specifies collection of Conditions to be added to this ConditionSet,

if a dict is provided:

each entry should map an owner node (the node whose execution behavior will be governed) to a Condition

class psyneulink.core.scheduling.condition.EveryNCalls(dependency, n)¶
Parameters
  • dependency (node) – the node on which the Condition depends

  • n (int) – the frequency of executions of dependency at which the Condition is satisfied

Satisfied when:

  • the node specified in dependency has executed at least n times since the last time the Condition’s owner executed.

Notes

  • scheduler’s count of each other node that is “useable” by the node is reset to 0 when the node runs

class psyneulink.core.scheduling.condition.EveryNPasses(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the frequency of passes with which this condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting PASSes (default: TimeScale.TRIAL)

Satisfied when:

  • PASS 0

  • the specified number of PASSes that has occurred within a unit of time (at the TimeScale specified by time_scale) is evenly divisible by n.

class psyneulink.core.scheduling.condition.JustRan(dependency)¶
Parameters

dependency (node) – the node on which the Condition depends

Satisfied when:

  • the node specified in dependency executed in the previous TIME_STEP.

Notes

  • This Condition can transcend divisions between TimeScales. For example, if A runs in the final TIME_STEP of an TRIAL, JustRan(A) is satisfied at the beginning of the next TRIAL.

class psyneulink.core.scheduling.condition.Never¶
Parameters

none –

Satisfied when:

  • never satisfied.

class psyneulink.core.scheduling.condition.Not(condition)¶
Parameters

condition (Condition) – a Condition

Satisfied when:

  • condition is not satisfied.

class psyneulink.core.scheduling.condition.NWhen(condition, n=1)¶
Parameters
  • condition (Condition) – a Condition

  • n (int) – the maximum number of times this condition will be satisfied

Satisfied when:

  • the first n times condition is satisfied upon evaluation

class psyneulink.core.scheduling.condition.Or(*args, **dependencies)¶
Parameters

args – one or more Conditions

Satisfied when:

  • one or more of the Conditions in args is satisfied.

Notes

  • To initialize with a list (for example):

    conditions = [AfterNCalls(node, 5) for node in node_list]
    

    unpack the list to supply its members as args:

    composite_condition = Any(*conditions)
    
class psyneulink.core.scheduling.condition.WhenFinished(dependency)¶
Parameters

dependency (node) – the node on which the Condition depends

Satisfied when:

  • the is_finished methods of the node specified in dependencies returns True.

Notes

  • This is a dynamic Condition: Each node is responsible for managing its finished status on its own, which can occur independently of the execution of other nodes. Therefore the satisfaction of this Condition) can vary arbitrarily in time.

  • The is_finished method is called with execution_id as its sole positional argument

class psyneulink.core.scheduling.condition.WhenFinishedAll(*dependencies)¶
Parameters

*nodes (nodes) – zero or more nodes on which the Condition depends

Satisfied when:

  • the is_finished methods of all nodes specified in dependencies return True.

Notes

  • This is a convenience class; WhenFinishedAny(A, B, C) is equivalent to All(WhenFinished(A), WhenFinished(B), WhenFinished(C)). If no nodes are specified, the condition will default to checking all of scheduler’s nodes.

  • This is a dynamic Condition: Each node is responsible for managing its finished status on its own, which can occur independently of the execution of other nodes. Therefore the satisfaction of this Condition) can vary arbitrarily in time.

  • The is_finished method is called with execution_id as its sole positional argument

class psyneulink.core.scheduling.condition.WhenFinishedAny(*dependencies)¶
Parameters

*nodes (nodes) – zero or more nodes on which the Condition depends

Satisfied when:

  • the is_finished methods of any nodes specified in dependencies returns True.

Notes

  • This is a convenience class; WhenFinishedAny(A, B, C) is equivalent to Any(WhenFinished(A), WhenFinished(B), WhenFinished(C)). If no nodes are specified, the condition will default to checking all of scheduler’s nodes.

  • This is a dynamic Condition: Each node is responsible for managing its finished status on its own, which can occur independently of the execution of other nodes. Therefore the satisfaction of this Condition) can vary arbitrarily in time.

  • The is_finished method is called with execution_id as its sole positional argument

class psyneulink.core.scheduling.condition.While(func, *args, **kwargs)¶

Used in conjunction with a Scheduler to specify the condition under which a node should be allowed to execute.

Parameters
  • func (callable) – specifies function to be called when the Condition is evaluated, to determine whether it is currently satisfied.

  • args (*args) – specifies formal arguments to pass to func when the Condition is evaluated.

  • kwargs (**kwargs) – specifies keyword arguments to pass to func when the Condition is evaluated.

owner(node)¶

the node with which the Condition is associated, and the execution of which it determines.

class psyneulink.core.scheduling.condition.WhileNot(func, *args, **kwargs)¶
Parameters
  • func – callable specifies function to be called when the Condition is evaluated, to determine whether it is currently satisfied.

  • args – *args specifies formal arguments to pass to func when the Condition is evaluated.

  • kwargs – **kwargs specifies keyword arguments to pass to func when the Condition is evaluated.

Satisfied when:

  • func is False

class psyneulink.core.scheduling.condition.TimeInterval(repeat=None, start=None, end=None, unit=<Unit('millisecond')>, start_inclusive=True, end_inclusive=True)¶
repeat¶

the interval between *unit*s where this condition can be satisfied

start¶

the time at/after which this condition can be satisfied

end¶

the time at/fter which this condition can be satisfied

unit¶

the pint.Unit to use for scalar values of repeat, start, and end

start_inclusive¶

if True, start allows satisfaction exactly at the time corresponding to start. if False, satisfaction can occur only after start

end_inclusive¶

if True, end allows satisfaction exactly until the time corresponding to end. if False, satisfaction can occur only before end

Satisfied when:

Every repeat units of time at/after start and before/through end

Notes

Using a TimeInterval as a termination Condition may result in unexpected behavior. The user may be inclined to create TimeInterval(end=x) to terminate at time x, but this will do the opposite and be true only and always until time x, terminating at any time before x. If in doubt, use TimeTermination instead.

If the scheduler is not set to exact_time_mode = True, start_inclusive and end_inclusive may not behave as expected. See Exact Time Mode for more info.

class psyneulink.core.scheduling.condition.TimeTermination(t, inclusive=True, unit=<Unit('millisecond')>)¶
t¶

the time at/after which this condition is satisfied

unit¶

the pint.Unit to use for scalar values of t, start, and end

start_inclusive¶

if True, the condition is satisfied exactly at the time corresponding to t. if False, satisfaction can occur only after t

Satisfied when:

At/After time t

class psyneulink.core.scheduling.condition.Threshold(dependency, parameter, threshold, comparator, indices=None, atol=0, rtol=0)¶
dependency¶

the node on which the Condition depends

parameter¶

the name of the parameter of dependency whose value is to be compared to threshold

threshold¶

the fixed value compared to the value of the parameter

comparator¶

the string comparison operator determining the direction or type of comparison of the value of the parameter relative to threshold

indices¶

if specified, a series of indices that reach the desired number given an iterable value for parameter

atol¶

absolute tolerance for the comparison

rtol¶

relative tolerance (to threshold) for the comparison

Satisfied when:

The comparison between the value of the parameter and threshold using comparator is true. If comparator is an equality (==, !=), the comparison will be considered equal within tolerances atol and rtol.

Notes

The comparison must be done with scalars. If the value of parameter contains more than one item, indices must be specified.

class psyneulink.core.scheduling.condition.AfterNTimeSteps(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the number of TIME_STEPs after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • at least n TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterTimeStep(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the TIME_STEP after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • at least n+1 TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScals are zero-indexed (that is, the first TIME_STEP is 0, the second TIME_STEP is 1, etc.); so, AfterTimeStep(1) is satisfied after TIME_STEP 1 has occurred and thereafter (i.e., in TIME_STEPs 2, 3, 4, etc.).

class psyneulink.core.scheduling.condition.AtTimeStep(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the TIME_STEP at which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • exactly n TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first ‘TIME_STEP’ is pass 0, the second ‘TIME_STEP’ is 1, etc.); so, AtTimeStep(1) is satisfied when a single TIME_STEP (TIME_STEP 0) has occurred, and AtTimeStep(2) is satisfied when two TIME_STEPs have occurred (TIME_STEP 0 and TIME_STEP 1), etc..

class psyneulink.core.scheduling.condition.BeforeTimeStep(n, time_scale=TimeScale.ENVIRONMENT_STATE_UPDATE)¶
Parameters
  • n (int) – the ‘TIME_STEP’ before which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TIME_STEPs (default: TimeScale.TRIAL)

Satisfied when:

  • at most n-1 TIME_STEPs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TIME_STEP is 0, the second TIME_STEP is 1, etc.); so, BeforeTimeStep(2) is satisfied at TIME_STEP 0 and TIME_STEP 1.

class psyneulink.core.scheduling.condition.AfterNTrials(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶
Parameters
  • n (int) – the number of TRIALs after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • at least n TRIALs have occured within one unit of time at the TimeScale specified by time_scale.

class psyneulink.core.scheduling.condition.AfterTrial(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶
Parameters
  • n (int) – the TRIAL after which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs.

  • (default – TimeScale.RUN)

Satisfied when:

  • at least n+1 TRIALs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TRIAL is 0, the second

TRIAL is 1, etc.); so, AfterPass(1) is satisfied after TRIAL 1 has occurred and thereafter (i.e., in TRIALs 2, 3, 4, etc.).

class psyneulink.core.scheduling.condition.AtTrial(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶
Parameters
  • n (int) – the TRIAL at which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • exactly n TRIALs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TRIAL is 0, the second TRIAL is 1, etc.); so, AtTrial(1) is satisfied when one TRIAL (TRIAL 0) has already occurred.

class psyneulink.core.scheduling.condition.AtTrialStart¶

Satisfied when:

  • at the beginning of an TRIAL

Notes

  • identical to AtPass(0)

class psyneulink.core.scheduling.condition.AtTrialNStart(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶
Parameters
  • n (int) – the TRIAL on which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • on PASS 0 of the specified TRIAL counted using ‘TimeScale`

Notes

  • identical to All(AtPass(0), AtTrial(n, time_scale))

class psyneulink.core.scheduling.condition.BeforeTrial(n, time_scale=TimeScale.ENVIRONMENT_SEQUENCE)¶
Parameters
  • n (int) – the TRIAL before which the Condition is satisfied

  • time_scale (TimeScale) – the TimeScale used as basis for counting TRIALs

  • (default – TimeScale.RUN)

Satisfied when:

  • at most n-1 TRIALs have occurred within one unit of time at the TimeScale specified by time_scale.

Notes

  • Counts of TimeScales are zero-indexed (that is, the first TRIAL is 0, the second TRIAL is 1, etc.); so, BeforeTrial(2) is satisfied at TRIAL 0 and TRIAL 1.

class psyneulink.core.scheduling.condition.AtRun(n)¶
Parameters

n (int) – the RUN at which the Condition is satisfied

Satisfied when:

  • exactly n RUNs have occurred.

Notes

  • RUNs are managed by the environment using the Scheduler (e.g. end_environment_sequence ) and are not automatically updated by this package.

class psyneulink.core.scheduling.condition.AfterRun(n)¶
Parameters

n (int) – the RUN after which the Condition is satisfied

Satisfied when:

  • at least n+1 RUNs have occurred.

Notes

  • RUNs are managed by the environment using the Scheduler (e.g. end_environment_sequence ) and are not automatically updated by this package.

class psyneulink.core.scheduling.condition.AfterNRuns(n)¶
Parameters

n (int) – the number of RUNs after which the Condition is satisfied

Satisfied when:

  • at least n RUNs have occured.

Notes

  • RUNs are managed by the environment using the Scheduler (e.g. end_environment_sequence ) and are not automatically updated by this package.

class psyneulink.core.scheduling.condition.AtRunStart¶

Satisfied when:

  • at the beginning of an RUN

Notes

  • identical to AtTrial(0)

class psyneulink.core.scheduling.condition.AtRunNStart(n)¶
Parameters

n (int) – the RUN on which the Condition is satisfied

Satisfied when:

  • on TRIAL 0 of the specified RUN counted using ‘TimeScale`

Notes

  • identical to All(AtTrial(0), AtRun(n))


© Copyright 2016, Jonathan D. Cohen.

Built with Sphinx using a theme provided by Read the Docs.
  • Condition
    • Overview
    • Creating Conditions
      • Pre-specified Conditions
      • Custom Conditions
    • Structure
      • List of Pre-specified Conditions
    • Execution
    • Class Reference
  • Github