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

Refactor/project/learning vs executing #605

Merged
merged 74 commits into from
Dec 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3276e28
• System
jdcpni Nov 30, 2017
6908d7f
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Nov 30, 2017
461e18f
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 4, 2017
bd5f9a0
• Log
jdcpni Dec 5, 2017
04ffdac
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 5, 2017
2d6409b
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 5, 2017
7b7e277
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 7, 2017
cda732e
-
jdcpni Dec 7, 2017
9d204af
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 10, 2017
a6449c1
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 10, 2017
5603fa6
-
jdcpni Dec 10, 2017
21332d7
-
jdcpni Dec 10, 2017
335ab58
-
jdcpni Dec 10, 2017
51c0aed
-
jdcpni Dec 10, 2017
ab5144b
-
jdcpni Dec 10, 2017
6d58251
-
jdcpni Dec 10, 2017
5516f6d
-
jdcpni Dec 10, 2017
1dec9aa
-
jdcpni Dec 10, 2017
3e4766d
-
jdcpni Dec 10, 2017
e1ffdec
-
jdcpni Dec 10, 2017
0eec811
-
jdcpni Dec 10, 2017
17b487c
-
jdcpni Dec 10, 2017
3f438f5
Merge branch 'feat/Log/clean_up' into devel
jdcpni Dec 10, 2017
0561216
-
jdcpni Dec 10, 2017
c76a3a8
• Log
jdcpni Dec 10, 2017
43f9a0d
• Log
jdcpni Dec 10, 2017
17eaa3a
-
jdcpni Dec 11, 2017
f495751
-
jdcpni Dec 11, 2017
bb4fecd
-
jdcpni Dec 11, 2017
9579899
-
jdcpni Dec 11, 2017
aa679dd
-
jdcpni Dec 11, 2017
d7024ae
-
jdcpni Dec 11, 2017
73a8013
-
jdcpni Dec 11, 2017
6416865
• Log
jdcpni Dec 11, 2017
e200f88
• Log
jdcpni Dec 11, 2017
e5a3881
• Log
jdcpni Dec 11, 2017
5065c1d
• Log
jdcpni Dec 11, 2017
36c0988
• Log
jdcpni Dec 11, 2017
fe14d1e
• Log
jdcpni Dec 11, 2017
3a29540
• Log
jdcpni Dec 11, 2017
de216a8
Merge branch 'feat/Log/add_entry' into devel
jdcpni Dec 11, 2017
4dacd4d
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 11, 2017
5f043a0
-
jdcpni Dec 12, 2017
2d6b0a2
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 12, 2017
d2e5167
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 12, 2017
7baddea
• Component
jdcpni Dec 12, 2017
5e959fb
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 13, 2017
979a9ea
• Log
jdcpni Dec 13, 2017
5a5d15d
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 13, 2017
47cd066
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 13, 2017
7bc2742
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 14, 2017
7e0c5d3
Merge branch 'devel' of https://github.com/PrincetonUniversity/PsyNeu…
jdcpni Dec 14, 2017
dd84cad
• Mechanism
jdcpni Dec 14, 2017
1dab5f8
• Mechanism
jdcpni Dec 14, 2017
d22e5b8
• Log
jdcpni Dec 15, 2017
38ffc9d
-
jdcpni Dec 15, 2017
5132edb
• Log
jdcpni Dec 16, 2017
f77dcb4
• Log
jdcpni Dec 16, 2017
6e60b06
• Projection
jdcpni Dec 16, 2017
ef3db09
• Projection
jdcpni Dec 16, 2017
523d109
• Projection
jdcpni Dec 17, 2017
8d8be2f
-
jdcpni Dec 17, 2017
48a0614
-
jdcpni Dec 17, 2017
a56e9c1
• Log
jdcpni Dec 17, 2017
a76c57d
• Project:
jdcpni Dec 17, 2017
5562085
-
jdcpni Dec 17, 2017
9394d30
-
jdcpni Dec 17, 2017
a8119fc
-
jdcpni Dec 17, 2017
bf743e4
-
jdcpni Dec 17, 2017
8586828
-
jdcpni Dec 17, 2017
bd0abf4
-
jdcpni Dec 17, 2017
b096c81
-
jdcpni Dec 17, 2017
467c54f
-
jdcpni Dec 17, 2017
2709142
-
jdcpni Dec 17, 2017
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
20 changes: 17 additions & 3 deletions psyneulink/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class `UserList <https://docs.python.org/3.6/library/collections.html?highlight=
from psyneulink.globals.registry import register_category
from psyneulink.globals.keywords import COMMAND_LINE, DEFERRED_INITIALIZATION, DEFERRED_DEFAULT_NAME, COMPONENT_INIT, \
CONTEXT, CONTROL, CONTROL_PROJECTION, FUNCTION, FUNCTION_CHECK_ARGS, FUNCTION_PARAMS, INITIALIZING, LOG_ENTRIES, \
INIT_FULL_EXECUTE_METHOD, INPUT_STATES, LEARNING, LEARNING_PROJECTION, MAPPING_PROJECTION, NAME, OUTPUT_STATES, \
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, LogCondition
Expand Down Expand Up @@ -841,14 +842,12 @@ def __init__(self,
self.prefs = ComponentPreferenceSet(owner=self, prefs=prefs, context=context)

# ASSIGN LOG

from psyneulink.globals.log import Log
self.log = Log(owner=self)
self.recording = False
# Used by run to store return value of execute
self.results = []


# ENFORCE REQUIRED CLASS DEFAULTS

# All subclasses must implement self.ClassDefaults.variable
Expand Down Expand Up @@ -2841,6 +2840,21 @@ def runtimeParamStickyAssignmentPref(self):
def runtimeParamStickyAssignmentPref(self, setting):
self.prefs.runtimeParamStickyAssignmentPref = setting

@property
def log(self):
try:
return self._log
except AttributeError:
if self.init_status is InitStatus.DEFERRED_INITIALIZATION:
raise ComponentError("Initialization of {} is deferred; try assigning {} after it is complete".
format(self.name, 'log'))
else:
raise AttributeError

@log.setter
def log(self, log):
self._log = log

@property
def loggable_items(self):
"""Diciontary of items that can be logged in the Component's `log <Component.log>` and their current `LogCondition`.
Expand Down
19 changes: 10 additions & 9 deletions psyneulink/components/functions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
EXPONENTIAL_DIST_FUNCTION, EXPONENTIAL_FUNCTION, EXPONENTS, FHN_INTEGRATOR_FUNCTION, FULL_CONNECTIVITY_MATRIX, \
FUNCTION, FUNCTION_OUTPUT_TYPE, FUNCTION_OUTPUT_TYPE_CONVERSION, FUNCTION_PARAMS, GAIN, GAMMA_DIST_FUNCTION, \
HEBBIAN_FUNCTION, HIGH, HOLLOW_MATRIX, IDENTITY_MATRIX, INCREMENT, INITIALIZER, \
INITIALIZING, INPUT_STATES, INTEGRATOR_FUNCTION, INTEGRATOR_FUNCTION_TYPE, INTERCEPT, LEARNING_FUNCTION_TYPE, \
INITIALIZING, INPUT_STATES, INTEGRATOR_FUNCTION, INTEGRATOR_FUNCTION_TYPE, INTERCEPT, \
LEARNING, LEARNING_FUNCTION_TYPE, \
LEARNING_RATE, LINEAR_COMBINATION_FUNCTION, LINEAR_FUNCTION, LINEAR_MATRIX_FUNCTION, LOGISTIC_FUNCTION, LOW, MATRIX, \
MATRIX_KEYWORD_NAMES, MATRIX_KEYWORD_VALUES, MAX_INDICATOR, MAX_VAL, NOISE, NORMAL_DIST_FUNCTION, \
OBJECTIVE_FUNCTION_TYPE, OFFSET, OPERATION, ORNSTEIN_UHLENBECK_INTEGRATOR_FUNCTION, OUTPUT_STATES, OUTPUT_TYPE, \
Expand Down Expand Up @@ -1557,14 +1558,14 @@ def _validate_params(self, request_set, target_set=None, context=None):

if WEIGHTS in target_set and target_set[WEIGHTS] is not None:
target_set[WEIGHTS] = np.atleast_2d(target_set[WEIGHTS]).reshape(-1, 1)
if EXECUTING in context:
if any(c in context for c in {EXECUTING, LEARNING}):
if len(target_set[WEIGHTS]) != len(self.instance_defaults.variable):
raise FunctionError("Number of weights ({0}) is not equal to number of items in variable ({1})".
format(len(target_set[WEIGHTS]), len(self.instance_defaults.variable.shape)))

if EXPONENTS in target_set and target_set[EXPONENTS] is not None:
target_set[EXPONENTS] = np.atleast_2d(target_set[EXPONENTS]).reshape(-1, 1)
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if len(target_set[EXPONENTS]) != len(self.instance_defaults.variable):
raise FunctionError("Number of exponents ({0}) does not equal number of items in variable ({1})".
format(len(target_set[EXPONENTS]), len(self.instance_defaults.variable.shape)))
Expand All @@ -1578,7 +1579,7 @@ def _validate_params(self, request_set, target_set=None, context=None):
else:
raise FunctionError("{} param of {} ({}) must be a scalar or an np.ndarray".
format(SCALE, self.name, scale))
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if (isinstance(scale, np.ndarray) and
(scale.size != self.instance_defaults.variable.size or
scale.shape != self.instance_defaults.variable.shape)):
Expand All @@ -1596,7 +1597,7 @@ def _validate_params(self, request_set, target_set=None, context=None):
else:
raise FunctionError("{} param of {} ({}) must be a scalar or an np.ndarray".
format(OFFSET, self.name, offset))
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if (isinstance(offset, np.ndarray) and
(offset.size != self.instance_defaults.variable.size or
offset.shape != self.instance_defaults.variable.shape)):
Expand Down Expand Up @@ -1996,14 +1997,14 @@ def _validate_params(self, request_set, target_set=None, context=None):

if WEIGHTS in target_set and target_set[WEIGHTS] is not None:
target_set[WEIGHTS] = np.atleast_2d(target_set[WEIGHTS]).reshape(-1, 1)
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if len(target_set[WEIGHTS]) != len(self.instance_defaults.variable):
raise FunctionError("Number of weights ({0}) is not equal to number of items in variable ({1})".
format(len(target_set[WEIGHTS]), len(self.instance_defaults.variable.shape)))

if EXPONENTS in target_set and target_set[EXPONENTS] is not None:
target_set[EXPONENTS] = np.atleast_2d(target_set[EXPONENTS]).reshape(-1, 1)
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if len(target_set[EXPONENTS]) != len(self.instance_defaults.variable):
raise FunctionError("Number of exponents ({0}) does not equal number of items in variable ({1})".
format(len(target_set[EXPONENTS]), len(self.instance_defaults.variable.shape)))
Expand All @@ -2017,7 +2018,7 @@ def _validate_params(self, request_set, target_set=None, context=None):
else:
raise FunctionError("{} param of {} ({}) must be a scalar or an np.ndarray".
format(SCALE, self.name, scale))
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if (isinstance(scale, np.ndarray) and
(scale.size != self.instance_defaults.variable.size or
scale.shape != self.instance_defaults.variable.shape)):
Expand All @@ -2035,7 +2036,7 @@ def _validate_params(self, request_set, target_set=None, context=None):
else:
raise FunctionError("{} param of {} ({}) must be a scalar or an np.ndarray".
format(OFFSET, self.name, offset))
if EXECUTING in context:
if (c in context for c in {EXECUTING, LEARNING}):
if (isinstance(offset, np.ndarray) and
(offset.size != self.instance_defaults.variable.size or
offset.shape != self.instance_defaults.variable.shape)):
Expand Down
7 changes: 4 additions & 3 deletions psyneulink/components/mechanisms/mechanism.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ class `UserList <https://docs.python.org/3.6/library/collections.html?highlight=
from psyneulink.components.states.parameterstate import ParameterState
from psyneulink.components.states.state import ADD_STATES, _parse_state_spec
from psyneulink.globals.defaults import timeScaleSystemDefault
from psyneulink.globals.keywords import CHANGED, COMMAND_LINE, EVC_SIMULATION, EXECUTING, FUNCTION_PARAMS, INITIALIZING, INIT_FUNCTION_METHOD_ONLY, INIT__EXECUTE__METHOD_ONLY, INPUT_STATES, INPUT_STATE_PARAMS, MECHANISM_TIME_SCALE, MONITOR_FOR_CONTROL, MONITOR_FOR_LEARNING, NO_CONTEXT, OUTPUT_STATES, OUTPUT_STATE_PARAMS, PARAMETER_STATES, PARAMETER_STATE_PARAMS, PROCESS_INIT, REFERENCE_VALUE, SEPARATOR_BAR, SET_ATTRIBUTE, SYSTEM_INIT, TIME_SCALE, UNCHANGED, VALIDATE, VALUE, VARIABLE, kwMechanismComponentCategory, kwMechanismExecuteFunction
from psyneulink.globals.keywords import CHANGED, COMMAND_LINE, EVC_SIMULATION, EXECUTING, FUNCTION_PARAMS, INITIALIZING, INIT_FUNCTION_METHOD_ONLY, INIT__EXECUTE__METHOD_ONLY, INPUT_STATES, INPUT_STATE_PARAMS, LEARNING, MECHANISM_TIME_SCALE, MONITOR_FOR_CONTROL, MONITOR_FOR_LEARNING, NO_CONTEXT, OUTPUT_STATES, OUTPUT_STATE_PARAMS, PARAMETER_STATES, PARAMETER_STATE_PARAMS, PROCESS_INIT, REFERENCE_VALUE, SEPARATOR_BAR, SET_ATTRIBUTE, SYSTEM_INIT, TIME_SCALE, UNCHANGED, VALIDATE, VALUE, VARIABLE, kwMechanismComponentCategory, kwMechanismExecuteFunction
from psyneulink.globals.preferences.preferenceset import PreferenceLevel
from psyneulink.globals.registry import register_category
from psyneulink.globals.utilities import ContentAddressableList, append_type_to_name, convert_to_np_array, iscompatible, kwCompatibilityNumeric
Expand Down Expand Up @@ -1986,7 +1986,7 @@ def execute(self,
# Executing or simulating Process or System, get input by updating input_states

if (input is None
and (EXECUTING in context or EVC_SIMULATION in context)
and (c in context for c in {EXECUTING, LEARNING, EVC_SIMULATION})
and (self.input_state.path_afferents != [])):
variable = self._update_variable(self._update_input_states(runtime_params=runtime_params,
time_scale=time_scale,
Expand Down Expand Up @@ -2049,7 +2049,8 @@ def execute(self,
#endregion

#region REPORT EXECUTION
if self.prefs.reportOutputPref and context and EXECUTING in context:
# if self.prefs.reportOutputPref and context and EXECUTING in context:
if self.prefs.reportOutputPref and context and (c in context for c in {EXECUTING, LEARNING}):
self._report_mechanism_execution(self.input_values, self.user_params, self.output_state.value)
#endregion

Expand Down
7 changes: 2 additions & 5 deletions psyneulink/components/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2153,8 +2153,7 @@ def execute(
mech._execution_id = self._execution_id

# Report output if reporting preference is on and this is not an initialization run
report_output = self.prefs.reportOutputPref and context and EXECUTING in context

report_output = self.prefs.reportOutputPref and context and (c in context for c in {EXECUTING, LEARNING})

# FIX: CONSOLIDATE/REARRANGE _assign_input_values, _check_args, AND ASSIGNMENT OF input TO variable
# FIX: (SO THAT assign_input_value DOESN'T HAVE TO RETURN input
Expand Down Expand Up @@ -2278,9 +2277,7 @@ def _execute_learning(self, target=None, context=None):
# Call parameter_state.update with LEARNING in context to update LearningSignals
# 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 + ' ')
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
8 changes: 4 additions & 4 deletions psyneulink/components/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,9 @@ def execute(self,
for projection in state.all_afferents:
projection.sender.owner._execution_id = self._execution_id

self._report_system_output = self.prefs.reportOutputPref and context and EXECUTING in context
self._report_system_output = self.prefs.reportOutputPref and context and (c in context for c in {EXECUTING,
LEARNING})

if self._report_system_output:
self._report_process_output = any(process.reportOutputPref for process in self.processes)

Expand Down Expand Up @@ -2539,9 +2541,7 @@ def execute(self,

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


Expand Down
Loading