Skip to content

Commit 9ce7a4d

Browse files
committed
New output
Tried to add the uniform output (compatible with SciMLBase).
1 parent f435dfe commit 9ce7a4d

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
2020
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2121
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2222
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
23+
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2324
TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
2425
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
2526
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
@@ -39,6 +40,7 @@ ProgressLogging = "0.1"
3940
Reexport = "0.2, 1.0"
4041
Requires = "1.0"
4142
ReverseDiff = "1.4"
43+
SciMLBase = "1.7.3"
4244
TerminalLoggers = "0.1"
4345
Tracker = "0.2"
4446
Zygote = "0.5, 0.6"

src/solve.jl

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
1-
abstract type AbstractOptimizationSolution end #experimental; comments welcome
2-
mutable struct OptimizationSolution{O, Tx, Tf, Tls, Tsb} <: AbstractOptimizationSolution
3-
method::O
4-
initial_x::Tx
5-
minimizer::Tx
1+
abstract type AbstractOptimizationSolution{T, N} <: AbstractNoTimeSolution{T, N} end
2+
3+
struct OptimizationSolution{T, N, uType, P, A, Tf} <: AbstractOptimizationSolution{T, N}
4+
u::uType # minimizer
5+
prob::P # optimization problem
6+
alg::A # algorithm
67
minimum::Tf
7-
iterations::Int
8-
iteration_converged::Bool
9-
ls_success::Tls
10-
time_run::Float64
11-
stopped_by::Tsb
8+
initial_x::Array{Float64,1}
9+
retcode::Symbol
10+
original::String # original output of the optimizer
1211
end
1312

14-
function Base.show(io::IO, r::AbstractOptimizationSolution)
15-
take = Iterators.take
16-
failure_string = "failure"
17-
if isa(r.ls_success, Bool) && !r.ls_success
18-
failure_string *= " (line search failed)"
19-
end
13+
function build_solution(prob::AbstractNonlinearProblem,
14+
alg, u, minimum;
15+
initial_x = prob.u0,
16+
retcode = :Default,
17+
original = nothing,
18+
kwargs...)
19+
20+
T = eltype(eltype(u))
21+
N = ndims(u)
22+
23+
OptimizationSolution{T, N, typeof(u), typeof(prob), typeof(alg),
24+
typeof(minimum)}
25+
(u, prob, alg, minimum, initial_x,
26+
retcode, original)
27+
end
28+
29+
function Base.show(io::IO, A::AbstractNoTimeSolution)
2030

21-
@printf io " * Status: %s\n\n" r.iteration_converged ? "success" : failure_string
31+
@printf io "\n * Status: %s\n\n" A.retcode === :Success ? "success" : "failure"
2232
@printf io " * Candidate solution\n"
23-
fmt = " Final objective value: %e "*repeat(", %e ",length(r.minimum)-1)*"\n"
24-
@eval @printf($io, $fmt, $r.minimum...)
25-
#@printf io " Final objective value: %e\n" r.minimum
33+
@printf io " Final objective value: %e\n" A.minimum
2634
@printf io "\n"
2735
@printf io " * Found with\n"
28-
@printf io " Algorithm: %s\n" r.method
36+
@printf io " Algorithm: %s\n" A.alg
2937
return
3038
end
3139

@@ -159,15 +167,7 @@ function __solve(prob::OptimizationProblem, opt, data = DEFAULT_DATA;
159167

160168
_time = time()
161169

162-
OptimizationSolution(opt,
163-
prob.u0,# initial_x,
164-
θ, #pick_best_x(f_incr_pick, state),
165-
save_best ? first(min_err) : first(x), # pick_best_f(f_incr_pick, state, d),
166-
maxiters, #iteration,
167-
maxiters >= maxiters, #iteration == options.iterations,
168-
true,
169-
_time-t0,
170-
NamedTuple())
170+
# here should be build_solution to create the output message
171171
end
172172

173173

@@ -447,7 +447,7 @@ function __init__()
447447
end
448448

449449
_loss = function(θ)
450-
x = ntuple(i->first(prob.prob[i].f(θ, prob.prob[i].p, cur...)),length(prob.prob))
450+
x = ntuple(i->first(prob.prob[i].f(θ, prob.prob[i].p, cur...)),length(prob.prob))
451451
return x
452452
end
453453

0 commit comments

Comments
 (0)