Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
* devel: (140 commits)
  Increment version to 0.4.0
  add more input_state spec tests to handle currently known combinations for setting default_variable
  Refactor/mechanism/preprocess variable (#531)
  Docs/state and projections/docstring revs (#529)
  correct bug in _parse_arg_input_states where a non-list argument wouldn't be made into a list before processing
  change behavior of _parse_state_spec to not populate the state dict with a variable if it's a ClassDefault
  Fixed/state/ parse state spec/projection spec (#528)
  Refactor/distance metrics (#526)
  Docs/latex math (#525)
  Docs/intro materials (#524)
  Logo (#523)
  make self.name return unnamed .__class__ in case no name was set
  Docs/input state specs (#522)
  Fix/input state specs (#521)
  Fix/input state specs (#520)
  Fix/input state specs (#519)
  Fix/input state specs (#518)
  using new EULER option on the LCControlMechanism in GilzenratModel in order to match original model
  adding validation requiring integration_method to either be RK4 or EULER
  adding 'integration_method' to LCControlMechanism so that user can switch between euler and rk4 integration for the built-in FHN function
  ...
  • Loading branch information
kmantel committed Nov 14, 2017
2 parents 353e05b + 89652f4 commit 7da6769
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
# built documents.
#
# The short X.Y version.
version = u'0.3'
version = u'0.4'
# The full version, including alpha/beta/rc tags.
release = u'0.3.2'
release = u'0.4.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.3.4',
version='0.4.0',

description='A block modeling system for cognitive neuroscience',
long_description=long_description,
Expand Down
149 changes: 141 additions & 8 deletions tests/mechanisms/test_input_state_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
from psyneulink.components.mechanisms.mechanism import MechanismError
from psyneulink.components.mechanisms.processing.transfermechanism import TransferMechanism
from psyneulink.components.projections.pathway.mappingprojection import MappingProjection
from psyneulink.components.states.inputstate import InputState
from psyneulink.components.states.state import StateError
from psyneulink.globals.keywords import INPUT_STATES, MECHANISM, NAME, OUTPUT_STATES, PROJECTIONS, VARIABLE

mismatches_default_variable_error_text = 'not compatible with the specified default variable'
mismatches_size_error_text = 'not compatible with the default variable determined from size parameter'


class TestInputStateSpec:
# ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -35,11 +40,11 @@ def test_match_with_default_variable(self):
def test_mismatch_with_default_variable_error(self):

with pytest.raises(MechanismError) as error_text:
T = TransferMechanism(
TransferMechanism(
default_variable=[[0], [0]],
input_states=[[32, 24], 'HELLO']
)
assert "not compatible with the specified default variable" in str(error_text.value)
assert mismatches_default_variable_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 3
Expand Down Expand Up @@ -355,25 +360,25 @@ def test_dict_with_variable_matches_default_multiple_input_states(self):

def test_dict_with_variable_mismatches_default(self):
with pytest.raises(MechanismError) as error_text:
T = TransferMechanism(
TransferMechanism(
default_variable=[0],
input_states=[{NAME: 'FIRST', VARIABLE: [0, 0]}]
)
assert 'not compatible with the specified default variable' in str(error_text.value)
assert mismatches_default_variable_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 23

def test_dict_with_variable_mismatches_default_multiple_input_states(self):
with pytest.raises(MechanismError) as error_text:
T = TransferMechanism(
TransferMechanism(
default_variable=[[0], [0]],
input_states=[
{NAME: 'FIRST', VARIABLE: [0, 0]},
{NAME: 'SECOND', VARIABLE: [0]}
]
)
assert 'not compatible with the specified default variable' in str(error_text.value)
assert mismatches_default_variable_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 24
Expand All @@ -391,8 +396,136 @@ def test_dict_with_variable_matches_size(self):

def test_dict_with_variable_mismatches_size(self):
with pytest.raises(MechanismError) as error_text:
T = TransferMechanism(
TransferMechanism(
size=1,
input_states=[{NAME: 'FIRST', VARIABLE: [0, 0]}]
)
assert 'not compatible with the default variable determined from size parameter' in str(error_text.value)
assert mismatches_size_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 26

def test_params_override(self):
T = TransferMechanism(
input_states=[[0], [0]],
params={INPUT_STATES: [[0, 0], [0]]}
)
assert T.instance_defaults.variable.shape == np.array([[0, 0], [0]]).shape
assert len(T.input_states) == 2

# ------------------------------------------------------------------------------------------------
# TEST 27

def test_inputstate_object(self):
with pytest.raises(StateError) as error_text:
m = TransferMechanism(default_variable=[0, 0, 0])
i = InputState(owner=m, variable=[0, 0, 0])
TransferMechanism(input_states=[i])
assert 'that belongs to another Mechanism' in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 28

def test_inputstate_class(self):
T = TransferMechanism(input_states=[InputState])

np.testing.assert_array_equal(T.instance_defaults.variable, [InputState.ClassDefaults.variable])
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 29

def test_inputstate_class_with_variable(self):
T = TransferMechanism(default_variable=[0, 0], input_states=[InputState])

np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 30

def test_InputState_mismatches_default(self):
with pytest.raises(MechanismError) as error_text:
i = InputState(reference_value=[0, 0, 0])
TransferMechanism(default_variable=[0, 0], input_states=[i])
assert mismatches_default_variable_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 31

def test_projection_with_matrix_and_sender(self):
m = TransferMechanism(size=2)
p = MappingProjection(sender=m, matrix=[[0, 0, 0], [0, 0, 0]])
T = TransferMechanism(input_states=[p])

np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0, 0]]))
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 32

def test_projection_with_matrix_and_sender_mismatches_default(self):
with pytest.raises(MechanismError) as error_text:
m = TransferMechanism(size=2)
p = MappingProjection(sender=m, matrix=[[0, 0, 0], [0, 0, 0]])
TransferMechanism(default_variable=[0, 0], input_states=[p])
assert mismatches_default_variable_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 33

def test_projection_with_sender_and_default(self):
t = TransferMechanism(size=3)
p = MappingProjection(sender=t)
T = TransferMechanism(default_variable=[0, 0], input_states=[p])

np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 34

def test_projection_no_args_projection_spec(self):
p = MappingProjection()
T = TransferMechanism(input_states=[p])

np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0]]))
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 35

def test_projection_no_args_projection_spec_with_default(self):
p = MappingProjection()
T = TransferMechanism(default_variable=[0, 0], input_states=[p])

np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0]]))
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 36

def test_projection_no_args_dict_spec(self):
p = MappingProjection()
T = TransferMechanism(input_states=[{VARIABLE: [0, 0, 0], PROJECTIONS:[p]}])

np.testing.assert_array_equal(T.instance_defaults.variable, np.array([[0, 0, 0]]))
assert len(T.input_states) == 1

# ------------------------------------------------------------------------------------------------
# TEST 37

def test_projection_no_args_dict_spec_mismatch_with_default(self):
with pytest.raises(MechanismError) as error_text:
p = MappingProjection()
TransferMechanism(default_variable=[0, 0], input_states=[{VARIABLE: [0, 0, 0], PROJECTIONS: [p]}])
assert mismatches_default_variable_error_text in str(error_text.value)

# ------------------------------------------------------------------------------------------------
# TEST 38

def test_outputstate_(self):
with pytest.raises(MechanismError) as error_text:
p = MappingProjection()
TransferMechanism(default_variable=[0, 0], input_states=[{VARIABLE: [0, 0, 0], PROJECTIONS: [p]}])
assert mismatches_default_variable_error_text in str(error_text.value)

0 comments on commit 7da6769

Please sign in to comment.