# Context¶

## Overview¶

The Context class is used for the context attribute of all Components. It is set when a Component is first instantiated, and updated under various operating conditions. Its primary attribute is flags - a binary vector, the individual flags of which are specified using the ContextFlags enum. The flags attribute is divided functionally into the three fields:

Each field can be addressed using the corresponding property of the class, and in general only one of the flags in a field is set (although see individual property documentation for exceptions).

## Context and Logging¶

The flags attribute is used by Log to identify conditions for logging (see). Accordingly, the LogCondition(s) used to specify such conditions in the set_log_conditions method of Log are a subset of (and are aliased to) the flags in ContextFlags.

In addition to flags, Context has four other attributes that record information relevant to the operating state of the Component:

owner
the Component to which the Context belongs (assigned to its context attribute;
flags_string
a string containing the names of the flags currently set in each of the fields of the flags attribute;
composition
the Composition in which the Component is currently being executed;
execution_id
the execution_id assigned to the Component by the Composition in which it is currently being executed;
execution_time
the current time of the scheduler running the Composition within which the Component is currently being executed;
string
contains message(s) relevant to a method of the Component currently invoked or that is referencing the Component. In general, this contains a copy of the context argument passed to method of the Component or one that references it, but it is possible that future uses will involve other messages.

Note

The string attribute of Context is not the same as, nor does it usually contain the same information as the string returned by the flags_string method of Context.

## Class Reference¶

class psyneulink.core.globals.context.ContextFlags

Used to identify the initialization and execution status of a Component.

Used when a Component’s value or one of its attributes is being accessed. Also used to specify the context in which a value of the Component or its attribute is logged..

DEFERRED_INIT = 2

Set if flagged for deferred initialization.

INITIALIZING = 4

Set during initialization of the Component.

VALIDATING = 8

Set during validation of the value of a Component or its attribute.

INITIALIZED = 16

Set after completion of initialization of the Component.

REINITIALIZED = 16

Set on stateful Components when they are re-initialized.

PROCESSING = 32

Set during the processing phase of execution of a Composition.

LEARNING = 64

Set during the learning phase of execution of a Composition.

CONTROL = 128

Set during the control phase System_Execution_Control> of execution of a Composition.

SIMULATION = 256

Set during simulation by Composition.controller

IDLE = -481

Identifies condition in which no flags in the execution_phase are set.

COMMAND_LINE = 512

Direct call by user (either interactively from the command line, or in a script).

CONSTRUCTOR = 1024

Call from Component’s constructor method.

INSTANTIATE = 2048

Call by an instantiation method.

COMPONENT = 4096

Call by Component __init__.

METHOD = 8192

Call by method of the Component other than its constructor.

PROPERTY = 16384

Call by property of the Component.

COMPOSITION = 32768

Call by a/the Composition to which the Component belongs.

PROCESS = 32768

Call by a/the Composition to which the Component belongs.

class psyneulink.core.globals.context.Context(owner=None, composition=None, flags=None, initialization_status=<ContextFlags.UNINITIALIZED: -31>, execution_phase=None, source=<ContextFlags.NONE: -56833>, execution_id: uuid.UUID = None, string: str = '', time=None)

Used to indicate the state of initialization and phase of execution of a Component, as well as the source of call of a method; also used to specify and identify conditions for logging.

owner

Component – Component to which the Context belongs.

flags

binary vector – represents the current operating context of the owner; contains three fields initialization_status, execution_phase, and source (described below).

flags_string

str – contains the names of the flags currently set in each of the fields of the flags attribute; note that this is not the same as the string attribute (see note).

initialization_status

field of flags attribute – indicates the state of initialization of the Component; one and only one of the following flags is always set:

execution_phase

field of flags attribute – indicates the phase of execution of the Component; one or more of the following flags can be set:

If no flags are set, the Component is not being executed at the current time, and flags_string will include IDLE in the string. In some circumstances all of the execution_phase flags may be set, in which case flags_string will include EXECUTING in the string.

source

field of the flags attribute – indicates the source of a call to a method belonging to or referencing the Component; one of the following flags is always set:

composition

Composition – the Composition in which the owner is currently being executed.

execution_id

UUID – the execution_id assigned to the Component by the Composition in which it is currently being executed.

execution_time

TimeScale – current time of the Scheduler running the Composition within which the Component is currently being executed.

string

str – contains message(s) relevant to a method of the Component currently invoked or that is referencing the Component. In general, this contains a copy of the context argument passed to method of the Component or one that references it, but it is possible that future uses will involve other messages. Note that this is not the same as the flags_string attribute (see note).