Skip to content

Commit 9535ba7

Browse files
feat: remove IfElse support
1 parent 87df269 commit 9535ba7

File tree

12 files changed

+19
-24
lines changed

12 files changed

+19
-24
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@
4949
`(single_parameter => expression_involving_other_parameters)` and a `Vector` of these can be passed to
5050
the `parameter_dependencies` keyword argument of `ODESystem`, `SDESystem` and `JumpSystem`. The dependent
5151
parameters are updated whenever other parameters are modified, e.g. in callbacks.
52+
- Support for `IfElse.jl` has been dropped. `Base.ifelse` can be used instead.

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ FindFirstFunctions = "64ca27bc-2ba2-4a57-88aa-44e436879224"
2323
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
2424
FunctionWrappersWrappers = "77dc65aa-8811-40c2-897b-53d922fa7daf"
2525
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
26-
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"
2726
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
2827
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
2928
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
@@ -81,7 +80,6 @@ FindFirstFunctions = "1"
8180
ForwardDiff = "0.10.3"
8281
FunctionWrappersWrappers = "0.1"
8382
Graphs = "1.5.2"
84-
IfElse = "0.1"
8583
InteractiveUtils = "1"
8684
JuliaFormatter = "1.0.47"
8785
JumpProcesses = "9.1"

docs/src/basics/FAQ.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ pnew = varmap_to_vars([β => 3.0, c => 10.0, γ => 2.0], parameters(sys))
2424

2525
## How do I handle `if` statements in my symbolic forms?
2626

27-
For statements that are in the `if then else` form, use `IfElse.ifelse` from the
28-
[IfElse.jl](https://github.com/SciML/IfElse.jl) package to represent the code in a
29-
functional form. For handling direct `if` statements, you can use equivalent boolean
30-
mathematical expressions. For example, `if x > 0 ...` can be implemented as just
31-
`(x > 0) * `, where if `x <= 0` then the boolean will evaluate to `0` and thus the
32-
term will be excluded from the model.
27+
For statements that are in the `if then else` form, use `Base.ifelse` from the
28+
to represent the code in a functional form. For handling direct `if` statements,
29+
you can use equivalent boolean mathematical expressions. For example, `if x > 0 ...`
30+
can be implemented as just `(x > 0) * `, where if `x <= 0` then the boolean will
31+
evaluate to `0` and thus the term will be excluded from the model.
3332

3433
## ERROR: TypeError: non-boolean (Num) used in boolean context?
3534

src/ModelingToolkit.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ using PrecompileTools, Reexport
2727
using DocStringExtensions
2828
using Base: RefValue
2929
using Combinatorics
30-
import IfElse
3130
import Distributions
3231
import FunctionWrappersWrappers
3332
using URIs: URI

src/systems/unit_check.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#For dispatching get_unit
2-
const Conditional = Union{typeof(ifelse), typeof(IfElse.ifelse)}
2+
const Conditional = Union{typeof(ifelse)}
33
const Comparison = Union{typeof.([==, !=, , <, <=, , >, >=, ])...}
44

55
struct ValidationError <: Exception

src/systems/validation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module UnitfulUnitCheck
22

3-
using ..ModelingToolkit, Symbolics, SciMLBase, Unitful, IfElse, RecursiveArrayTools
3+
using ..ModelingToolkit, Symbolics, SciMLBase, Unitful, RecursiveArrayTools
44
using ..ModelingToolkit: ValidationError,
55
ModelingToolkit, Connection, instream, JumpType, VariableUnit,
66
get_systems,

test/domain_connectors.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using ModelingToolkit
22
using ModelingToolkit: t_nounits as t, D_nounits as D
33
using Test
4-
using IfElse: ifelse
54

65
@connector function HydraulicPort(; p_int, name)
76
pars = @parameters begin

test/downstream/linearize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ end
163163
function saturation(; y_max, y_min = y_max > 0 ? -y_max : -Inf, name)
164164
@variables u(t)=0 y(t)=0
165165
@parameters y_max=y_max y_min=y_min
166-
ie = ModelingToolkit.IfElse.ifelse
166+
ie = ifelse
167167
eqs = [
168168
# The equation below is equivalent to y ~ clamp(u, y_min, y_max)
169169
y ~ ie(u > y_max, y_max, ie((y_min < u) & (u < y_max), u, y_min))

test/dq_units.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelingToolkit, OrdinaryDiffEq, JumpProcesses, IfElse, DynamicQuantities
1+
using ModelingToolkit, OrdinaryDiffEq, JumpProcesses, DynamicQuantities
22
using Test
33
MT = ModelingToolkit
44
using ModelingToolkit: t, D

test/generate_custom_function.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using ModelingToolkit
22
using ModelingToolkit: t_nounits as t, D_nounits as D
3-
using IfElse
43

54
@variables x(t) y(t)[1:3]
65
@parameters p1=1.0 p2[1:3]=[1.0, 2.0, 3.0] p3::Int=1 p4::Bool=false
@@ -24,9 +23,9 @@ fn3_iip(buffer, u0, p, 1.0)
2423
@test buffer == [4.0, 6.0, 2.0, 3.0]
2524
@test fn3_oop(u0, p, 1.0) == [4.0, 6.0, 2.0, 3.0]
2625

27-
fn4 = generate_custom_function(sys, IfElse.ifelse(p4, p1, p2[2]); expression = Val(false))
26+
fn4 = generate_custom_function(sys, ifelse(p4, p1, p2[2]); expression = Val(false))
2827
@test fn4(u0, p, 1.0) == 2.0
29-
fn5 = generate_custom_function(sys, IfElse.ifelse(!p4, p1, p2[2]); expression = Val(false))
28+
fn5 = generate_custom_function(sys, ifelse(!p4, p1, p2[2]); expression = Val(false))
3029
@test fn5(u0, p, 1.0) == 1.0
3130

3231
@variables x y[1:3]
@@ -47,7 +46,7 @@ fn3_iip(buffer, u0, p)
4746
@test buffer == [4.0, 6.0, 2.0]
4847
@test fn3_oop(u0, p, 1.0) == [4.0, 6.0, 2.0]
4948

50-
fn4 = generate_custom_function(sys, IfElse.ifelse(p4, p1, p2[2]); expression = Val(false))
49+
fn4 = generate_custom_function(sys, ifelse(p4, p1, p2[2]); expression = Val(false))
5150
@test fn4(u0, p, 1.0) == 2.0
52-
fn5 = generate_custom_function(sys, IfElse.ifelse(!p4, p1, p2[2]); expression = Val(false))
51+
fn5 = generate_custom_function(sys, ifelse(!p4, p1, p2[2]); expression = Val(false))
5352
@test fn5(u0, p, 1.0) == 1.0

test/state_selection.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelingToolkit, OrdinaryDiffEq, IfElse, Test
1+
using ModelingToolkit, OrdinaryDiffEq, Test
22
using ModelingToolkit: t_nounits as t, D_nounits as D
33

44
sts = @variables x1(t) x2(t) x3(t) x4(t)
@@ -249,7 +249,7 @@ let
249249
Δp2 = p2
250250

251251
eqs = [+flow(xm, Δp1) ~ rho1 * dV1 + drho1 * V1
252-
0 ~ IfElse.ifelse(w > 0.5,
252+
0 ~ ifelse(w > 0.5,
253253
(0) - (rho2 * dV2 + drho2 * V2),
254254
(-flow(xm, Δp2)) - (rho2 * dV2 + drho2 * V2))
255255
V1 ~ (l_1f + w) * A_1f
@@ -265,7 +265,7 @@ let
265265
D(w) ~ dw
266266
D(dw) ~ ddw
267267
xf ~ 20e-3 * (1 - cos(2 * π * 5 * t))
268-
0 ~ IfElse.ifelse(w > 0.5,
268+
0 ~ ifelse(w > 0.5,
269269
(m_total * ddw) - (p1 * A_1f - p2 * A_2f - damp * dw),
270270
(m_total * ddw) - (p1 * A_1f - p2 * A_2f))]
271271
# ----------------------------------------------------------------------------

test/units.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModelingToolkit, OrdinaryDiffEq, JumpProcesses, IfElse, Unitful
1+
using ModelingToolkit, OrdinaryDiffEq, JumpProcesses, Unitful
22
using Test
33
MT = ModelingToolkit
44
UMT = ModelingToolkit.UnitfulUnitCheck
@@ -33,7 +33,7 @@ D = Differential(t)
3333
@test UMT.get_unit(t / τ) == UMT.unitless
3434
@test UMT.equivalent(UMT.get_unit(P - E / τ), u"MW")
3535
@test UMT.equivalent(UMT.get_unit(D(D(E))), u"MW/ms")
36-
@test UMT.get_unit(IfElse.ifelse(t > t, P, E / τ)) == u"MW"
36+
@test UMT.get_unit(ifelse(t > t, P, E / τ)) == u"MW"
3737
@test UMT.get_unit(1.0^(t / τ)) == UMT.unitless
3838
@test UMT.get_unit(exp(t / τ)) == UMT.unitless
3939
@test UMT.get_unit(sin(t / τ)) == UMT.unitless

0 commit comments

Comments
 (0)