Closed chris-hampel-CA closed 7 months ago
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())
The eqs print as:
eqs = Any[(broadcast(~, x, Main.var"##mock test#292".vec_return(T, n)))[1], (broadcast(~, x, Main.var"##mock test#292".vec_return(T, n)))[2], (broadcast(~, x, Main.var"##mock test#292".vec_return(T, n)))[3], a ~ 1 + x[1], b ~ 2+ x[2], c ~ 3 + x[3]]
The error is:
LoadError: MethodError: no method matching -(::SymbolicUtils.BasicSymbolic{Any}, ::SymbolicUtils.BasicSymbolic{Real})
Does anything look blatantly incorrect in the implementation when using @register_array_symbolic
in your mind? Thanks.
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 theSciML
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
https://github.com/JuliaSymbolics/Symbolics.jl/compare/v5.2.0...v5.3.0 due to another issue https://github.com/JuliaSymbolics/Symbolics.jl/issues/882The 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.