-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The IfLifting
pass doesn't seem to be working quite right
#3369
Comments
I want to reopen this because The MWE is found in the BlockComponents. Simple checkout the I'm pretty confident I'm not doing anything wrong here (all I'm doing is enabling the additional pass). |
@maxesit can you please look at pulling a MWE out of the tests, ideally in MTK? |
This would be the MWE, contains the @mtiller-jh is there a way to locally turn off the automatic file generation? I'm unable to change any of the generated .jl files, because as soon as I save them, they get regenerated. Because of this, I wasn't able to check what was the exact error that you had, but this is what I got with the MWE: Results:
Code: using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
# Cosine
@component function Cosine(; name, start_time=0, offset=0, amplitude=nothing, frequency=nothing, phase=nothing)
params = @parameters begin
(start_time::Float64 = start_time)
(offset::Float64 = offset)
(amplitude::Float64 = amplitude)
(frequency::Float64 = frequency)
(phase::Float64 = phase)
end
vars = @variables begin
y(t), [output = true]
end
eqs = Equation[
y ~ ifelse(start_time < t, offset + amplitude * cos(2 * pi * frequency * (t - start_time) + phase), offset)
]
return ODESystem(eqs, t, vars, params; systems = [], name)
end
export Cosine
# Integrator
@component function Integrator(; name, x0=0, k=1)
params = @parameters begin
(x0::Float64 = x0), [description = "Initial value of the integrator state"]
(k::Float64 = k), [description = "Gain"]
end
vars = @variables begin
u(t), [input = true]
y(t), [output = true]
x(t), [description = "State of Integrator"]
end
initialization_eqs = [
x ~ x0
]
eqs = Equation[
D(x) ~ k * u
y ~ x
]
return ODESystem(eqs, t, vars, params; systems = [], name, initialization_eqs)
end
export Integrator
# Cosine Test
@component function CosineTest(; name)
systems = @named begin
integrator = Integrator()
signal = Cosine(amplitude=1, frequency=2, start_time=0.5, offset=0.5, phase=3.14)
end
eqs = Equation[
signal.y ~ integrator.u
]
return ODESystem(eqs, t, [], []; systems, name)
end
export CosineTest
## Testset for the Cosine Test
using OrdinaryDiffEqDefault
using Test
@testset "Running test case1 for CosineTest" begin
@named model_full = CosineTest()
# Error with IfLifting
model = structural_simplify(model_full; additional_passes=[ModelingToolkit.IfLifting])
u0 = []
prob = ODEProblem(model, u0, (0, 5))
sol = solve(prob, DefaultODEAlgorithm())
@test SciMLBase.successful_retcode(sol)
@test sol[model.signal.y][1] ≈ 0.5 atol = 0.001
@test sol[model.signal.y][end] ≈ -0.49999 atol = 0.001
@test sol[model.integrator.x][end] ≈ 2.45255 atol = 0.001
end |
I'll go through the models 1 by 1 to find the ones that error, pull one of them out and post the MWE here. I have to leave home now, so first thing in the morning! |
All, I revisited the errors I'm seeing and I realized that the current error I'm experiencing (after resolving the issue with the macro) is the error that @maxesit has reproduced but that is actually just a failure of the regression testing. In other words, the However, there does seem to be a different issue lurking somewhere here. With |
Describe the bug 🐞
If I add
additional_passes=[IfLifting]
to an@mtkbuild
call, I get an error.Expected behavior
I would not expect to get an error message.
Minimal Reproducible Example 👇
Clone https://github.com/JuliaComputing/BlockComponents and checkout the
mmt/if-lifting
branch. Attempt to run]test
and you'll get:Error & Stacktrace⚠️
Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: