Skip to content

Commit 96c9b39

Browse files
Merge pull request #734 from jonathanfischer97/fix_pop_save
Reversion: stop deep copying population, just save `curr_u` for `OptimizationState` construction
2 parents 5333fd5 + e2cad3d commit 96c9b39

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

lib/OptimizationEvolutionary/src/OptimizationEvolutionary.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ function Evolutionary.trace!(tr, iteration, objfun, state, population,
2121
dt = Dict{String, Any}()
2222
dt["time"] = curr_time
2323

24-
# record `x` to store the population. Needed for constructing OptimizationState.
25-
dt["x"] = deepcopy(population)
24+
# record current u0. Needed for constructing OptimizationState.
25+
dt["curr_u"] = population[end]
2626

2727
# set additional trace value
2828
Evolutionary.trace!(dt, objfun, state, population, method, options)
@@ -105,7 +105,7 @@ function SciMLBase.__solve(cache::OptimizationCache{
105105
cur, state = iterate(cache.data)
106106

107107
function _cb(trace)
108-
curr_u = decompose_trace(trace).metadata["x"][end]
108+
curr_u = decompose_trace(trace).metadata["curr_u"]
109109
opt_state = Optimization.OptimizationState(;
110110
iter = decompose_trace(trace).iteration,
111111
u = curr_u,

lib/OptimizationEvolutionary/test/runtests.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ Random.seed!(1234)
5353
# 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

56-
# Make sure that both the user's trace record value, as well as `x` are stored in the trace.
56+
# Make sure that both the user's trace record value, as well as `curr_u` are stored in the trace.
5757
@test haskey(sol.original.trace[end].metadata, "TESTVAL") &&
58-
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"])
58+
haskey(sol.original.trace[end].metadata, "curr_u")
6259
end

0 commit comments

Comments
 (0)