mauro3/Parameters.jl

how to make parameter independence work for using copy or reconstruct?

vancleve opened this issue · 4 comments

If there is parameter interdependence like below, updating the value of an independent parameter when copying or reconstructing a parameter object does not update the value of the dependent parameter.

julia> @with_kw struct pars
           a::Float64 = 1.0
           b::Float64 = a + 1.0
       end
pars

julia> x = pars()
pars
  a: Float64 1.0
  b: Float64 2.0


julia> y = pars(x; a=2.0)
pars
  a: Float64 2.0
  b: Float64 2.0

Any ideas how to get around this?

No, not really. But you could add an assertion to at least catch it, at least if property b==a+1 must hold.

Yes, right. One can implement tests on a case-by-case basis. I'll give it a go.

Another thing you can do, if it always holds, is to use getproperty and calculated it on the fly.

ah yes, great idea!