Skip to content

Commit 20e46a6

Browse files
Merge pull request #730 from jonathanfischer97/fix_pop_save
`deepcopy` to save population in default trace, instead of reference
2 parents 8310517 + d4c732a commit 20e46a6

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/OptimizationEvolutionary/src/OptimizationEvolutionary.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Evolutionary.trace!(tr, iteration, objfun, state, population,
1818
dt["time"] = curr_time
1919

2020
# record `x` to store the population. Needed for constructing OptimizationState.
21-
dt["x"] = population
21+
dt["x"] = deepcopy(population)
2222

2323
# set additional trace value
2424
Evolutionary.trace!(dt, objfun, state, population, method, options)

lib/OptimizationEvolutionary/test/runtests.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ Random.seed!(1234)
5050
record["TESTVAL"] = state.fittest
5151
end
5252

53-
#test that `store_trace=true` works now. Threw ""type Array has no field value" before.
53+
# Test that `store_trace=true` works now. Threw ""type Array has no field value" before.
5454
sol = solve(prob, CMAES= 40, λ = 100), store_trace = true)
5555

5656
# Make sure that both the user's trace record value, as well as `x` are stored in the trace.
5757
@test haskey(sol.original.trace[end].metadata, "TESTVAL") &&
5858
haskey(sol.original.trace[end].metadata, "x")
59+
60+
# Test the the values of x are saved, not the reference
61+
@test sol.original.trace[end].metadata["x"] !== sol.original.trace[end-1].metadata["x"]
5962
end

0 commit comments

Comments
 (0)