Skip to content

Commit

Permalink
Fix/component preference set/class preferences (#598)
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

* -

* • Component
  - moved value property to Component (from Mechanism, Projection and State)
    (left an override on ControlSignal that needs it for the getter)

* • Log
  - docstring: added hint about using call_before_trial and call_after_trial
    to log values

* • ComponentPreferenceSet
  - fixed bug in which instantiation of classPreferences assigned same
    PreferenceSet to class and object

* • ComponentPreferenceSet
  - fixed bug in which instantiation of classPreferences assigned same
    PreferenceSet to class and object

* • Log
  - docstring: reinstated test on log_value (now that pref bug is fixed)
  • Loading branch information
jdcpni authored Dec 14, 2017
1 parent d789c2e commit c486224
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
21 changes: 21 additions & 0 deletions .idea/runConfigurations/scratch.xml

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

5 changes: 2 additions & 3 deletions psyneulink/globals/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
COMMENT:
FIX: THIS EXAMPLE CAN'T CURRENTLY BE EXECUTED AS IT PERMANENTLY SETS THE LogPref FOR ALL TransferMechanism
COMMENT
>> import psyneulink as pnl
>> T = pnl.TransferMechanism(
>>> import psyneulink as pnl
>>> T = pnl.TransferMechanism(
... prefs={pnl.LOG_PREF: pnl.PreferenceEntry(pnl.LogCondition.INITIALIZATION, pnl.PreferenceLevel.INSTANCE)})
.. hint::
Expand All @@ -155,7 +155,6 @@
`MappingProjection` from the first to the second::
# Create a Process with two TransferMechanisms, and get a reference for the Projection created between them:
>>> import psyneulink as pnl
>>> my_mech_A = pnl.TransferMechanism(name='mech_A', size=2)
>>> my_mech_B = pnl.TransferMechanism(name='mech_B', size=3)
>>> my_process = pnl.Process(pathway=[my_mech_A, my_mech_B])
Expand Down
37 changes: 14 additions & 23 deletions psyneulink/globals/preferences/componentpreferenceset.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,24 +304,25 @@ def __init__(self,
if isinstance(owner_class.classPreferences, dict):
raise AttributeError
except AttributeError:
super(ComponentPreferenceSet, self).__init__(
owner=owner_class,
level=owner_class.classPreferenceLevel,
prefs=ComponentDefaultPrefDicts[owner_class.classPreferenceLevel],
name=name,
context=self)

# Instantiate PreferenceSet
super(ComponentPreferenceSet, self).__init__(owner=owner,
if inspect.isclass(owner):
# If this is a call to instantiate the classPreferences, no need to keep doing it! (infinite recursion)
pass
else:
# Instantiate the classPreferences
owner_class.classPreferences = ComponentPreferenceSet(
owner=owner_class,
level=owner_class.classPreferenceLevel,
prefs=prefs,
prefs=ComponentDefaultPrefDicts[owner_class.classPreferenceLevel],
name=name,
context=self)
# FIX: NECESSARY?? 5/30/16
# Instantiate PreferenceSet
super().__init__(owner=owner,
level=owner_class.classPreferenceLevel,
prefs=prefs,
name=name,
context=self)
self._level = level

#region verbose entry ----------------------------------------------------------------------------------------------

@property
def verbosePref(self):
"""Return setting of owner's verbosePref at level specified in its PreferenceEntry.level
Expand All @@ -340,8 +341,6 @@ def verbosePref(self, setting):
"""
self.set_preference(candidate_info=setting, pref_ivar_name=kpVerbosePref)

# region param_validation ----------------------------------------------------------------------------------------------

@property
def paramValidationPref(self):
"""Return setting of owner's param_validationPref at level specified in its PreferenceEntry.level
Expand All @@ -361,8 +360,6 @@ def paramValidationPref(self, setting):
"""
self.set_preference(setting,kpParamValidationPref)

#region reportOutput entry -----------------------------------------------------------------------------------------

@property
def reportOutputPref(self):
"""Return setting of owner's reportOutputPref at level specified in its PreferenceEntry.level
Expand All @@ -382,8 +379,6 @@ def reportOutputPref(self, setting):
"""
self.set_preference(candidate_info=setting, pref_ivar_name=kpReportOutputPref)

#region log entry --------------------------------------------------------------------------------------------------

@property
def logPref(self):
"""Return setting of owner's logPref at level specified in its PreferenceEntry.level
Expand Down Expand Up @@ -423,8 +418,6 @@ def logPref(self, setting):
self.set_preference(candidate_info=setting, pref_ivar_name=kpLogPref)


#region runtimeParamModulation -------------------------------------------------------------------------------------

@property
def runtimeParamModulationPref(self):
"""Returns owner's runtimeParamModulationPref
Expand All @@ -444,8 +437,6 @@ def runtimeParamModulationPref(self, setting):
"""
self.set_preference(candidate_info=setting, pref_ivar_name=kpRuntimeParamModulationPref)

#region runtimeParamStickyAssignment -------------------------------------------------------------------------------

@property
def runtimeParamStickyAssignmentPref(self):
"""Returns owner's runtimeParamStickyAssignmentPref
Expand Down
10 changes: 8 additions & 2 deletions psyneulink/globals/preferences/preferenceset.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PreferenceSet(object):
Description:
Each PreferenceSet object stores a set of preferences in its corresponding attributes
Every class in the Function hierarchy is assigned a PreferenceLevel:
Every class in the Component hierarchy is assigned a PreferenceLevel:
- System: reserved for the Component class
- Category: primary function subclasses (e.g., Process, Mechanism, State, Projection, Function)
- Type: Category subclasses (e.g., MappingProjection and ControlProjection subclasses of Projection, Function subclasses)
Expand Down Expand Up @@ -530,7 +530,13 @@ def set_preference(self, candidate_info, pref_ivar_name, default_entry=None):
#endregion

#region candidate_info is a PreferenceEntry
if isinstance(candidate_info, PreferenceEntry):
if (isinstance(candidate_info, PreferenceEntry)
or (isinstance(candidate_info, tuple) and len(candidate_info)==2)):
# elif len(candidate_info) != 2:
# raise PreferenceSetError("Preference specification tuple for {} ({}) must have only two entries "
# "(setting and level)".format(owner_name, candidate_info))
if not isinstance(candidate_info, PreferenceEntry):
candidate_info = PreferenceEntry(candidate_info[0], candidate_info[1])
setting_OK = self.validate_setting(candidate_info.setting, default_setting, pref_ivar_name)
level_OK = isinstance(candidate_info.level, PreferenceLevel)
if level_OK and setting_OK:
Expand Down

0 comments on commit c486224

Please sign in to comment.