def test_ddm_is_finished(mode, noise, threshold, expected_results): comp = Composition() ddm = DDM(execute_until_finished=True, function=DriftDiffusionIntegrator(threshold=threshold, noise=noise)) comp.add_node(ddm) results = comp.run([0], bin_execute=mode) results = [x for x in np.array(results).flatten()] #HACK: The result is an object dtype in Python mode for some reason? assert np.allclose(results, np.array(expected_results).flatten())
def test_LCAMechanism_threshold_with_convergence(self, benchmark, mode): lca = LCAMechanism(size=3, leak=0.5, threshold=0.01, threshold_criterion=CONVERGENCE) comp = Composition() comp.add_node(lca) result = comp.run(inputs={lca:[0,1,2]}, bin_execute=mode) assert np.allclose(result, [[0.19153799, 0.5, 0.80846201]]) if mode == 'Python': assert lca.num_executions_before_finished == 18 if benchmark.enabled: benchmark(comp.run, inputs={lca:[0,1,2]}, bin_execute=mode)
def test_valid_input_float(self): A = ProcessingMechanism(name="A") comp = Composition(name="comp") comp.add_node(A) comp.run(inputs={A: 5.0}) assert np.allclose(comp.results, [[5.0]]) comp.run(inputs={A: [5.0, 10.0, 15.0]}) assert np.allclose(comp.results, [[[5.0]], [[5.0]], [[10.0]], [[15.0]]])
def test_one_composition_two_contexts(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='scheduler-pytests-A') comp.add_node(A) sched = Scheduler(composition=comp) 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) eid = uuid.uuid4() comp.run( inputs={A: [[0], [1], [2], [3], [4], [5]]}, scheduler_processing=sched, termination_processing=termination_conds, execution_id=eid, ) output = sched.execution_list[eid] expected_output = [ A, A, A, A, A, set() ] # pprint.pprint(output) assert output == pytest.helpers.setify_expected_output(expected_output) comp.run( inputs={A: [[0], [1], [2], [3], [4], [5]]}, scheduler_processing=sched, termination_processing=termination_conds, execution_id=eid, ) output = sched.execution_list[eid] expected_output = [ A, A, A, A, A, set(), set(), set(), set(), set(), set(), set() ] # pprint.pprint(output) assert output == pytest.helpers.setify_expected_output(expected_output) eid2 = uuid.uuid4() comp.run( inputs={A: [[0], [1], [2], [3], [4], [5]]}, scheduler_processing=sched, termination_processing=termination_conds, execution_id=eid2, ) output = sched.execution_list[eid2] expected_output = [ A, A, A, A, A, set() ] # pprint.pprint(output) assert output == pytest.helpers.setify_expected_output(expected_output)
def test_LCAMechanism_DDM_equivalent(self, comp_mode): lca = LCAMechanism(size=2, leak=0., threshold=1, auto=0, hetero=0, initial_value=[0, 0], execute_until_finished=False) comp1 = Composition() comp1.add_node(lca) result1 = comp1.run(inputs={lca: [1, -1]}, execution_mode=comp_mode) assert np.allclose(result1, [[0.52497918747894, 0.47502081252106]])
def test_partial_override_composition(self): comp = Composition() A = TransferMechanism(name='scheduler-pytests-A') B = IntegratorMechanism(name='scheduler-pytests-B') for m in [A, B]: comp.add_node(m) comp.add_projection(MappingProjection(), A, B) termination_conds = {TimeScale.TRIAL: AfterNCalls(B, 2)} output = comp.run(inputs={A: 1}, termination_processing=termination_conds) # two executions of B assert output == [.75]
def test_nested_composition_run_trials_inputs(benchmark, executions, mode): benchmark.group = "Nested Composition mutliple trials/inputs multirun {}".format( executions) # mechanisms A = ProcessingMechanism(name="A", function=AdaptiveIntegrator(rate=0.1)) B = ProcessingMechanism(name="B", function=Logistic) inner_comp = Composition(name="inner_comp") inner_comp.add_linear_processing_pathway([A, B]) inner_comp._analyze_graph() sched = Scheduler(composition=inner_comp) outer_comp = Composition(name="outer_comp") outer_comp.add_node(inner_comp) outer_comp._analyze_graph() sched = Scheduler(composition=outer_comp) # The input dict should assign inputs origin nodes (inner_comp in this case) var = {inner_comp: [[[2.0]], [[3.0]]]} expected = [[[0.549833997312478]], [[0.617747874769249]], [[0.6529428177055896]], [[0.7044959416252289]]] if executions > 1: var = [var for _ in range(executions)] if mode == 'Python': def f(v, num_trials, res=False): results = [] for i in range(executions): outer_comp.run(v[i], execution_id=i, num_trials=num_trials) if res: # copy the results immediately, otherwise it's empty results.append(outer_comp.results.copy()) return results res = f(var, 4, True) if executions > 1 else f([var], 4, True) benchmark(f if executions > 1 else outer_comp.run, var, num_trials=4) elif mode == 'LLVM': e = pnlvm.execution.CompExecution(outer_comp, [None for _ in range(executions)]) res = e.run(var, 4, 2) benchmark(e.run, var, 4, 2) elif mode == 'PTX': e = pnlvm.execution.CompExecution(outer_comp, [None for _ in range(executions)]) res = e.cuda_run(var, 4, 2) benchmark(e.cuda_run, var, 4, 2) assert np.allclose(res, [expected for _ in range(executions)]) assert len(res) == executions or executions == 1
def test_origin_input_source_true_no_input(self): A = ProcessingMechanism(name='A') B = ProcessingMechanism(name='B') C = ProcessingMechanism(name='C', default_variable=[[4.56]]) comp = Composition(name='comp') comp.add_linear_processing_pathway([A, B]) comp.add_node(C) comp.run(inputs={A: [[1.23]]}) assert np.allclose(A.parameters.value.get(comp), [[1.23]]) assert np.allclose(B.parameters.value.get(comp), [[1.23]]) assert np.allclose(C.parameters.value.get(comp), [[4.56]])
def test_one_to_two(self): A = ProcessingMechanism(name='A') B = ProcessingMechanism(name='B') C = ProcessingMechanism(name='C', input_states=[A.input_state]) comp = Composition(name='comp') comp.add_linear_processing_pathway([A, B]) comp.add_node(C) comp.run(inputs={A: [[1.23]]}) assert np.allclose(A.parameters.value.get(comp), [[1.23]]) assert np.allclose(B.parameters.value.get(comp), [[1.23]]) assert np.allclose(C.parameters.value.get(comp), [[1.23]])
def test_BeforeNCalls(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') comp.add_node(A) sched = Scheduler(composition=comp) sched.add_condition(A, BeforeNCalls(A, 3)) 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, set(), set()] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_WhileNot_AtPass_in_middle(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') comp.add_node(A) sched = Scheduler(composition=comp) sched.add_condition(A, WhileNot(lambda sched: sched.clock.get_total_times_relative(TimeScale.PASS, TimeScale.TRIAL) == 2, sched)) 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, set(), A, A] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_All_end_after_one_finished(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') for m in [A]: comp.add_node(m) sched = Scheduler(composition=comp) sched.add_condition(A, EveryNPasses(1)) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(1) termination_conds[TimeScale.TRIAL] = Any(AfterNCalls(A, 5), AtPass(10)) output = list(sched.run(termination_conds=termination_conds)) expected_output = [A for _ in range(5)] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_partial_override_scheduler(self): comp = Composition() A = TransferMechanism(name='scheduler-pytests-A') B = TransferMechanism(name='scheduler-pytests-B') for m in [A, B]: comp.add_node(m) comp.add_projection(MappingProjection(), A, B) sched = Scheduler(composition=comp) sched.add_condition(B, EveryNCalls(A, 2)) termination_conds = {TimeScale.TRIAL: AfterNCalls(B, 2)} output = list(sched.run(termination_conds=termination_conds)) expected_output = [A, A, B, A, A, B] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_nested_composition_execution(benchmark, executions, mode): benchmark.group = "Nested Composition execution multirun {}".format( executions) # mechanisms A = ProcessingMechanism(name="A", function=AdaptiveIntegrator(rate=0.1)) B = ProcessingMechanism(name="B", function=Logistic) inner_comp = Composition(name="inner_comp") inner_comp.add_linear_processing_pathway([A, B]) inner_comp._analyze_graph() sched = Scheduler(composition=inner_comp) outer_comp = Composition(name="outer_comp") outer_comp.add_node(inner_comp) outer_comp._analyze_graph() sched = Scheduler(composition=outer_comp) # The input dict should assign inputs origin nodes (inner_comp in this case) var = {inner_comp: [[1.0]]} expected = [[0.52497918747894]] if executions > 1: var = [var for _ in range(executions)] if mode == 'Python': f = lambda x: [ outer_comp.execute(x[i], execution_id=i) for i in range(executions) ] res = f(var) if executions > 1 else outer_comp.execute(var) benchmark(f if executions > 1 else outer_comp.execute, var) elif mode == 'LLVM': e = pnlvm.execution.CompExecution(outer_comp, [None for _ in range(executions)]) e.execute(var) res = e.extract_node_output(outer_comp.output_CIM) benchmark(e.execute, var) elif mode == 'PTX': e = pnlvm.execution.CompExecution(outer_comp, [None for _ in range(executions)]) e.cuda_execute(var) res = e.extract_node_output(outer_comp.output_CIM) benchmark(e.cuda_execute, var) assert np.allclose(res, [expected for _ in range(executions)]) assert len(res) == executions
def test_multisource_2(self): comp = Composition() A1 = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A1') A2 = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A2') B1 = TransferMechanism(function=Linear(intercept=4.0), name='B1') B2 = TransferMechanism(function=Linear(intercept=4.0), name='B2') B3 = TransferMechanism(function=Linear(intercept=4.0), name='B3') C1 = TransferMechanism(function=Linear(intercept=1.5), name='C1') C2 = TransferMechanism(function=Linear(intercept=.5), name='C2') for m in [A1, A2, B1, B2, B3, C1, C2]: comp.add_node(m) comp.add_projection(MappingProjection(), A1, B1) comp.add_projection(MappingProjection(), A1, B2) comp.add_projection(MappingProjection(), A2, B1) comp.add_projection(MappingProjection(), A2, B2) comp.add_projection(MappingProjection(), A2, B3) comp.add_projection(MappingProjection(), B1, C1) comp.add_projection(MappingProjection(), B2, C1) comp.add_projection(MappingProjection(), B1, C2) comp.add_projection(MappingProjection(), B3, C2) sched = Scheduler(composition=comp) sched.add_condition_set({ A1: Always(), A2: Always(), B1: EveryNCalls(A1, 2), B3: EveryNCalls(A2, 2), B2: All(EveryNCalls(A1, 4), EveryNCalls(A2, 4)), C1: Any(AfterNCalls(B1, 2), AfterNCalls(B2, 2)), C2: Any(AfterNCalls(B2, 2), AfterNCalls(B3, 2)), }) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(1) termination_conds[TimeScale.TRIAL] = All(AfterNCalls(C1, 1), AfterNCalls(C2, 1)) output = list(sched.run(termination_conds=termination_conds)) expected_output = [ set([A1, A2]), set([A1, A2]), set([B1, B3]), set([A1, A2]), set([A1, A2]), set([B1, B2, B3]), set([C1, C2]) ] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_user_added_ports(self): comp = Composition() mech = ProcessingMechanism() comp.add_node(mech) # instantiate custom input and output ports inp = InputPort(size=2) out = OutputPort(size=2) # add custom input and output ports to CIM comp.input_CIM.add_ports([inp, out]) # verify the ports have been added to the user_added_ports set # and that no extra ports were added assert inp in comp.input_CIM.user_added_ports['input_ports'] assert len(comp.input_CIM.user_added_ports['input_ports']) == 1 assert out in comp.input_CIM.user_added_ports['output_ports'] assert len(comp.input_CIM.user_added_ports['output_ports']) == 1 comp.input_CIM.remove_ports([inp, out]) # verify that call to remove ports succesfully removed the ports from user_added_ports assert len(comp.input_CIM.user_added_ports['input_ports']) == 0 assert len(comp.input_CIM.user_added_ports['output_ports']) == 0
def test_one_input_port_one_output_port(self): comp = Composition() A = TransferMechanism(name="A", function=Linear(slope=2.0)) B = TransferMechanism(name="B", function=Linear(slope=3.0)) comp.add_node(A) comp.add_node(B) comp.add_projection(MappingProjection(sender=A, receiver=B), A, B) inputs_dict = { A: [[5.]], } sched = Scheduler(composition=comp) output = comp.run(inputs=inputs_dict, scheduler=sched) assert np.allclose([30], output)
def test_AfterTrial(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') comp.add_node(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=sched, termination_processing=termination_conds ) output = sched.execution_list[comp.default_execution_id] expected_output = [A, A, A, A, A] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_BeforeTimeStep_2(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='A') B = TransferMechanism(name='B') comp.add_node(A) comp.add_node(B) comp.add_projection(MappingProjection(), A, B) sched = Scheduler(composition=comp) sched.add_condition(A, BeforeTimeStep(2)) sched.add_condition(B, Always()) 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, B, B, B, B, B] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_NWhen_AfterNCalls(self, n, expected_output): 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_node(m) comp.add_projection(MappingProjection(), A, B) sched = Scheduler(composition=comp) sched.add_condition(A, Always()) sched.add_condition(B, NWhen(AfterNCalls(A, 3), n)) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(1) termination_conds[TimeScale.TRIAL] = AfterNCalls(A, 6) output = list(sched.run(termination_conds=termination_conds)) expected_output = [A if x == 'A' else B for x in expected_output] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_mix_and_match_input_sources(self): A = ProcessingMechanism(name='A') B = ProcessingMechanism(name='B', default_variable=[[0.], [0.]]) C = ProcessingMechanism( name='C', input_states=[B.input_states[1], A.input_state, B.input_states[0]]) input_dict = {A: [[2.0]], B: [[3.0], [1.0]]} comp = Composition(name="comp") comp.add_node(A) comp.add_node(B) comp.add_node(C) comp.run(inputs=input_dict) assert np.allclose(A.parameters.value.get(comp), [[2.]]) assert np.allclose(B.parameters.value.get(comp), [[3.], [1.]]) assert np.allclose(C.parameters.value.get(comp), [[1.], [2.], [3.]])
def test_linear_ABB(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='scheduler-pytests-A') B = TransferMechanism(function=Linear(intercept=4.0), name='scheduler-pytests-B') for m in [A, B]: comp.add_node(m) comp.add_projection(MappingProjection(), A, B) sched = Scheduler(composition=comp) sched.add_condition(A, Any(AtPass(0), EveryNCalls(B, 2))) sched.add_condition(B, Any(EveryNCalls(A, 1), EveryNCalls(B, 1))) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(1) termination_conds[TimeScale.TRIAL] = AfterNCalls(B, 8, time_scale=TimeScale.TRIAL) output = list(sched.run(termination_conds=termination_conds)) expected_output = [A, B, B, A, B, B, A, B, B, A, B, B] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_create_multiple_contexts(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='scheduler-pytests-A') comp.add_node(A) comp.scheduler_processing.clock._increment_time(TimeScale.TRIAL) eid2 = uuid.uuid4() eid3 = uuid.uuid4() comp.scheduler_processing._init_counts(execution_id=eid2) assert comp.scheduler_processing.clocks[eid2].time.trial == 0 comp.scheduler_processing.clock._increment_time(TimeScale.TRIAL) assert comp.scheduler_processing.clocks[eid2].time.trial == 0 comp.scheduler_processing._init_counts(execution_id=eid3, base_execution_id=comp.scheduler_processing.default_execution_id) assert comp.scheduler_processing.clocks[eid3].time.trial == 2
def test_9b(self): comp = Composition() A = TransferMechanism(function=Linear(slope=5.0, intercept=2.0), name='scheduler-pytests-A') A._is_finished = False B = TransferMechanism(function=Linear(intercept=4.0), name='scheduler-pytests-B') for m in [A, B]: comp.add_node(m) comp.add_projection(MappingProjection(), A, 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)
def test_warning_on_custom_cim_ports(self): comp = Composition() mech = ProcessingMechanism() comp.add_node(mech) warning_text = ( 'You are attempting to add custom ports to a CIM, which can result in unpredictable behavior ' 'and is therefore recommended against. If suitable, you should instead add ports to the ' r'mechanism\(s\) that project to or are projected to from the CIM.' ) with pytest.warns(UserWarning, match=warning_text): # KDM 7/22/20: previously was OutputPort, but that produces # an invalid CIM state that cannot be executed, and will # throw an error due to new _update_default_variable call comp.input_CIM.add_ports(InputPort()) with pytest.warns(None) as w: comp._analyze_graph() comp.run({mech: [[1]]}) assert len(w) == 0
def test_function_param_no_condition(self): T = TransferMechanism() C = Composition() C.add_node(T) assert T.function.slope.base == 1.0 assert T.parameter_ports['slope'].value == 1.0 C.run(inputs={T: 2.0}, runtime_params={T: {"slope": 10.0}}) # runtime param used for slope assert T.parameters.value.get(C.default_execution_id) == 20.0 # slope restored to default assert T.function.slope.base == 1.0 assert T.parameter_ports['slope'].parameters.value.get(C) == 1.0 # previous runtime_param for slope not used again C.run(inputs={T: 2.0}) assert T.parameters.value.get(C.default_execution_id) == 2.0 assert T.function.slope.base == 1.0 assert T.parameter_ports['slope'].parameters.value.get(C) == 1.0
def test_connect_compositions_with_complicated_states(self, mode): inner_composition_1 = Composition(name="comp1") A = TransferMechanism(name="A1", default_variable=[[0.0], [0.0]], function=Linear(slope=2.0)) B = TransferMechanism(name="B1", default_variable=[[0.0], [0.0]], function=Linear(slope=3.0)) inner_composition_1.add_node(A) inner_composition_1.add_node(B) inner_composition_1.add_projection(MappingProjection(sender=A, receiver=B), A, B) inner_composition_1.add_projection(MappingProjection(sender=A.output_ports[1], receiver=B.input_ports[1]), A, B) inner_composition_2 = Composition(name="comp2") A2 = TransferMechanism(name="A2", default_variable=[[0.0], [0.0]], function=Linear(slope=2.0)) B2 = TransferMechanism(name="B2", default_variable=[[0.0], [0.0]], function=Linear(slope=3.0)) inner_composition_2.add_node(A2) inner_composition_2.add_node(B2) inner_composition_2.add_projection(MappingProjection(sender=A2, receiver=B2), A2, B2) inner_composition_2.add_projection(MappingProjection(sender=A2.output_ports[1], receiver=B2.input_ports[1]), A2, B2) outer_composition = Composition(name="outer_composition") outer_composition.add_node(inner_composition_1) outer_composition.add_node(inner_composition_2) outer_composition.add_projection(projection=MappingProjection(), sender=inner_composition_1, receiver=inner_composition_2) outer_composition.add_projection( projection=MappingProjection(sender=inner_composition_1.output_CIM.output_ports[1], receiver=inner_composition_2.input_CIM.input_ports[1]), sender=inner_composition_1, receiver=inner_composition_2) sched = Scheduler(composition=outer_composition) output = outer_composition.run( inputs={inner_composition_1: [[[5.0], [50.0]]]}, scheduler=sched, bin_execute=mode ) assert np.allclose(output, [[[180.], [1800.]]]) if mode == 'Python': assert np.allclose(inner_composition_1.get_output_values(outer_composition), [[30.], [300.]]) assert np.allclose(inner_composition_2.get_output_values(outer_composition), [[180.], [1800.]]) assert np.allclose(outer_composition.get_output_values(outer_composition), [[180.], [1800.]])
def test_composition_run_function_param_no_condition(self): # Construction T = TransferMechanism() C = Composition() C.add_node(T) assert T.function.slope == 1.0 assert T.parameter_ports['slope'].value == 1.0 # Runtime param used for slope # ONLY mechanism value should reflect runtime param -- attr should be changed back by the time we inspect it C.run(inputs={T: 2.0}, runtime_params={T: {"slope": 10.0}}) assert T.function.slope == 1.0 assert T.parameter_ports['slope'].parameters.value.get(C) == 1.0 assert T.parameters.value.get(C.default_execution_id) == 20.0 # Runtime param NOT used for slope C.run(inputs={T: 2.0}) assert T.function.slope == 1.0 assert T.parameter_ports['slope'].parameters.value.get(C) == 1.0 assert T.parameters.value.get(C.default_execution_id) == 2.0
def test_AtPass_underconstrained(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_node(m) comp.add_projection(MappingProjection(), A, B) comp.add_projection(MappingProjection(), B, C) sched = Scheduler(composition=comp) sched.add_condition(A, AtPass(0)) sched.add_condition(B, Always()) sched.add_condition(C, Always()) termination_conds = {} termination_conds[TimeScale.RUN] = AfterNTrials(1) termination_conds[TimeScale.TRIAL] = AfterNCalls(C, 2) output = list(sched.run(termination_conds=termination_conds)) expected_output = [A, B, C, B, C] assert output == pytest.helpers.setify_expected_output(expected_output)
def test_mechanism_param_no_condition(self): T = TransferMechanism() C = Composition() C.add_node(T) assert T.noise.base == 0.0 assert T.parameter_ports['noise'].value == 0.0 # runtime param used for noise C.run(inputs={T: 2.0}, runtime_params={T: {"noise": 10.0}}) assert T.parameters.value.get(C.default_execution_id) == 12.0 # noise restored to default assert T.noise.base == 0.0 assert T.parameter_ports['noise'].parameters.value.get(C) == 0.0 # previous runtime_param for noise not used again C.run(inputs={T: 2.0}, ) assert T.noise.base == 0.0 assert T.parameter_ports['noise'].parameters.value.get(C) == 0.0 assert T.parameters.value.get(C.default_execution_id) == 2.0