diff --git a/psyneulink/core/compositions/composition.py b/psyneulink/core/compositions/composition.py index 6cc1a44d39..f1ebc16e4e 100644 --- a/psyneulink/core/compositions/composition.py +++ b/psyneulink/core/compositions/composition.py @@ -12880,7 +12880,7 @@ def do_gradient_optimization(self, retain_in_pnl_options, context, optimization_ pass @handle_external_context(fallback_most_recent=True) - def reset(self, values=None, include_unspecified_nodes=True, context=NotImplemented): + def reset(self, values=None, include_unspecified_nodes=True, clear_results=False, context=NotImplemented): if not values: values = {} @@ -12890,6 +12890,9 @@ def reset(self, values=None, include_unspecified_nodes=True, context=NotImplemen reset_val = values.get(node) node.reset(reset_val, context=context) + if clear_results: + self.parameters.results._set([], context) + @handle_external_context(fallback_most_recent=True) def initialize(self, values=None, include_unspecified_nodes=True, context=None): """ diff --git a/tests/composition/test_composition.py b/tests/composition/test_composition.py index 41b8127e52..8940d1ecab 100644 --- a/tests/composition/test_composition.py +++ b/tests/composition/test_composition.py @@ -7264,6 +7264,16 @@ def test_save_state_before_simulations(self): np.testing.assert_allclose(np.asfarray(run_1_values), [[0.36], [0.056], [0.056]]) np.testing.assert_allclose(np.asfarray(run_2_values), [[0.5904], [0.16384], [0.16384]]) + def test_reset_clear_results(self): + mech = ProcessingMechanism(name='mech') + comp = Composition(nodes=[mech]) + comp.run(inputs={mech: 1}) + assert comp.results == [[1]] + comp.reset() + assert comp.results == [[1]] + comp.reset(clear_results=True) + assert comp.results == [] + class TestNodeRoles: