Skip to content

Commit

Permalink
• composition.py
Browse files Browse the repository at this point in the history
  - reset():  add clear_results arg
  • Loading branch information
jdcpni committed Dec 2, 2024
1 parent 9e5f06b commit 7b8187b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion psyneulink/core/compositions/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand All @@ -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):
"""
Expand Down
10 changes: 10 additions & 0 deletions tests/composition/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 7b8187b

Please sign in to comment.