Skip to content

Commit

Permalink
Names/log/set log conditions (#590)
Browse files Browse the repository at this point in the history
* • System
  - show_graph():
    fixed bug producing empty image for graphs with just one Mechanism
    added auto-recurrent projections

* • Log
  - added numpy_array output method

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* -

* • Log
  - fixed bugs preventing logging during INITIALIZATION

* • Log
  - fixed bugs preventing logging during INITIALIZATION

* -

* -

* -

* -

* -

* • Log
  - logged_item, print_entries:  corrected to use 'value' rather than owner's name in reports

* • Log
  - logged_item, print_entries:  corrected to use 'value' rather than owner's name in reports

• Tests
  test_log:  added test_log_initialization

* • Log
  - _alias_owner_name:  added to used 'value' rather than owner's name in reports
  - nparray: bug fix to handle None values

• Tests
  test_log:  added test_log_initialization

* • Log
  - log_value: added

• Tests
  - test_multilayer: added test of log_value

* • Log
  - log_value: implemented
  - logged_item, print_entries:  corrected to use 'value' rather than owner's name in reports

• Tests
  - test_multilayer: added test of log_value

* • Log
  - log_value: implemented
  - logged_item, print_entries:  corrected to use 'value' rather than owner's name in reports

• Tests
  - test_multilayer: added test of log_value

* Merge branch 'feat/Log/add_entry' into devel

# Conflicts:
#	Scripts/Scratch Pad.py
#	psyneulink/globals/log.py

* Merge branch 'feat/Log/add_entry' into devel

# Conflicts:
#	Scripts/Scratch Pad.py
#	psyneulink/globals/log.py

* Merge branch 'feat/Log/add_entry' into devel

# Conflicts:
#	Scripts/Scratch Pad.py
#	psyneulink/globals/log.py

* Merge branch 'feat/Log/add_entry' into devel

# Conflicts:
#	Scripts/Scratch Pad.py
#	psyneulink/globals/log.py

* • Log
  - print_entries(): fixed field widths

* • Log
  - print_entries(): fixed field widths

* • Log
  - print_entries(): fixed field widths

* • Log
  - clear_entries: option added for deleting entry or just the data

* • Log
  - LogLevels -> LogConditions
  - set_log_levels -> set_log_conditions

* • Log
  - LogLevels -> LogConditions
  - set_log_levels -> set_log_conditions

* • Log
  - LogLevels -> LogConditions
  - set_log_levels -> set_log_conditions

* -

* -

* -
  • Loading branch information
jdcpni authored Dec 12, 2017
1 parent 8387be6 commit a245271
Show file tree
Hide file tree
Showing 16 changed files with 355 additions and 217 deletions.
6 changes: 3 additions & 3 deletions .idea/runConfigurations/Make_HTML.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Scripts/Examples/Multilayer-Learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def show_target(system):
)

# Log Middle_Weights of MappingProjection to Hidden_Layer_2
# Hidden_Layer_2.log_items('Middle Weights')
Middle_Weights.log_items('matrix')
# Hidden_Layer_2.set_log_conditions('Middle Weights')
Middle_Weights.set_log_conditions('matrix')

mySystem.reportOutputPref = True
# Shows graph will full information:
Expand Down
47 changes: 24 additions & 23 deletions Scripts/Scratch Pad.py
Original file line number Diff line number Diff line change
Expand Up @@ -2237,9 +2237,9 @@ def __init__(self, error_value):
# assert PJ.loggable_items == {'matrix': 'OFF',
# 'value': 'OFF'}
#
# T_1.log_items(pnl.NOISE)
# T_1.log_items(pnl.RESULTS)
# PJ.log_items(pnl.MATRIX)
# T_1.set_log_conditions(pnl.NOISE)
# T_1.set_log_conditions(pnl.RESULTS)
# PJ.set_log_conditions(pnl.MATRIX)
#
# assert T_1.loggable_items == {'InputState-0': 'OFF',
# 'slope': 'OFF',
Expand Down Expand Up @@ -2312,7 +2312,7 @@ def __init__(self, error_value):
#
# def test_log_initialization():
# T = pnl.TransferMechanism(
# prefs={pnl.LOG_PREF: pnl.PreferenceEntry(pnl.LogLevel.INITIALIZATION, pnl.PreferenceLevel.INSTANCE)}
# prefs={pnl.LOG_PREF: pnl.PreferenceEntry(pnl.LogCondition.INITIALIZATION, pnl.PreferenceLevel.INSTANCE)}
# )
# print(T.logged_items)
# print(T.log.nparray())
Expand All @@ -2325,12 +2325,12 @@ def __init__(self, error_value):

#region TEST LOG MISC @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# print("TEST LOG MISC")

#
# T = pnl.TransferMechanism()
#
# P = pnl.Process(pathway=[T])
# S = pnl.System(processes=P)
# T.log_items(pnl.RESULTS)
# T.set_log_conditions(pnl.RESULTS)
# S.execute()
# S.execute()
# S.execute()
Expand All @@ -2342,13 +2342,13 @@ def __init__(self, error_value):
# assert True

# T = pnl.TransferMechanism(size=3, name='My_T'
# # prefs={pnl.LOG_PREF:pnl.PreferenceEntry(pnl.LogLevel.INITIALIZATION, pnl.PreferenceLevel.INSTANCE)}
# # prefs={pnl.LOG_PREF:pnl.PreferenceEntry(pnl.LogCondition.INITIALIZATION, pnl.PreferenceLevel.INSTANCE)}
# )
# T2 = pnl.TransferMechanism(size=4, input_states=[T])
# # T.parameter_states['slope'].logPref=pnl.PreferenceEntry(pnl.LogLevel.EXECUTION, pnl.PreferenceLevel.INSTANCE)
# # T.parameter_states['slope'].logPref=pnl.PreferenceEntry(pnl.LogCondition.EXECUTION, pnl.PreferenceLevel.INSTANCE)
# print(T.loggable_items)
# T.log_items(('noise'))
# T.log_items('RESULTS')
# T.set_log_conditions(('noise'))
# T.set_log_conditions('RESULTS')
# print(T.loggable_items)
#
# T.execute()
Expand All @@ -2369,9 +2369,9 @@ def __init__(self, error_value):
# PJ = T2.path_afferents[0]
# print(PJ.loggable_items)
#
# T1.log_items('noise')
# T1.log_items('RESULTS')
# PJ.log_items('matrix')
# T1.set_log_conditions('noise')
# T1.set_log_conditions('RESULTS')
# PJ.set_log_conditions('matrix')
#
# # Execute each Process twice (to generate some values in the logs):
# PS.execute()
Expand Down Expand Up @@ -2403,9 +2403,9 @@ def __init__(self, error_value):
# print(my_mech_B.loggable_items) # doctest: +SKIP
# print(proj_A_to_B.loggable_items) # doctest: +SKIP
#
# my_mech_A.log_items('noise')
# my_mech_A.log_items('RESULTS')
# proj_A_to_B.log_items(pnl.MATRIX)
# my_mech_A.set_log_conditions('noise')
# my_mech_A.set_log_conditions('RESULTS')
# proj_A_to_B.set_log_conditions(pnl.MATRIX)
#
#
# my_process.execute()
Expand Down Expand Up @@ -2517,7 +2517,7 @@ def test_multilayer():
},
)

Middle_Weights.log_items(('matrix', pnl.EXECUTION))
Middle_Weights.set_log_conditions(('matrix', pnl.EXECUTION))

stim_list = {Input_Layer: [[-1, 30]]}
target_list = {Output_Layer: [[0, 0, 1]]}
Expand Down Expand Up @@ -2673,14 +2673,16 @@ def show_target():
atol=1e-08,
err_msg='Failed on test of logged values')

Middle_Weights.log.print_entries()
Middle_Weights.log.print_entries(width=200, display=[pnl.TIME, pnl.CONTEXT, pnl.VALUE])

# Test Programatic logging
# Test Programatic logging
Hidden_Layer_2.log.log_value(pnl.VALUE)
Hidden_Layer_2.log.log_values(pnl.VALUE)

log_val = Hidden_Layer_2.log.nparray(header=False)
expected_log_val = np.array(
[
[[0]],
[[10]],
[[0]],
[[[0.8565238418942037, 0.8601053239957609, 0.8662098921116546, 0.8746933736954071]]]
], dtype=object
Expand All @@ -2698,7 +2700,7 @@ def show_target():

# Clear log and test with logging of weights set to LEARNING for another 5 trials of learning
Middle_Weights.log.clear_entries(entries=None, confirm=False)
Middle_Weights.log_items(('matrix', pnl.LEARNING))
Middle_Weights.set_log_conditions(('matrix', pnl.LEARNING))
s.run(
num_trials=5,
inputs=stim_list,
Expand Down Expand Up @@ -2749,10 +2751,9 @@ def show_target():
err_msg='Failed on test of logged values')
test_multilayer()

#endregion
# endregion

#region TEST OVER-WRITING OF LOG @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#

# class a:
#
Expand Down
38 changes: 26 additions & 12 deletions psyneulink/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@
* **log** - the `log <Component.log>` attribute contains the Component's `Log`, that can be used to record its
`value <Component.value>`, as well as that of Components that belong to it, during initialization, validation,
execution and learning. It also has three convenience methods -- `loggable_items <Log.loggable_items>`, `log_items
<Log.log_items>`, and `logged_items <Log.logged_items>` -- that provide access to the corresponding methods of its
Log, used to identify, configure and track items for logging.
execution and learning. It also has four convenience methods -- `loggable_items <Log.loggable_items>`, `set_log_conditions
<Log.set_log_conditions>`, `log_values <Log.log_values>` and `logged_items <Log.logged_items>` -- that provide access to the
corresponding methods of its Log, used to identify, configure and track items for logging.
..
.. _Component_Name:
Expand Down Expand Up @@ -361,7 +361,7 @@ class `UserList <https://docs.python.org/3.6/library/collections.html?highlight=
INIT_FULL_EXECUTE_METHOD, INPUT_STATES, LEARNING, LEARNING_PROJECTION, MAPPING_PROJECTION, NAME, OUTPUT_STATES, \
PARAMS, PARAMS_CURRENT, PARAM_CLASS_DEFAULTS, PARAM_INSTANCE_DEFAULTS, PREFS_ARG, SEPARATOR_BAR, SET_ATTRIBUTE, \
SIZE, USER_PARAMS, VALUE, VARIABLE, MODULATORY_SPEC_KEYWORDS, kwComponentCategory
# from psyneulink.globals.log import Log, LogLevel
# from psyneulink.globals.log import Log, LogCondition
from psyneulink.globals.preferences.componentpreferenceset import ComponentPreferenceSet, kpVerbosePref
from psyneulink.globals.preferences.preferenceset import PreferenceEntry, PreferenceLevel, PreferenceSet
from psyneulink.globals.utilities import ContentAddressableList, ReadOnlyOrderedDict, convert_all_elements_to_np_array, convert_to_np_array, is_matrix, is_same_function_spec, iscompatible, kwCompatibilityLength
Expand Down Expand Up @@ -2834,28 +2834,42 @@ def runtimeParamStickyAssignmentPref(self, setting):

@property
def loggable_items(self):
"""Diciontary of items that can be logged in the Component's `log <Component.log>` and their current `LogLevel`.
"""Diciontary of items that can be logged in the Component's `log <Component.log>` and their current `LogCondition`.
This is a convenience method that calls the `loggable_items <Log.loggable_items>` property of the Component's
`log <Component.log>`.
"""
return self.log.loggable_items

from psyneulink.globals.log import LogLevel
def log_items(self, items, log_level=LogLevel.EXECUTION):
from psyneulink.globals.log import LogCondition
def set_log_conditions(self, items, log_condition=LogCondition.EXECUTION):
"""
log_items( \
set_log_conditions( \
items \
log_level=EXECUTION \
log_condition=EXECUTION \
)
Specifies items to be logged. This is a convenience method that calls the `log_items <Log.logged_items>` method
Specifies items to be logged; these must be be `loggable_items <Component.loggable_items>` of the Component's
`log <Component.log>`. This is a convenience method that calls the `set_log_conditions <Log.set_log_conditions>` method
of the Component's `log <Component.log>`.
"""
self.log.log_items(items=items, log_level=log_level)
self.log.set_log_conditions(items=items, log_condition=log_condition)

def log_values(self, entries):
"""
log_values( \
entries \
)
Specifies items to be logged; ; these must be be `loggable_items <Component.loggable_items>` of the Component's
`log <Component.log>`. This is a convenience method that calls the `log_values <Log.log_values>` method
of the Component's `log <Component.log>`.
"""
self.log.log_values(entries)


@property
def logged_items(self):
"""Dictionary of all items that have entries in the log, and their currently assigned `LogLevel`\\s
"""Dictionary of all items that have entries in the log, and their currently assigned `LogCondition`\\s
This is a convenience method that calls the `logged_items <Log.logged_items>` property of the Component's
`log <Component.log>`.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@
<OutputState.value>` of each of its `OutputStates <OutputState>`, and to the 1st item of the Mechanism's
`output_values <TransferMechanism.output_values>` attribute.
COMMENT:
.. _Transfer_Examples:
Examples
--------
EXAMPLES HERE
COMMENT
.. _Transfer_Class_Reference:
Class Reference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
from psyneulink.components.component import InitStatus
from psyneulink.components.projections.projection import Projection_Base
from psyneulink.globals.keywords import EXECUTING, INITIALIZING, MODULATORY_PROJECTION, NAME, kwAssign
from psyneulink.globals.log import LogEntry, LogLevel
from psyneulink.globals.log import LogEntry, LogCondition


__all__ = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
from psyneulink.components.projections.projection import ProjectionError, Projection_Base, projection_keywords
from psyneulink.components.states.outputstate import OutputState
from psyneulink.globals.keywords import AUTO_ASSIGN_MATRIX, CHANGED, DEFAULT_MATRIX, EXECUTING, FULL_CONNECTIVITY_MATRIX, FUNCTION, FUNCTION_PARAMS, HOLLOW_MATRIX, IDENTITY_MATRIX, INITIALIZING, INPUT_STATE, LEARNING, LEARNING_PROJECTION, MAPPING_PROJECTION, MATRIX, OUTPUT_STATE, PROCESS_INPUT_STATE, PROJECTION_SENDER, PROJECTION_SENDER_VALUE, SYSTEM_INPUT_STATE, VALUE, kwAssign
from psyneulink.globals.log import LogEntry, LogLevel
from psyneulink.globals.log import LogEntry, LogCondition
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set
from psyneulink.globals.preferences.preferenceset import PreferenceEntry, PreferenceLevel

Expand Down
2 changes: 1 addition & 1 deletion psyneulink/components/projections/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
from psyneulink.globals.registry import register_category
from psyneulink.globals.utilities import ContentAddressableList, is_matrix, is_numeric, iscompatible, type_match
from psyneulink.globals.utilities import ContentAddressableList, iscompatible, is_numeric, is_matrix, type_match
from psyneulink.globals.log import LogLevel, LogEntry, _get_log_context
from psyneulink.globals.log import LogCondition, LogEntry, _get_log_context

__all__ = [
'kpProjectionTimeScaleLogEntry', 'Projection_Base', 'projection_keywords', 'PROJECTION_SPEC_KEYWORDS', 'ProjectionError',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@
from psyneulink.components.states.state import State_Base
from psyneulink.globals.defaults import defaultControlAllocation
from psyneulink.globals.keywords import ALLOCATION_SAMPLES, AUTO, COMMAND_LINE, CONTROLLED_PARAMS, CONTROL_PROJECTION, CONTROL_SIGNAL, EXECUTING, FUNCTION, FUNCTION_PARAMS, INTERCEPT, OFF, ON, OUTPUT_STATE_PARAMS, PARAMETER_STATE, PARAMETER_STATES, PROJECTION_TYPE, RECEIVER, SEPARATOR_BAR, SLOPE, SUM, kwAssign
from psyneulink.globals.log import LogEntry, LogLevel
from psyneulink.globals.log import LogEntry, LogCondition
from psyneulink.globals.preferences.componentpreferenceset import is_pref_set
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.utilities import is_numeric, iscompatible, kwCompatibilityLength, kwCompatibilityNumeric, kwCompatibilityType
Expand Down Expand Up @@ -975,9 +975,9 @@ def update(self, params=None, time_scale=TimeScale.TRIAL, context=None):
context = context + SEPARATOR_BAR + self.name + kwAssign

# If context is consistent with log_pref:
if (log_pref is LogLevel.ALL_ASSIGNMENTS or
(log_pref is LogLevel.EXECUTION and EXECUTING in context) or
(log_pref is LogLevel.VALUE_ASSIGNMENT and (EXECUTING in context))):
if (log_pref is LogCondition.ALL_ASSIGNMENTS or
(log_pref is LogCondition.EXECUTION and EXECUTING in context) or
(log_pref is LogCondition.VALUE_ASSIGNMENT and (EXECUTING in context))):
# record info in log

# FIX: ENCODE ALL OF THIS AS 1D ARRAYS IN 2D PROJECTION VALUE, AND PASS TO .value FOR LOGGING
Expand Down
5 changes: 3 additions & 2 deletions psyneulink/components/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@
The `scheduler_processing` can be assigned in the **scheduler** argument of the System's constructor; if it is not
specified, a default `Scheduler` is created automatically. The `scheduler_learning` is always assigned automatically.
The System's Schedulers base the ordering of execution of its Components based on the order in which they are listed
in the `pathway <Process.pathway>`\\s of the `Proceses <Process>` used to construct the System, constrained by any
in the `pathway <Process.pathway>`\\s of the `Processes <Process>` used to construct the System, constrained by any
`Conditions <Condition>` that have been created for individual Components and assigned to the System's Schedulers (see
`Scheduler`, `Condition <Condition_Creation>`, `System_Execution_Processing`, and `System_Execution_Learning` for
additional details).
additional details). Both schedulers maintain a `Clock` that can be used to access their current `time
<Time_Overview>`.
.. _System_Control:
Expand Down
10 changes: 4 additions & 6 deletions psyneulink/globals/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
'INTEGRATOR_MECHANISM', 'INTERCEPT', 'INTERNAL', 'K_VALUE', 'kpMechanismControlAllocationsLogEntry',
'kpMechanismExecutedLogEntry', 'kpMechanismInputLogEntry', 'kpMechanismOutputLogEntry', 'kpMechanismTimeScaleLogEntry',
'kwAddInputState', 'kwAddOutputState', 'kwAggregate', 'kwAssign', 'kwComponentCategory', 'kwComponentPreferenceSet',
'kwContext', 'kwDefaultPreferenceSetOwner', 'kwInitialPoint', 'kwInstantiate', 'kwMechanismAdjustFunction',
'kwDefaultPreferenceSetOwner', 'kwInitialPoint', 'kwInstantiate', 'kwMechanismAdjustFunction',
'kwMechanismComponentCategory', 'kwMechanismConfidence', 'kwMechanismDefault', 'kwMechanismDefaultInputValue',
'kwMechanismDefaultParams', 'kwMechanismDuration', 'kwMechanismExecuteFunction', 'kwMechanismExecutionSequenceTemplate',
'kwMechanismInterrogateFunction', 'kwMechanismName', 'kwMechanismOutputValue', 'kwMechanismParams',
Expand All @@ -61,7 +61,7 @@
'kwPrefsOwner', 'kwProcessComponentCategory', 'kwProcessDefaultMechanism', 'kwProcessDefaultProjectionFunction',
'kwProcessExecute', 'kwProgressBarChar', 'kwProjectionComponentCategory', 'kwProjectionReceiver', 'kwProjections',
'kwReceiverArg', 'kwSeparator', 'kwStateComponentCategory', 'kwStateContext', 'kwStateName', 'kwStatePrefs',
'kwSystemComponentCategory', 'KWTA', 'kwThreshold', 'kwTime', 'kwValue', 'LCA', 'LEARNED_PARAM', 'LEARNING',
'kwSystemComponentCategory', 'KWTA', 'kwThreshold', 'LCA', 'LEARNED_PARAM', 'LEARNING',
'LEARNING_FUNCTION_TYPE', 'LEARNING_MECHANISM', 'LEARNING_PROJECTION', 'LEARNING_PROJECTION_PARAMS', 'LEARNING_RATE',
'LEARNING_SIGNAL', 'LEARNING_SIGNAL_SPECS', 'LEARNING_SIGNALS', 'LINEAR', 'LINEAR_COMBINATION_FUNCTION',
'LINEAR_FUNCTION', 'LINEAR_MATRIX_FUNCTION', 'LOG_ENTRIES', 'LOGISTIC_FUNCTION', 'LOW',
Expand All @@ -84,7 +84,7 @@
'SIMPLE', 'SIMPLE_INTEGRATOR_FUNCTION', 'SINGLETON', 'SIZE', 'SLOPE', 'SOFT_CLAMP', 'SOFTMAX_FUNCTION',
'STABILITY_FUNCTION', 'STANDARD_ARGS','STANDARD_DEVIATION', 'STANDARD_OUTPUT_STATES', 'STATE', 'STATE_PARAMS',
'STATE_TYPE', 'STATE_VALUE', 'STATES', 'SUBTRACTION', 'SUM', 'SYSTEM', 'SYSTEM_DEFAULT_CONTROLLER',
'SYSTEM_INIT', 'TARGET', 'TERMINAL', 'THRESHOLD', 'TIME_SCALE', 'TIME_STEP_SIZE', 'TIME_STEPS_DIM',
'SYSTEM_INIT', 'TARGET', 'TERMINAL', 'THRESHOLD', 'TIME', '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', 'VALIDATION', 'VALUE', 'VALUE_ASSIGNMENT', 'VALUE_FUNCTION', 'VARIABLE', 'VARIANCE', 'VECTOR',
Expand Down Expand Up @@ -378,9 +378,7 @@ def _is_metric(metric):

#region ------------------------------------------------ LOG ------------------------------------------------------

kwTime = 'Time'
kwContext = 'Context'
kwValue = 'Value'
TIME = 'time'
LOG_ENTRIES = 'LOG_ENTRIES'
INITIALIZATION = 'INITIALIZATION'
VALIDATION = 'VALIDATION'
Expand Down
Loading

0 comments on commit a245271

Please sign in to comment.