def test_6_two_trials(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(B, MappingProjection(), C) sched = Scheduler(composition=comp) sched.add_condition(A, BeforePass(5)) sched.add_condition(B, AfterNCalls(A, 5)) sched.add_condition(C, AfterNCalls(B, 1)) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(2) termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 3) comp.run(inputs={A: range(6)}, scheduler_processing=sched, termination_processing=termination_conds) output = sched.execution_list expected_output = [ A, A, A, A, A, B, C, B, C, B, C, A, A, A, A, A, B, C, B, C, B, C ] # pprint.pprint(output) assert output == pytest.helpers.setify_expected_output(expected_output)
def test_two_compositions_one_scheduler(self): comp1 = Composition() comp2 = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') comp1.add_mechanism(A) comp2.add_mechanism(A) sched = Scheduler(composition=comp1) sched.add_condition(A, BeforeNCalls(A, 5, time_scale=TimeScale.LIFE)) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(6) termination_conds[TimeScale.TRIAL] = AfterNPasses(1) comp1.run(inputs={A: [[0], [1], [2], [3], [4], [5]]}, scheduler_processing=sched, termination_processing=termination_conds) output = sched.execution_list[comp1._execution_id] expected_output = [A, A, A, A, A, set()] # pprint.pprint(output) assert output == pytest.helpers.setify_expected_output(expected_output) comp2.run(inputs={A: [[0], [1], [2], [3], [4], [5]]}, scheduler_processing=sched, termination_processing=termination_conds) output = sched.execution_list[comp2._execution_id] expected_output = [A, A, A, A, A, set()] # pprint.pprint(output) assert output == pytest.helpers.setify_expected_output(expected_output)
def test_AfterTrial(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') comp.add_mechanism(A) sched = Scheduler(composition=comp) sched.add_condition(A, Always()) termination_conds = {} termination_conds[TimeScale.RUN] = AfterTrial(4) termination_conds[TimeScale.TRIAL] = AtPass(1) comp.run(inputs={A: range(6)}, scheduler_processing=sched, termination_processing=termination_conds) output = sched.execution_list expected_output = [A, A, A, A, A] assert output == pytest.helpers.setify_expected_output( expected_output)