fix: change parameter_values(::GraphSystemParameters) to access params_partitioned#42
fix: change parameter_values(::GraphSystemParameters) to access params_partitioned#42MasonProtter merged 7 commits intoNeuroblox:masterfrom
Conversation
|
Hm, no I don't think this is correct since the We might have to add an additional dispatch somewhere to avoid the stack overflow |
|
Like this? Doesn't handle the connections but will people be using More generally I wanted to ask what the idiomatic thing to do is when you need to change the parameters of a problem. Is it just to |
|
Yeah, we do use
Not really, I would just |
|
I think there's an issue when using EDIT: hm this happens if you try to directly setp the parameter object too. |
|
Oh, does that not currently error? We should be throwing an error when the user tries to change the type with julia> using ModelingToolkit
julia> using ModelingToolkit: t_nounits as t, D_nounits as D
julia> let
ps = @parameters a=1.0
vs = @variables x(t)=1.0
eqs = [D(x) ~ a*x]
@named sys = System(eqs, t)
prob = ODEProblem(structural_simplify(sys), [], (0.0, 1.0), [])
setp(prob, a)(prob, 2.0 + im)
end
ERROR: InexactError: Float64(2.0 + 1.0im)
Stacktrace:
[1] Real
@ ./complex.jl:44 [inlined]
[2] convert
@ ./number.jl:7 [inlined]
[3] setindex!
@ ./array.jl:985 [inlined]
[4] set_parameter!
@ ~/.julia/packages/ModelingToolkit/Aomff/src/systems/parameter_buffer.jl:364 [inlined]
[5] set_parameter!
@ ~/.julia/packages/SymbolicIndexingInterface/sZ3a9/src/value_provider_interface.jl:67 [inlined]
[6] SetParameterIndex
@ ~/.julia/packages/SymbolicIndexingInterface/sZ3a9/src/parameter_indexing.jl:699 [inlined]
[7] (::SymbolicIndexingInterface.ParameterHookWrapper{…})(prob::ODEProblem{…}, args::ComplexF64)
@ SymbolicIndexingInterface ~/.julia/packages/SymbolicIndexingInterface/sZ3a9/src/parameter_indexing.jl:667
[8] top-level scope
@ REPL[24]:7
Some type information was truncated. Use `show(err)` to see complete types.
|
|
Ah OK. Yeah it just silently doesn't change it at the moment, I can add that to this PR. What's the way to change a parameter type then? |
|
|
|
What about type promotion? MTKParameters can promote like 2 to a Float64 because it's an array but is there a way to do that with our SubsystemParameters? |
| end | ||
| function set_param_prop(s::SubsystemParams{T}, key, val; allow_typechange=false) where {T} | ||
| set_param_prop(s, NamedTuple{(key,)}(val); allow_typechange) | ||
| set_param_prop(s, NamedTuple{(key,)}((val,)); allow_typechange) |
There was a problem hiding this comment.
This bit is to allow values to be iterators because previously it was trying to splat them and that was erroring
| @test_broken begin | ||
| (prob, :particle1₊m)(prob, 20) | ||
| @test getp(prob, :particle1₊m)(prob) === 20.0 | ||
| end |
There was a problem hiding this comment.
We'll want to support stuff like setting an Int where the value is actually a Float64, but it's a little complicated. Lets do that in a followup PR and just get this merged first.
I ran into an issue where it would stack overflow whenever I try to
setpon aGraphSystemParametersobject, becauseset_parameter!(sys, val, idx)is implemented asset_parameter!(parameter_values(sys), val, idx)in SII, butparameter_values(::GraphSystemParameters)just returns itself. So this change fixes that recursion. But I am not sure if the semantics ofparameter_valuesremains correct in this case.