Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/log/log levels #580

Merged
merged 24 commits into from
Dec 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
529 changes: 269 additions & 260 deletions Scripts/Scratch Pad.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions psyneulink/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,6 +2434,7 @@ def value(self):
@value.setter
def value(self, assignment):
self._value = assignment
self.log._log_value(assignment)

# # MODIFIED 1/28/17 NEW: [COPIED FROM State]
# # Store value in log if specified
Expand Down
2 changes: 2 additions & 0 deletions psyneulink/components/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,8 @@ def _execute_learning(self, target=None, clock=CentralClock, context=None):
# Note: do this rather just calling LearningSignals directly
# since parameter_state.update() handles parsing of LearningProjection-specific params
context = context + SEPARATOR_BAR + LEARNING
# FIX: IMPLEMENT EXECUTION+LEARNING CONDITION
# context = context.replace(EXECUTING, LEARNING + ' ')

# NOTE: This will need to be updated when runtime params are re-enabled
# parameter_state.update(params=params, time_scale=TimeScale.TRIAL, context=context)
Expand Down
22 changes: 0 additions & 22 deletions psyneulink/components/projections/pathway/mappingprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,28 +658,6 @@ def matrix(self, matrix):

self.function_object.matrix = matrix

# # Log matrix value if specified by owner, sender, or sender's owner
#
# # Get context
# try:
# curr_frame = inspect.currentframe()
# prev_frame = inspect.getouterframes(curr_frame, 2)
# context = inspect.getargvalues(prev_frame[2][0]).locals['context']
# except KeyError:
# context = ""

# # Get logPref
# self_log_pref = self.prefs.logPref if self.prefs else None
#
# # Go through loggers, and if context is consistent with log_pref of logger, record value to logger's log
# for log_name, log, log_pref in loggers:
# if (log_pref is LogLevel.ALL_ASSIGNMENTS or
# (INITIALIZING in context and log_pref is LogLevel.INITIALIZATION) or
# (EXECUTING in context and log_pref is LogLevel.EXECUTION) or
# (all(c in context for c in {EXECUTING, kwAssign}) and log_pref is LogLevel.VALUE_ASSIGNMENT)):
# log.entries[self.name] = LogEntry(CurrentTime(), context, matrix)


@property
def _matrix_spec(self):
"""Returns matrix specification in self.paramsCurrent[FUNCTION_PARAMS][MATRIX]
Expand Down
29 changes: 2 additions & 27 deletions psyneulink/components/projections/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.registry import register_category
from psyneulink.globals.utilities import ContentAddressableList, iscompatible, is_numeric, is_matrix, type_match
from psyneulink.globals.log import LogLevel, LogEntry
from psyneulink.globals.log import LogLevel, LogEntry, _get_log_context
from psyneulink.scheduling.timescale import CurrentTime

__all__ = [
Expand Down Expand Up @@ -965,33 +965,8 @@ def value(self):

@value.setter
def value(self, assignment):

self._value = assignment

# STORE value IN log IF SPECIFIED

# Get context
try:
curr_frame = inspect.currentframe()
prev_frame = inspect.getouterframes(curr_frame, 2)
# context = inspect.getargvalues(prev_frame[1][0]).locals['context']
context = inspect.getargvalues(prev_frame[2][0]).locals['context']
except KeyError:
context = ""
if not isinstance(context, str):
context = ""

# Get logPref
log_pref = self.prefs.logPref if self.prefs else None

# If context is consistent with log_pref, record value to log
if (log_pref is LogLevel.ALL_ASSIGNMENTS or
(INITIALIZING in context and log_pref is LogLevel.INITIALIZATION) or
(EXECUTING in context and log_pref is LogLevel.EXECUTION) or
(all(c in context for c in {EXECUTING, kwAssign}) and log_pref is LogLevel.VALUE_ASSIGNMENT)
):
self.log.entries[self.name] = LogEntry(CurrentTime(), context, assignment)

self.log._log_value(assignment)

@tc.typecheck
def _is_projection_spec(spec, proj_type:tc.optional(type)=None, include_matrix_spec=True):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,8 @@ def value(self):
# FIX: NEED TO DEAL WITH LOGGING HERE (AS PER @PROPERTY State.value)
return self._intensity


@value.setter
def value(self, assignment):
self._value = assignment
self.log._log_value(assignment)
25 changes: 2 additions & 23 deletions psyneulink/components/states/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def test_multiple_modulatory_projections_with_mech_and_state_name_specs(self):
PREFS_ARG, PROJECTIONS, PROJECTION_PARAMS, PROJECTION_TYPE, RECEIVER, REFERENCE_VALUE, REFERENCE_VALUE_NAME, \
SENDER, SIZE, STANDARD_OUTPUT_STATES, STATE, STATE_PARAMS, STATE_TYPE, STATE_VALUE, VALUE, VARIABLE, \
kwAssign, kwStateComponentCategory, kwStateContext, kwStateName, kwStatePrefs
from psyneulink.globals.log import LogEntry, LogLevel
from psyneulink.globals.log import LogEntry, LogLevel, _get_log_context
from psyneulink.globals.preferences.componentpreferenceset import kpVerbosePref
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.registry import register_category
Expand Down Expand Up @@ -2052,28 +2052,7 @@ def value(self, assignment):
# MODIFIED 7/8/17 END

self._value = assignment

# STORE value IN log IF SPECIFIED

# Get context
try:
curr_frame = inspect.currentframe()
prev_frame = inspect.getouterframes(curr_frame, 2)
context = inspect.getargvalues(prev_frame[1][0]).locals['context']
except KeyError:
context = ""

# Get logPref
log_pref = self.prefs.logPref if self.prefs else None


# If context is consistent with log_pref, record value to log
if (log_pref is LogLevel.ALL_ASSIGNMENTS or
(INITIALIZING in context and log_pref is LogLevel.INITIALIZATION) or
((EXECUTING in context and not LEARNING in context) and log_pref is LogLevel.EXECUTION) or
(all(c in context for c in {EXECUTING, kwAssign}) and log_pref is LogLevel.VALUE_ASSIGNMENT)
):
self.log.entries[self.name] = LogEntry(CurrentTime(), context, assignment)
self.log._log_value(assignment)

@property
def projections(self):
Expand Down
13 changes: 11 additions & 2 deletions psyneulink/components/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,14 @@
from psyneulink.components.shellclasses import Mechanism, Process_Base, System_Base
from psyneulink.components.states.inputstate import InputState
from psyneulink.components.states.state import _parse_state_spec
from psyneulink.globals.keywords import ALL, COMPONENT_INIT, CONROLLER_PHASE_SPEC, CONTROL, CONTROLLER, CYCLE, EVC_SIMULATION, EXECUTING, EXPONENT, FUNCTION, IDENTITY_MATRIX, INITIALIZED, INITIALIZE_CYCLE, INITIALIZING, INITIAL_VALUES, INTERNAL, LEARNING, LEARNING_SIGNAL, MATRIX, MONITOR_FOR_CONTROL, ORIGIN, PARAMS, PROJECTIONS, SAMPLE, SINGLETON, SYSTEM, SYSTEM_INIT, TARGET, TERMINAL, TIME_SCALE, WEIGHT, kwSeparator, kwSystemComponentCategory
from psyneulink.globals.keywords import ALL, COMPONENT_INIT, CONROLLER_PHASE_SPEC, CONTROL, CONTROLLER, CYCLE, \
EVC_SIMULATION, EXECUTING, EXPONENT, FUNCTION, IDENTITY_MATRIX, INITIALIZED, INITIALIZE_CYCLE, INITIALIZING, \
INITIAL_VALUES, INTERNAL, LEARNING, LEARNING_SIGNAL, MATRIX, MONITOR_FOR_CONTROL, ORIGIN, PARAMS, PROJECTIONS, \
SAMPLE, SINGLETON, SYSTEM, SYSTEM_INIT, TARGET, TERMINAL, TIME_SCALE, WEIGHT, kwSeparator, \
kwSystemComponentCategory, SEPARATOR_BAR
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.log import Log
from psyneulink.globals.registry import register_category
from psyneulink.globals.utilities import AutoNumber, ContentAddressableList, append_type_to_name, convert_to_np_array, iscompatible
from psyneulink.scheduling.scheduler import Scheduler
Expand Down Expand Up @@ -2533,7 +2538,9 @@ def execute(self,

# Don't execute learning for simulation runs
if not EVC_SIMULATION in context and self.learning:
self._execute_learning(clock=clock, context=context + ' ' + LEARNING)
self._execute_learning(clock=clock, context=context + SEPARATOR_BAR + LEARNING)
# FIX: IMPLEMENT EXECUTION+LEARNING CONDITION
# self._execute_learning(clock=clock, context=context.replace(EXECUTING, LEARNING + ' '))
# endregion


Expand Down Expand Up @@ -3571,6 +3578,8 @@ def __init__(self, owner=None, variable=None, name=None, prefs=None):
else:
self.name = owner.name + "_" + name
self.prefs = prefs
self.log = Log(owner=self)
self.recording = False
self.efferents = []
self.owner = owner
self.value = variable
2 changes: 1 addition & 1 deletion psyneulink/globals/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,4 +1029,4 @@ def _get_object_type(object):

import uuid
def _get_unique_id():
return uuid.uuid4()
return uuid.uuid4()
26 changes: 18 additions & 8 deletions psyneulink/globals/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@
'DEFERRED_ASSIGNMENT', 'DEFERRED_DEFAULT_NAME', 'DEFERRED_INITIALIZATION', 'DIFFERENCE', 'DIFFERENCE', 'DIFFUSION',
'DIST_FUNCTION_TYPE', 'DIST_MEAN', 'DIST_SHAPE', 'DISTANCE_FUNCTION', 'DISTANCE_METRICS', 'DISTRIBUTION_FUNCTION_TYPE',
'DIVISION', 'DRIFT_DIFFUSION_INTEGRATOR_FUNCTION', 'DRIFT_RATE', 'ENABLE_CONTROLLER', 'ENABLED', 'ENERGY', 'ENTROPY',
'ERROR_DERIVATIVE_FUNCTION', 'EUCLIDEAN', 'EVC_MECHANISM', 'EVC_SIMULATION', 'EXAMPLE_FUNCTION_TYPE', 'EXECUTING',
'EXPONENT', 'EXPONENTIAL_DIST_FUNCTION', 'EXPONENTIAL_FUNCTION', 'EXPONENTS', 'FHN_INTEGRATOR_FUNCTION', 'FULL',
'FULL_CONNECTIVITY_MATRIX', 'FUNCTION', 'FUNCTION_CHECK_ARGS', 'FUNCTION_OUTPUT_TYPE',
'ERROR_DERIVATIVE_FUNCTION', 'EUCLIDEAN', 'EVC_MECHANISM', 'EVC_SIMULATION', 'EXAMPLE_FUNCTION_TYPE',
'EXECUTING', 'EXECUTION', 'EXPONENT', 'EXPONENTIAL_DIST_FUNCTION', 'EXPONENTIAL_FUNCTION', 'EXPONENTS',
'FHN_INTEGRATOR_FUNCTION', 'FINAL', 'FULL', 'FULL_CONNECTIVITY_MATRIX',
'FUNCTION', 'FUNCTION_CHECK_ARGS', 'FUNCTION_OUTPUT_TYPE',
'FUNCTION_OUTPUT_TYPE_CONVERSION', 'FUNCTION_PARAMS', 'GAIN', 'GAMMA_DIST_FUNCTION', 'GATE', 'GATING',
'GATING_MECHANISM', 'GATING_POLICY', 'GATING_PROJECTION', 'GATING_PROJECTION_PARAMS', 'GATING_PROJECTIONS',
'GATING_SIGNAL', 'GATING_SIGNAL_SPECS', 'GATING_SIGNALS', 'GILZENRAT_INTEGRATOR_FUNCTION', 'HARD_CLAMP',
'HEBBIAN_FUNCTION', 'HETERO', 'HIGH', 'HOLLOW_MATRIX', 'IDENTITY_MATRIX', 'INCREMENT', 'INDEX',
'INIT__EXECUTE__METHOD_ONLY', 'INIT_FULL_EXECUTE_METHOD', 'INIT_FUNCTION_METHOD_ONLY', 'INITIAL_VALUES',
'INITIALIZE_CYCLE', 'INITIALIZED', 'INITIALIZER', 'INITIALIZING', 'INPUT_STATE', 'INPUT_STATE_PARAMS', 'INPUT_STATES',
'INITIALIZE_CYCLE', 'INITIALIZATION', 'INITIALIZED', 'INITIALIZER', 'INITIALIZING', 'INPUT_STATE',
'INPUT_STATE_PARAMS', 'INPUT_STATES',
'INPUTS_DIM', 'INTEGRATION_TYPE', 'INTEGRATOR_FUNCTION', 'INTEGRATOR_FUNCTION', 'INTEGRATOR_FUNCTION_TYPE',
'INTEGRATOR_MECHANISM', 'INTERCEPT', 'INTERNAL', 'K_VALUE', 'kpMechanismControlAllocationsLogEntry',
'kpMechanismExecutedLogEntry', 'kpMechanismInputLogEntry', 'kpMechanismOutputLogEntry', 'kpMechanismTimeScaleLogEntry',
Expand Down Expand Up @@ -73,7 +75,7 @@
'OUTPUT_STATE', 'OUTPUT_STATE_PARAMS', 'OUTPUT_STATES', 'OUTPUT_TYPE', 'OWNER', 'PARAM_CLASS_DEFAULTS',
'PARAM_INSTANCE_DEFAULTS', 'PARAMETER_STATE', 'PARAMETER_STATE_PARAMS', 'PARAMETER_STATES', 'PARAMS',
'PARAMS_CURRENT', 'PATHWAY', 'PATHWAY_PROJECTION', 'PEARSON', 'PREDICTION_MECHANISM', 'PREDICTION_MECHANISM_OUTPUT',
'PREDICTION_MECHANISM_PARAMS', 'PREDICTION_MECHANISM_TYPE', 'PREFS_ARG', 'PRIMARY', 'PROB', 'PROCESS',
'PREDICTION_MECHANISM_PARAMS', 'PREDICTION_MECHANISM_TYPE', 'PREFS_ARG', 'PRIMARY', 'PROB', 'PROCESS', 'PROCESSING',
'PROCESS_INIT', 'PROCESSES', 'PROCESSES_DIM', 'PROCESSING_MECHANISM', 'PRODUCT', 'PROJECTION',
'PROJECTION_PARAMS', 'PROJECTION_SENDER', 'PROJECTION_SENDER_VALUE', 'PROJECTION_TYPE', 'PROJECTIONS',
'QUOTIENT', 'RANDOM_CONNECTIVITY_MATRIX', 'RATE', 'RATIO', 'RECEIVER', 'RECURRENT_TRANSFER_MECHANISM',
Expand All @@ -84,8 +86,8 @@
'STATE_TYPE', 'STATE_VALUE', 'STATES', 'SUBTRACTION', 'SUM', 'SYSTEM', 'SYSTEM_DEFAULT_CONTROLLER',
'SYSTEM_INIT', 'TARGET', 'TERMINAL', 'THRESHOLD', 'TIME_SCALE', 'TIME_STEP_SIZE', 'TIME_STEPS_DIM',
'TRANSFER_FUNCTION_TYPE', 'TRANSFER_MECHANISM', 'TRIALS_DIM', 'UNCHANGED', 'UNIFORM_DIST_FUNCTION',
'USER_DEFINED_FUNCTION', 'USER_DEFINED_FUNCTION_TYPE', 'USER_PARAMS', 'UTILITY_INTEGRATOR_FUNCTION', 'VALIDATE',
'VALUE', 'VALUE_FUNCTION', 'VARIABLE', 'VARIANCE', 'VECTOR',
'USER_DEFINED_FUNCTION', 'USER_DEFINED_FUNCTION_TYPE', 'USER_PARAMS', 'UTILITY_INTEGRATOR_FUNCTION',
'VALIDATE', 'VALIDATION', 'VALUE', 'VALUE_ASSIGNMENT', 'VALUE_FUNCTION', 'VARIABLE', 'VARIANCE', 'VECTOR',
'WALD_DIST_FUNCTION', 'WEIGHT', 'WEIGHTS',
]

Expand Down Expand Up @@ -382,6 +384,14 @@ def _is_metric(metric):
kwContext = 'Context'
kwValue = 'Value'
LOG_ENTRIES = 'LOG_ENTRIES'
INITIALIZATION = 'INITIALIZATION'
VALIDATION = 'VALIDATION'
EXECUTION = 'EXECUTION'
PROCESSING = 'PROCESSING'
VALUE_ASSIGNMENT = 'VALUE_ASSIGNMENT'
FINAL = 'FINAL'


#endregion

#region ----------------------------------------------- UTILITIES ----------------------------------------------------
Expand Down Expand Up @@ -577,7 +587,7 @@ def _is_metric(metric):
HARD_CLAMP = "hard_clamp"
LEARNING = 'LEARNING'
LEARNING_RATE = "learning_rate"
CONTROL = 'control'
CONTROL = 'CONTROL'
GATING = 'gating'
kwProjections = "projections"
kwProcessDefaultProjectionFunction = "Default Projection Function"
Expand Down
Loading