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
In a fresh Julia REPL I can setup a model using @mtkmodel and have some of the parameters as intervals (from IntervalArithmetics.jl). However if I then run the code again and change it to a normal (non-interval) parameter i get a TypeError. However, if I start another fresh REPL and run the code witha normal parameter, it works. And by changing it to an interval, it doesn't work. So depending in what order I run it, they both work. In my case it happens for the parameters, R, L, k, J, f but not the other two.
Expected behavior
Since both of them work with a fresh Julia REPL I would expect them to work if I simply change the parameter. The order should not matter.
Minimal Reproducible Example 👇
I tried to create a smaller example but then it worked for some reason. This is an example in the ModelingToolkitStandardLibrary documentation.
using ModelingToolkit
using ModelingToolkit: t_nounits as t
using IntervalArithmetic
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkitStandardLibrary.Mechanical.Rotational
@mtkmodel DCMotor begin@parametersbegin
R =0.5# first run this and then add ±0.1 and run again to get the error,(or the other way around) [description = "Armature resistance"] # Ohm
L =4.5e-3, [description ="Armature inductance"] # H
k =0.5±0.01, [description ="Motor constant"] # N.m/A
J =0.02, [description ="Inertia"] # kg.m²
f =0.01, [description ="Friction factor"] # N.m.s/rad
tau_L_step =-0.3, [description ="Amplitude of the load torque step"] # N.m
u_max=1end@componentsbegin
ground =Ground()
source =Voltage()
ref = Blocks.Step(height =1, start_time =0)
pi_controller = Blocks.LimPI(k =1.1, T =0.035, u_max = u_max, Ta =0.035)
feedback = Blocks.Feedback()
R1 =Resistor(R = R)
L1 =Inductor(L = L,i=0)
emf =EMF(k = k)
fixed =Fixed()
load =Torque()
load_step = Blocks.Step(height = tau_L_step, start_time =3)
inertia =Inertia(J = J, phi =0.0, w =0.0)
friction =Damper(d = f)
speed_sensor =SpeedSensor()
end@equationsbeginconnect(fixed.flange, emf.support, friction.flange_b)
connect(emf.flange, friction.flange_a, inertia.flange_a)
connect(inertia.flange_b, load.flange)
connect(inertia.flange_b, speed_sensor.flange)
connect(load_step.output, load.tau)
connect(ref.output, feedback.input1)
connect(speed_sensor.w, :y, feedback.input2)
connect(feedback.output, pi_controller.err_input)
connect(pi_controller.ctr_output, :u, source.V)
connect(source.p, R1.p)
connect(R1.n, L1.p)
connect(L1.n, emf.p)
connect(emf.n, source.n, ground.g)
endend@named model =DCMotor()
Hi! This issue is partially due to a relatively recent addition to the underlying symbolic manipulation infrastructure. We now have a global cache of expression trees, and when creating a new one we look to see if an identical tree already exists. This checking of "are these trees identical" uses isequal, and IntervalArithmetic does not allow comparing Intervals with anything else via isequal, so the symbolic manipulation library has no way to check "are these two things equal".
Thus, the order of evaluation bug happens because when running the model with k = 0.5±0.01, the cached tree stores 0.5±0.01. When trying to re-create it with k = 0.5 it tries to compare the two and fails when comparing isequal(0.5, 0.5±0.01). If you restart the REPL the cache is cleared. The first expression created works, and the second expression fails due to the equality check failing.
Describe the bug 🐞
In a fresh Julia REPL I can setup a model using @mtkmodel and have some of the parameters as intervals (from IntervalArithmetics.jl). However if I then run the code again and change it to a normal (non-interval) parameter i get a TypeError. However, if I start another fresh REPL and run the code witha normal parameter, it works. And by changing it to an interval, it doesn't work. So depending in what order I run it, they both work. In my case it happens for the parameters, R, L, k, J, f but not the other two.
Expected behavior
Since both of them work with a fresh Julia REPL I would expect them to work if I simply change the parameter. The order should not matter.
Minimal Reproducible Example 👇
I tried to create a smaller example but then it worked for some reason. This is an example in the ModelingToolkitStandardLibrary documentation.
Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
Additional context
The text was updated successfully, but these errors were encountered: