コード例 #1
0
    def test_formats_for_gating_specification_of_input_and_output_states(self):

        gating_spec_list = [
            pnl.GATING, pnl.GATING_SIGNAL, pnl.GATING_PROJECTION,
            pnl.GatingSignal,
            pnl.GatingSignal(), pnl.GatingProjection, "GP_OBJECT",
            pnl.GatingMechanism,
            pnl.GatingMechanism(), (0.3, pnl.GATING), (0.3, pnl.GATING_SIGNAL),
            (0.3, pnl.GATING_PROJECTION), (0.3, pnl.GatingSignal),
            (0.3, pnl.GatingSignal()), (0.3, pnl.GatingProjection),
            (0.3, "GP_OBJECT"), (0.3, pnl.GatingMechanism),
            (0.3, pnl.GatingMechanism())
        ]
        for i, gating_tuple in enumerate(
            [j for j in zip(gating_spec_list, reversed(gating_spec_list))]):
            G1, G2 = gating_tuple

            # This shenanigans is to avoid assigning the same instantiated ControlProjection more than once
            if G1 is 'GP_OBJECT':
                G1 = pnl.GatingProjection()
            elif isinstance(G1, tuple) and G1[1] is 'GP_OBJECT':
                G1 = (G1[0], pnl.GatingProjection())
            if G2 is 'GP_OBJECT':
                G2 = pnl.GatingProjection()
            elif isinstance(G2, tuple) and G2[1] is 'GP_OBJECT':
                G2 = (G2[0], pnl.GatingProjection())

            T = pnl.TransferMechanism(name='T-GATING-{}'.format(i),
                                      input_states=[G1],
                                      output_states=[G2])
            assert T.input_states[0].mod_afferents[0].name in \
                   'GatingProjection for T-GATING-{}[InputState-0]'.format(i)

            assert T.output_states[0].mod_afferents[0].name in \
                   'GatingProjection for T-GATING-{}[OutputState-0]'.format(i)
コード例 #2
0
ファイル: test_naming.py プロジェクト: uiuc-arc/PsyNeuLink
    def test_deferred_init_default_ModulatoryProjection_names(self):
        LP1 = pnl.LearningProjection()
        LP2 = pnl.LearningProjection()
        assert LP1.name == 'Deferred Init LearningProjection'
        assert LP2.name == 'Deferred Init LearningProjection-1'

        CP1 = pnl.ControlProjection()
        CP2 = pnl.ControlProjection()
        assert CP1.name == 'Deferred Init ControlProjection'
        assert CP2.name == 'Deferred Init ControlProjection-1'

        GP1 = pnl.GatingProjection()
        GP2 = pnl.GatingProjection()
        assert GP1.name == 'Deferred Init GatingProjection'
        assert GP2.name == 'Deferred Init GatingProjection-1'
コード例 #3
0
    def test_formats_for_gating_specification_of_input_and_output_states(self):

        gating_spec_list = [
            pnl.GATING, pnl.GATING_SIGNAL, pnl.GATING_PROJECTION,
            pnl.GatingSignal, pnl.GatingSignal,
            pnl.GatingSignal(), pnl.GatingProjection, "GP_OBJECT",
            pnl.GatingMechanism, pnl.ModulatoryMechanism,
            pnl.GatingMechanism(), (0.3, pnl.GATING), (0.3, pnl.GATING_SIGNAL),
            (0.3, pnl.GATING_PROJECTION), (0.3, pnl.GatingSignal),
            (0.3, pnl.GatingSignal()), (0.3, pnl.GatingProjection),
            (0.3, "GP_OBJECT"), (0.3, pnl.GatingMechanism),
            (0.3, pnl.ModulatoryMechanism), (0.3, pnl.GatingMechanism())
        ]
        for i, gating_tuple in enumerate(
            [j for j in zip(gating_spec_list, reversed(gating_spec_list))]):
            G1, G2 = gating_tuple

            # This shenanigans is to avoid assigning the same instantiated ControlProjection more than once
            if G1 is 'GP_OBJECT':
                G1 = pnl.GatingProjection()
            elif isinstance(G1, tuple) and G1[1] is 'GP_OBJECT':
                G1 = (G1[0], pnl.GatingProjection())
            if G2 is 'GP_OBJECT':
                G2 = pnl.GatingProjection()
            elif isinstance(G2, tuple) and G2[1] is 'GP_OBJECT':
                G2 = (G2[0], pnl.GatingProjection())

            T = pnl.TransferMechanism(name='T-GATING-{}'.format(i),
                                      input_states=[G1],
                                      output_states=[G2])
            assert T.input_states[0].mod_afferents[0].name in \
                   'GatingProjection for T-GATING-{}[InputState-0]'.format(i)

            assert T.output_states[0].mod_afferents[0].name in \
                   'GatingProjection for T-GATING-{}[OutputState-0]'.format(i)

        with pytest.raises(pnl.ProjectionError) as error_text:
            T1 = pnl.ProcessingMechanism(
                name='T1', input_states=[pnl.ModulatoryMechanism()])
        assert 'Primary OutputState of ModulatoryMechanism-0 (ControlSignal-0) ' \
               'cannot be used as a sender of a Projection to InputState of T1' in error_text.value.args[0]

        with pytest.raises(pnl.ProjectionError) as error_text:
            T2 = pnl.ProcessingMechanism(
                name='T2', output_states=[pnl.ModulatoryMechanism()])
        assert 'Primary OutputState of ModulatoryMechanism-1 (ControlSignal-0) ' \
               'cannot be used as a sender of a Projection to OutputState of T2' in error_text.value.args[0]
コード例 #4
0
    def test_formats_for_gating_specification_of_input_and_output_ports(
            self, input_port, output_port):
        G_IN, G_OUT = input_port, output_port

        # This shenanigans is to avoid assigning the same instantiated ControlProjection more than once
        if G_IN == 'GP_OBJECT':
            G_IN = pnl.GatingProjection()
        elif isinstance(G_IN, tuple) and G_IN[1] == 'GP_OBJECT':
            G_IN = (G_IN[0], pnl.GatingProjection())
        if G_OUT == 'GP_OBJECT':
            G_OUT = pnl.GatingProjection()
        elif isinstance(G_OUT, tuple) and G_OUT[1] == 'GP_OBJECT':
            G_OUT = (G_OUT[0], pnl.GatingProjection())

        if isinstance(G_IN, tuple):
            IN_NAME = G_IN[1]
        else:
            IN_NAME = G_IN
        IN_CONTROL = pnl.CONTROL in repr(IN_NAME).split(".")[-1].upper()
        if isinstance(G_OUT, tuple):
            OUT_NAME = G_OUT[1]
        else:
            OUT_NAME = G_OUT
        OUT_CONTROL = pnl.CONTROL in repr(OUT_NAME).split(".")[-1].upper()

        T = pnl.TransferMechanism(name='T-GATING',
                                  input_ports=[G_IN],
                                  output_ports=[G_OUT])

        if IN_CONTROL:
            assert T.input_ports[0].mod_afferents[0].name in \
                    'ControlProjection for T-GATING[InputPort-0]'
        else:
            assert T.input_ports[0].mod_afferents[0].name in \
                    'GatingProjection for T-GATING[InputPort-0]'

        if OUT_CONTROL:
            assert T.output_ports[0].mod_afferents[0].name in \
                    'ControlProjection for T-GATING[OutputPort-0]'
        else:
            assert T.output_ports[0].mod_afferents[0].name in \
                    'GatingProjection for T-GATING[OutputPort-0]'