Skip to content

Commit d89e955

Browse files
committed
Fix crash when sequential runs have different n_obj by cloning output objects
- Clone output objects in Algorithm.setup() to prevent state pollution between runs - Ensures each algorithm run gets a fresh output instance with correct dimensions - Prevents IndexError in normalization when n_obj changes between sequential runs Fixes #357
1 parent 3e74cac commit d89e955

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pymoo/core/algorithm.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ def setup(self, problem, **kwargs):
100100
# the problem to be solved by the algorithm
101101
self.problem = problem
102102

103+
# clone the output object if it exists to avoid state pollution between runs
104+
if self.output is not None:
105+
self.output = copy.deepcopy(self.output)
106+
103107
# set all the provided options to this method
104108
for key, value in kwargs.items():
105109
self.__dict__[key] = value

0 commit comments

Comments
 (0)