Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to access trace #246

Open
floswald opened this issue Jul 10, 2020 · 8 comments · May be fixed by #262
Open

API to access trace #246

floswald opened this issue Jul 10, 2020 · 8 comments · May be fixed by #262

Comments

@floswald
Copy link

floswald commented Jul 10, 2020

i'd find it very handy to get both x and F traces from a returned object, like

x=nlsolve(f!, j!, [ 0.1; 1.2],store_trace = true,extended_trace = true)
xtrace(x)
ftrace(x)

basically a shortcut for

julia> vcat([(x.trace[i].metadata["f(x)"])' for i in 1:x.iterations]...)
4×2 Array{Float64,2}:
 1.6568       0.320451
 0.375216     0.0164459
 0.00739956  -0.00032626
 4.3425e-7   -1.25053e-8

thoughts?

@pkofod
Copy link
Member

pkofod commented Aug 14, 2020

Yes, I thought it was already possible, but I think I only did that for Optim, https://github.com/JuliaNLSolvers/Optim.jl/blob/master/src/api.jl#L8 . Should be possible to more or less copy those here.

@floswald
Copy link
Author

it seems that in a recent version the metadata entry is no longer populated. how can I get the x and f traces?

r = nlsolve(f!, j!, [ 0.1; 1.2],store_trace = true)

julia> r.trace
Iter     f(x) inf-norm    Step 2-norm 
------   --------------   --------------
     0     1.656800e+00              NaN
     1     3.752158e-01     2.039103e-01
     2     7.399559e-03     3.379446e-02
     3     4.342501e-07     7.786475e-04
     4     3.552714e-15     4.361577e-08

julia> dump(r)
NLsolve.SolverResults{Float64,Float64,Array{Float64,1},Array{Float64,1}}
  method: String "Trust-region with dogleg and autoscaling"
  initial_x: Array{Float64}((2,)) [0.1, 1.2]
  zero: Array{Float64}((2,)) [-3.7818049096324184e-16, 1.0000000000000002]
  residual_norm: Float64 3.552713678800501e-15
  iterations: Int64 4
  x_converged: Bool false
  xtol: Float64 0.0
  f_converged: Bool true
  ftol: Float64 1.0e-8
  trace: NLsolve.SolverTrace
    states: Array{NLsolve.SolverState}((5,))
      1: NLsolve.SolverState{Float64}
        iteration: Int64 0
        fnorm: Float64 1.6568000000000005
        stepnorm: Float64 NaN
        metadata: Dict{Any,Any}
          slots: Array{UInt8}((16,)) UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
          keys: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          vals: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          ndel: Int64 0
          count: Int64 0
          age: UInt64 0x0000000000000000
          idxfloor: Int64 1
          maxprobe: Int64 0
      2: NLsolve.SolverState{Float64}
        iteration: Int64 1
        fnorm: Float64 0.3752157650857306
        stepnorm: Float64 0.20391031379570138
        metadata: Dict{Any,Any}
          slots: Array{UInt8}((16,)) UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
          keys: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          vals: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          ndel: Int64 0
          count: Int64 0
          age: UInt64 0x0000000000000000
          idxfloor: Int64 1
          maxprobe: Int64 0
      3: NLsolve.SolverState{Float64}
        iteration: Int64 2
        fnorm: Float64 0.007399559061358474
        stepnorm: Float64 0.03379445711009191
        metadata: Dict{Any,Any}
          slots: Array{UInt8}((16,)) UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
          keys: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          vals: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          ndel: Int64 0
          count: Int64 0
          age: UInt64 0x0000000000000000
          idxfloor: Int64 1
          maxprobe: Int64 0
      4: NLsolve.SolverState{Float64}
        iteration: Int64 3
        fnorm: Float64 4.3425005102903924e-7
        stepnorm: Float64 0.0007786475321158225
        metadata: Dict{Any,Any}
          slots: Array{UInt8}((16,)) UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
          keys: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          vals: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          ndel: Int64 0
          count: Int64 0
          age: UInt64 0x0000000000000000
          idxfloor: Int64 1
          maxprobe: Int64 0
      5: NLsolve.SolverState{Float64}
        iteration: Int64 4
        fnorm: Float64 3.552713678800501e-15
        stepnorm: Float64 4.3615772673215287e-8
        metadata: Dict{Any,Any}
          slots: Array{UInt8}((16,)) UInt8[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
          keys: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          vals: Array{Any}((16,))
            1: #undef
            2: #undef
            3: #undef
            4: #undef
            5: #undef
            ...
            12: #undef
            13: #undef
            14: #undef
            15: #undef
            16: #undef
          ndel: Int64 0
          count: Int64 0
          age: UInt64 0x0000000000000000
          idxfloor: Int64 1
          maxprobe: Int64 0
  f_calls: Int64 5
  g_calls: Int64 5

@pkofod
Copy link
Member

pkofod commented Dec 19, 2020

Seems like a bug. I'll look.

@pkofod
Copy link
Member

pkofod commented Dec 19, 2020

I think you always had to use extended_trace for the vectors to be stored.

@floswald
Copy link
Author

So store_trace and extended_trace need to be true?

@pkofod
Copy link
Member

pkofod commented Dec 19, 2020

Yes, that's also what you did in the first comment.

@pkofod pkofod linked a pull request Dec 19, 2020 that will close this issue
@pkofod
Copy link
Member

pkofod commented Dec 19, 2020

This is to avoid storing all the arrays unless you're very certain that you want to. It's the same in Optim where the store_trace only enables saving of the objective value (a scalar) and the gradient norm (a scalar). You need extended_trace for x, g, and H to be stored. I've opened #262

@floswald
Copy link
Author

Oh no! Of course. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants