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
Here is 2 bugs that I think are somewhat interlinked. First of when I structural_simplify a model where I set a vector variable to equal 'itself' in a different namespace in a connection, structural_simplify doesn't shift this connection to observed and instead thinks that these are equations it needs to solve. This is in direct contradiction to the expected behaviour and that which happens when the variable is instead a scalar. Below is an MWE I will use for the whole bug report.
using ModelingToolkit,DifferentialEquations
using ModelingToolkit: t_nounits as t, D_nounits as D
functioneq_factory(length;name)
@variablesy(t)[1:length]
@named dy =y_eq_template(length)
connections = [dy.rhs ~rhs_function_wrapper(length),
dy.y ~ y]
compose(ODESystem(connections,t;name),dy)
endfunctiony_eq_template(length;name)
@variablesy(t)[1:length] rhs(t)[1:length]
eqs =D(y) ~ rhs
ODESystem(eqs,t;name)
endfunctionrhs_function_wrapper(length)
@variablesy(t)[1:length]
@parameters a b
returnrhs_function(y,a,b,t)
endfunctionrhs_function(y::AbstractVector,a::Real,b::Real,t::Real)
return (y*a+b)./(t)
end@register_array_symbolicrhs_function(y::AbstractVector,a::Num,b::Num,t::Num) begin
size = (length(y),)
eltype =eltype(y)
end@named test_sys =eq_factory(10)
test_simp =structural_simplify(test_sys)
u0 = [test_simp.y=>zeros(10)]
p = [test_simp.a=>2,
test_simp.b=>5]
tspan=(0.0,10.0)
prob=ODEProblem(test_simp,u0,tspan,p)
#sol = solve(prob,Rosenbrock23();reltol=1e-3,abstol=1e-3)
When I look at the equations for test_simp, the output is as follows: The fact that the variable equals itself remains and there is no observed equations. Though as said earlier, this equation is a simple equality that should be moved to observed as far as I am aware, as is done for scalars.
This then leads to what I think is a following bug which is once I create the problem, the initial vector length is twice that of the provided one. Which I assume is because of something to do with the presence of the 0 ~ ... equation.
ODEProblem with uType Vector{Float64} and tType Float64. In-place:true
timespan: (0.0, 10.0)
u0:20-element Vector{Float64}:0.00.00.00.00.00.00.0⋮0.00.00.00.00.00.00.0
This is accompanied by a 'Warning: Internal error: Variable (y(t))[10] was marked as being in 0 ~ -(dy₊rhs(t))[10] + (rhs_function(y(t), a, b, t))[10], but was actually zero' performed n*n times where n is the length of y. This is I think because register symbolic wants the whole vector provided at each solve call. This is of course not required for this example but in my real work, I need the whole array sending for each individual vector point so that is why it is a registerd_symbolic_array like this.
Environment (please complete the following information):
Status `C:\Users\u5522838\OneDrive\PhD\LightMatter.jl\Project.toml`
[6e4b80f9] BenchmarkTools v1.5.0
[8bb1440f] DelimitedFiles v1.9.1
[39dd38d3] Dierckx v0.5.3
[0c46a032] DifferentialEquations v7.13.0
[f6369f11] ForwardDiff v0.10.36
[615f187c] IfElse v0.1.1
[de52edbc] Integrals v4.4.1
[961ee093] ModelingToolkit v9.32.0
[91a5bcdd] Plots v1.40.5
[f2b01f46] Roots v2.1.6
[90137ffa] StaticArrays v1.9.7
⌅ [0c5d862f] Symbolics v5.36.0
[1986cc42] Unitful v1.21.0
Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated`
Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
Here is 2 bugs that I think are somewhat interlinked. First of when I structural_simplify a model where I set a vector variable to equal 'itself' in a different namespace in a connection, structural_simplify doesn't shift this connection to observed and instead thinks that these are equations it needs to solve. This is in direct contradiction to the expected behaviour and that which happens when the variable is instead a scalar. Below is an MWE I will use for the whole bug report.
When I look at the equations for test_simp, the output is as follows: The fact that the variable equals itself remains and there is no observed equations. Though as said earlier, this equation is a simple equality that should be moved to observed as far as I am aware, as is done for scalars.
This then leads to what I think is a following bug which is once I create the problem, the initial vector length is twice that of the provided one. Which I assume is because of something to do with the presence of the 0 ~ ... equation.
This is accompanied by a 'Warning: Internal error: Variable (y(t))[10] was marked as being in 0 ~ -(dy₊rhs(t))[10] + (rhs_function(y(t), a, b, t))[10], but was actually zero' performed n*n times where n is the length of y. This is I think because register symbolic wants the whole vector provided at each solve call. This is of course not required for this example but in my real work, I need the whole array sending for each individual vector point so that is why it is a registerd_symbolic_array like this.
Environment (please complete the following information):
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: