You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My project has been stuck on Symbolics 5.2.0 because I ran into an error after trying to upgrade to 5.3.0. It no longer allowed me to use a registered function to return a vector of values to a variable that is defined as a vector.
I realize I am falling behind getting the newest versions of other packages in the SciML ecosystem so I can no longer put off figuring out this issue.
A simple example using Modeling toolkit below functions properly when below using a version of Symbolics less than 5.3.0. The error is due to change in version 5.2.0 to 5.3.0 where Broadcast.materialize was changed to Broadcase.copy v5.2.0...v5.3.0
due to another issue #882
The dummy script that works for 5.2.0 but fails on 5.3.0
using ModelingToolkit, NonlinearSolve
function vec_return(T, n)
return [T for _ in 1:n]
end
@register_symbolic vec_return(T, n)::Vector{Float64}
nx=3
Tx=500.0
vars = @variables (x[1:nx], a, b, c)
pars = @parameters (n=nx, T=Tx)
eqs = [
x .~ vec_return(T, n)
a ~ 1 + x[1]
b ~ 2 + x[2]
c ~ 3 + x[3]
]
@named sys = NonlinearSystem(eqs, [vars...;], pars)
guess = [x[1] => 1, x[2] => 1, x[3] => 1,
a => 1, b => 1, c => 1]
prob = NonlinearProblem(sys, guess, [])
sol = solve(prob, NewtonRaphson())
I'm surprised you ever had a vector return work with that. @register_symbolic always assumed a scalar output. You need to update this to @register_array_symbolic for array functions and it should be fine.
Ok I see that is was added in 5.13.0. Thanks for letting me know!
I am trying to test the script on 5.13.0, but I am still getting stumped with figuring out the exact implementation. I think I am closely following the example near line 530 in the MTK test file
If you don't mind taking a peak below and offering some guidance, would be much appreciated.
function vec_return(T, n)
[T, T, T]
end
@register_array_symbolic vec_return(T, n) begin
size=(3,)
eltype=promote_type(eltype(T), eltype(n)) #=optional?, fails to build eqs if I do not specify this=#
end
nx=3.0
Tx=500.0
vars = @variables (x[1:3], a, b, c)
pars = @parameters (n=nx, T=Tx)
eqs = [
x ~ vec_return(T, n)
a ~ 1 + x[1]
b ~ 2 + x[2]
c ~ 3 + x[3]
]
@show eqs
@named sys = NonlinearSystem(eqs, vars, pars)
guess = [x[1] => 1, x[2] => 1, x[3] => 1,
a => 1, b => 1, c => 1]
prob = NonlinearProblem(sys, guess, [])
sol = solve(prob, NewtonRaphson())
Hello,
My project has been stuck on
Symbolics 5.2.0
because I ran into an error after trying to upgrade to5.3.0
. It no longer allowed me to use a registered function to return a vector of values to a variable that is defined as a vector.I realize I am falling behind getting the newest versions of other packages in the
SciML
ecosystem so I can no longer put off figuring out this issue.A simple example using Modeling toolkit below functions properly when below using a version of
Symbolics
less than5.3.0
. The error is due to change in version5.2.0
to5.3.0
whereBroadcast.materialize
was changed toBroadcase.copy
v5.2.0...v5.3.0
due to another issue #882
The dummy script that works for 5.2.0 but fails on 5.3.0
The result with Symbolics 5.2.0
The result with Symbolics 5.3.0
Is there anyway to make a change in my code to allow this or can the previous functionality of 5.2.0 be re-added to Symbolics src code?
Thanks.
The text was updated successfully, but these errors were encountered: