Example #1
0
    def test_9(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='A')
        B = TransferMechanism(function=Linear(intercept=4.0), name='B')
        for m in [A, B]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, WhenFinished(A))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(B, 2)

        output = []
        i = 0
        for step in sched.run(termination_conds=termination_conds):
            if i == 3:
                A.is_finished = True
            output.append(step)
            i += 1

        expected_output = [A, A, A, A, B, A, B]
        assert output == pytest.helpers.setify_expected_output(expected_output)
Example #2
0
    def test_triangle_4b(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='A')
        B = TransferMechanism(function=Linear(intercept=4.0), name='B')
        C = TransferMechanism(function=Linear(intercept=1.5), name='C')

        for m in [A, B, C]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)
        comp.add_projection(A, MappingProjection(), C)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, EveryNCalls(A, 2))
        sched.add_condition(C, All(WhenFinished(A), AfterNCalls(B, 3)))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 1)
        output = []
        i = 0
        for step in sched.run(termination_conds=termination_conds):
            if i == 10:
                A.is_finished = True
            output.append(step)
            i += 1

        expected_output = [A, A, B, A, A, B, A, A, B, A, A, set([B, C])]
        # pprint.pprint(output)
        assert output == pytest.helpers.setify_expected_output(expected_output)
 def change_termination_processing():
     if S.termination_processing is None:
         S.scheduler_processing.termination_conds = {
             TimeScale.TRIAL: WhenFinished(D)
         }
         S.termination_processing = {TimeScale.TRIAL: WhenFinished(D)}
     elif isinstance(S.termination_processing[TimeScale.TRIAL],
                     AllHaveRun):
         S.scheduler_processing.termination_conds = {
             TimeScale.TRIAL: WhenFinished(D)
         }
         S.termination_processing = {TimeScale.TRIAL: WhenFinished(D)}
     else:
         S.scheduler_processing.termination_conds = {
             TimeScale.TRIAL: AllHaveRun()
         }
         S.termination_processing = {TimeScale.TRIAL: AllHaveRun()}
Example #4
0
    def test_is_finished_stops_system(self):
        D = DDM(name='DDM', function=DriftDiffusionIntegrator(threshold=10.0))
        P = Process(pathway=[D])
        S = System(processes=[P])

        S.run(inputs={D: 2.0},
              termination_processing={TimeScale.TRIAL: WhenFinished(D)})
        # decision variable's value should match threshold
        assert D.value[0] == 10.0
        # it should have taken 5 executions (and time_step_size = 1.0)
        assert D.value[1] == 5.0
Example #5
0
    def test_9b(self):
        comp = Composition()
        A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0),
                              name='A')
        A.is_finished = False
        B = TransferMechanism(function=Linear(intercept=4.0), name='B')
        for m in [A, B]:
            comp.add_mechanism(m)
        comp.add_projection(A, MappingProjection(), B)

        sched = Scheduler(composition=comp)

        sched.add_condition(A, EveryNPasses(1))
        sched.add_condition(B, WhenFinished(A))

        termination_conds = {}
        termination_conds[TimeScale.RUN] = AfterNTrials(1)
        termination_conds[TimeScale.TRIAL] = AtPass(5)
        output = list(sched.run(termination_conds=termination_conds))

        expected_output = [A, A, A, A, A]
        assert output == pytest.helpers.setify_expected_output(expected_output)
Example #6
0
 def test_invalid_input_WhenFinishedAll_2(self):
     with pytest.raises(ConditionError):
         WhenFinished({None}).is_satisfied()
Example #7
0
 def test_invalid_input_WhenFinishedAny_1(self):
     with pytest.raises(ConditionError):
         WhenFinished(None).is_satisfied()