Skip to content

Commit 32cd1e5

Browse files
Remove unused cse keyword throughout ModelingToolkitBase
`cse` was threaded through the `*Function` constructors, `generate_*` helpers, `build_function_wrapper`, `build_explicit_observed_function`, the SCC/optimal- control/homotopy paths, and the `ObservedFunctionCache` (as a `Bool` field), but nothing ever consumed it: it was only ever forwarded down to `Symbolics.codegen_function`, which does not accept it (the IR codegen path has no `cse` option). Common-subexpression elimination in the current pipeline is unrelated to this flag. Remove it everywhere in ModelingToolkitBase: constructor/helper keywords, the `ObservedFunctionCache` field (and its constructor, `deepcopy`, and call operator), and the documentation bullets. Symbolics' own `cse` (which *is* used by `Symbolics.Code.cse`) is unaffected, as are the `##cse#` generated variable names. Constructors that take `kwargs...` remain backwards compatible (a stray `cse=` is absorbed and dropped as before). The one exception is `SymbolicIndexingInterface.observed`, which has no `kwargs...`: passing `cse=` there now errors instead of being silently ignored. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent ff06009 commit 32cd1e5

22 files changed

Lines changed: 97 additions & 106 deletions

lib/ModelingToolkitBase/src/problems/bvproblem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@fallback_iip_specialize function SciMLBase.BVProblem{iip, spec}(
22
sys::System, op, tspan;
3-
check_compatibility = true, cse = true,
3+
check_compatibility = true,
44
checkbounds = false, eval_expression = false, eval_module = @__MODULE__,
55
expression = Val{false}, guesses = Dict(), callback = nothing,
66
kwargs...
@@ -19,21 +19,21 @@
1919
fode, u0,
2020
p = process_SciMLProblem(
2121
ODEFunction{_iip, spec}, sys, _op; guesses,
22-
t = tspan !== nothing ? tspan[1] : tspan, check_compatibility = false, cse,
22+
t = tspan !== nothing ? tspan[1] : tspan, check_compatibility = false,
2323
checkbounds, time_dependent_init = false, expression, kwargs...
2424
)
2525

2626
fcost = generate_bvp_cost(
2727
sys; expression = Val{false}, wrap_gfw = Val{false},
28-
eval_expression, eval_module, cse, checkbounds
28+
eval_expression, eval_module, checkbounds
2929
)
3030

3131
stidxmap = Dict([v => i for (i, v) in enumerate(dvs)])
3232
u0_idxs = has_alg_eqs(sys) ? collect(1:length(dvs)) :
3333
[stidxmap[k] for (k, v) in op if haskey(stidxmap, k)]
3434
fbc = generate_boundary_conditions(
3535
sys, u0, u0_idxs, tspan[1]; expression = Val{false},
36-
wrap_gfw = Val{true}, cse, checkbounds
36+
wrap_gfw = Val{true}, checkbounds
3737
)
3838

3939
n_controls = length(default_codegen_inputs(sys))

lib/ModelingToolkitBase/src/problems/daeproblem.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
sys::System; u0 = nothing, p = nothing, tgrad = false, jac = false,
33
t = nothing, eval_expression = false, eval_module = @__MODULE__, sparse = false,
44
steady_state = false, checkbounds = false, sparsity = false, analytic = nothing,
5-
simplify = false, cse = true, initialization_data = nothing,
5+
simplify = false, initialization_data = nothing,
66
expression = Val{false}, check_compatibility = true, kwargs...
77
) where {iip, spec}
88
check_complete(sys, DAEFunction)
99
check_compatibility && check_compatible_system(DAEFunction, sys)
1010

1111
f = generate_rhs(
1212
sys; expression, wrap_gfw = Val{true},
13-
implicit_dae = true, eval_expression, eval_module, checkbounds = checkbounds, cse,
13+
implicit_dae = true, eval_expression, eval_module, checkbounds = checkbounds,
1414
kwargs...
1515
)
1616

@@ -28,15 +28,15 @@
2828
if jac
2929
_jac = generate_dae_jacobian(
3030
sys; expression,
31-
wrap_gfw = Val{true}, simplify, sparse, cse, eval_expression, eval_module,
31+
wrap_gfw = Val{true}, simplify, sparse, eval_expression, eval_module,
3232
checkbounds, kwargs...
3333
)
3434
else
3535
_jac = nothing
3636
end
3737

3838
observedfun = ObservedFunctionCache(
39-
sys; expression, steady_state, eval_expression, eval_module, checkbounds, cse
39+
sys; expression, steady_state, eval_expression, eval_module, checkbounds
4040
)
4141

4242
jac_prototype = if sparse

lib/ModelingToolkitBase/src/problems/ddeproblem.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
@fallback_iip_specialize function SciMLBase.DDEFunction{iip, spec}(
22
sys::System; u0 = nothing, p = nothing, eval_expression = false,
33
eval_module = @__MODULE__, expression = Val{false}, checkbounds = false,
4-
initialization_data = nothing, cse = true, check_compatibility = true,
4+
initialization_data = nothing, check_compatibility = true,
55
sparse = false, simplify = false, analytic = nothing, kwargs...
66
) where {iip, spec}
77
check_complete(sys, DDEFunction)
88
check_compatibility && check_compatible_system(DDEFunction, sys)
99

1010
f = generate_rhs(
1111
sys; expression, wrap_gfw = Val{true},
12-
eval_expression, eval_module, checkbounds = checkbounds, cse,
12+
eval_expression, eval_module, checkbounds = checkbounds,
1313
kwargs...
1414
)
1515

@@ -28,7 +28,7 @@
2828
_M = concrete_massmatrix(M; sparse, u0)
2929

3030
observedfun = ObservedFunctionCache(
31-
sys; expression, eval_expression, eval_module, checkbounds, cse
31+
sys; expression, eval_expression, eval_module, checkbounds
3232
)
3333

3434
kwargs = (;
@@ -45,7 +45,7 @@ end
4545

4646
@fallback_iip_specialize function SciMLBase.DDEProblem{iip, spec}(
4747
sys::System, op, tspan;
48-
callback = nothing, check_length = true, cse = true, checkbounds = false,
48+
callback = nothing, check_length = true, checkbounds = false,
4949
eval_expression = false, eval_module = @__MODULE__, check_compatibility = true,
5050
u0_constructor = identity, expression = Val{false}, kwargs...
5151
) where {iip, spec}
@@ -56,13 +56,13 @@ end
5656
f, u0,
5757
p = process_SciMLProblem(
5858
DDEFunction{_iip, spec}, sys, op;
59-
t = tspan !== nothing ? tspan[1] : tspan, check_length, cse, checkbounds,
59+
t = tspan !== nothing ? tspan[1] : tspan, check_length, checkbounds,
6060
eval_expression, eval_module, check_compatibility, symbolic_u0 = true,
6161
expression, u0_constructor, kwargs...
6262
)
6363

6464
h = generate_history(
65-
sys, u0; expression, wrap_gfw = Val{true}, cse, eval_expression, eval_module,
65+
sys, u0; expression, wrap_gfw = Val{true}, eval_expression, eval_module,
6666
checkbounds
6767
)
6868

lib/ModelingToolkitBase/src/problems/discreteproblem.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@fallback_iip_specialize function SciMLBase.DiscreteFunction{iip, spec}(
22
sys::System; u0 = nothing, p = nothing, t = nothing,
33
eval_expression = false, eval_module = @__MODULE__, expression = Val{false},
4-
checkbounds = false, analytic = nothing, simplify = false, cse = true,
4+
checkbounds = false, analytic = nothing, simplify = false,
55
initialization_data = nothing, check_compatibility = true,
66
kwargs...
77
) where {iip, spec}
@@ -10,7 +10,7 @@
1010

1111
f = generate_rhs(
1212
sys; expression, wrap_gfw = Val{true},
13-
eval_expression, eval_module, checkbounds = checkbounds, cse,
13+
eval_expression, eval_module, checkbounds = checkbounds,
1414
kwargs...
1515
)
1616

@@ -26,8 +26,7 @@
2626
end
2727

2828
observedfun = ObservedFunctionCache(
29-
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds,
30-
cse
29+
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds
3130
)
3231

3332
kwargs = (;

lib/ModelingToolkitBase/src/problems/docs.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ function function_docstring(
248248
$EVAL_EXPR_MOD_KWARGS
249249
- `checkbounds`: Whether to enable bounds checking in the generated code.
250250
- `simplify`: Whether to `simplify` any symbolically computed jacobians/hessians/etc.
251-
- `cse`: Whether to enable Common Subexpression Elimination (CSE) on the generated code.
252251
This typically improves performance of the generated code but reduces readability.
253252
- `sparse`: Whether to generate jacobian/hessian/etc. functions that return/operate on
254253
sparse matrices. Also controls whether the mass matrix is sparse, wherever applicable.
@@ -387,7 +386,6 @@ subtype indicating the level of specialization of the $func.
387386
$EVAL_EXPR_MOD_KWARGS
388387
- `checkbounds`: Whether to enable bounds checking in the generated code.
389388
- `simplify`: Whether to `simplify` any symbolically computed jacobians/hessians/etc.
390-
- `cse`: Whether to enable Common Subexpression Elimination (CSE) on the generated code.
391389
This typically improves performance of the generated code but reduces readability.
392390
- `fraction_cancel_fn`: The function to use to simplify fractions in the polynomial
393391
expression. A more powerful function can increase processing time but be able to

lib/ModelingToolkitBase/src/problems/implicitdiscreteproblem.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@fallback_iip_specialize function SciMLBase.ImplicitDiscreteFunction{iip, spec}(
22
sys::System; u0 = nothing, p = nothing, t = nothing, eval_expression = false,
33
eval_module = @__MODULE__, expression = Val{false},
4-
checkbounds = false, analytic = nothing, simplify = false, cse = true,
4+
checkbounds = false, analytic = nothing, simplify = false,
55
initialization_data = nothing, check_compatibility = true, kwargs...
66
) where {
77
iip, spec,
@@ -13,7 +13,7 @@
1313
dvs = unknowns(sys)
1414
f = generate_rhs(
1515
sys; expression, wrap_gfw = Val{true},
16-
implicit_dae = true, eval_expression, eval_module, checkbounds = checkbounds, cse,
16+
implicit_dae = true, eval_expression, eval_module, checkbounds = checkbounds,
1717
override_discrete = true, kwargs...
1818
)
1919

@@ -31,7 +31,7 @@
3131
end
3232

3333
observedfun = ObservedFunctionCache(
34-
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds, cse
34+
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds
3535
)
3636

3737
args = (; f)

lib/ModelingToolkitBase/src/problems/intervalnonlinearproblem.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
function SciMLBase.IntervalNonlinearFunction(
22
sys::System; u0 = nothing, p = nothing, eval_expression = false,
33
eval_module = @__MODULE__, expression = Val{false}, checkbounds = false,
4-
analytic = nothing, cse = true, initialization_data = nothing,
4+
analytic = nothing, initialization_data = nothing,
55
check_compatibility = true, kwargs...
66
)
77
check_complete(sys, IntervalNonlinearFunction)
88
check_compatibility && check_compatible_system(IntervalNonlinearFunction, sys)
99

1010
f = generate_rhs(
1111
sys; expression, wrap_gfw = Val{true},
12-
scalar = true, eval_expression, eval_module, checkbounds, cse, kwargs...
12+
scalar = true, eval_expression, eval_module, checkbounds, kwargs...
1313
)
1414

1515
observedfun = ObservedFunctionCache(
16-
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds,
17-
cse
16+
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds
1817
)
1918

2019
args = (; f)

lib/ModelingToolkitBase/src/problems/jumpproblem.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@fallback_iip_specialize function JumpProcesses.JumpProblem{iip, spec}(
22
sys::System, op, tspan::Union{Tuple, Nothing};
33
check_compatibility = true, eval_expression = false, eval_module = @__MODULE__,
4-
checkbounds = false, cse = true, aggregator = JumpProcesses.NullAggregator(),
4+
checkbounds = false, aggregator = JumpProcesses.NullAggregator(),
55
callback = nothing, rng = nothing, save_positions = (true, true), kwargs...
66
) where {iip, spec}
77
check_complete(sys, JumpProblem)
@@ -23,13 +23,13 @@
2323
if has_eqs && has_noise
2424
prob = SDEProblem{iip, spec}(
2525
sys, op, tspan; check_compatibility = false,
26-
build_initializeprob = false, checkbounds, cse, check_length = false,
26+
build_initializeprob = false, checkbounds, check_length = false,
2727
_skip_events = true, _skip_tstops = true, kwargs...
2828
)
2929
elseif has_eqs
3030
prob = ODEProblem{iip, spec}(
3131
sys, op, tspan; check_compatibility = false,
32-
build_initializeprob = false, checkbounds, cse, check_length = false,
32+
build_initializeprob = false, checkbounds, check_length = false,
3333
_skip_events = true, _skip_tstops = true, kwargs...
3434
)
3535
else
@@ -41,7 +41,7 @@
4141
)
4242
observedfun = ObservedFunctionCache(
4343
sys; eval_expression, eval_module,
44-
checkbounds, cse
44+
checkbounds
4545
)
4646
f = (du, u, p, t) -> (du .= 0; nothing)
4747
df = ODEFunction{true, spec}(f; sys, observed = observedfun)
@@ -51,12 +51,12 @@
5151
_f, u0,
5252
p = process_SciMLProblem(
5353
EmptySciMLFunction{iip}, sys, op;
54-
t = tspan === nothing ? nothing : tspan[1], check_length = false, build_initializeprob = false, cse, kwargs...
54+
t = tspan === nothing ? nothing : tspan[1], check_length = false, build_initializeprob = false, kwargs...
5555
)
5656
f = DiffEqBase.DISCRETE_INPLACE_DEFAULT
5757

5858
observedfun = ObservedFunctionCache(
59-
sys; eval_expression, eval_module, checkbounds, cse
59+
sys; eval_expression, eval_module, checkbounds
6060
)
6161

6262
df = DiscreteFunction{true, true}(

lib/ModelingToolkitBase/src/problems/linearproblem.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Moshi.Derive.@derive StructuralHint[Show]
2222
function LinearFunction{iip}(
2323
sys::System; expression = Val{false}, check_compatibility = true,
2424
sparse = false, eval_expression = false, eval_module = @__MODULE__,
25-
checkbounds = false, cse = true,
25+
checkbounds = false,
2626
structural_hint::StructuralHint.Type = StructuralHint.NoHint(), kwargs...
2727
) where {iip}
2828
check_complete(sys, LinearProblem)
@@ -39,15 +39,14 @@ function LinearFunction{iip}(
3939
end
4040
update_A = generate_update_A(
4141
sys, A; expression, wrap_gfw = Val{true}, eval_expression,
42-
eval_module, checkbounds, cse, kwargs...
42+
eval_module, checkbounds, kwargs...
4343
)
4444
update_b = generate_update_b(
4545
sys, b; expression, wrap_gfw = Val{true}, eval_expression,
46-
eval_module, checkbounds, cse, kwargs...
46+
eval_module, checkbounds, kwargs...
4747
)
4848
observedfun = ObservedFunctionCache(
49-
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds,
50-
cse
49+
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds
5150
)
5251

5352
if expression == Val{true}

lib/ModelingToolkitBase/src/problems/nonlinearproblem.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
sys::System; u0 = nothing, p = nothing, jac = false,
33
eval_expression = false, eval_module = @__MODULE__, sparse = false,
44
checkbounds = false, sparsity = false, analytic = nothing,
5-
simplify = false, cse = true, initialization_data = nothing,
5+
simplify = false, initialization_data = nothing,
66
resid_prototype = nothing, check_compatibility = true, expression = Val{false},
77
kwargs...
88
) where {iip, spec}
@@ -11,7 +11,7 @@
1111

1212
f = generate_rhs(
1313
sys; expression, wrap_gfw = Val{true},
14-
eval_expression, eval_module, checkbounds = checkbounds, cse,
14+
eval_expression, eval_module, checkbounds = checkbounds,
1515
kwargs...
1616
)
1717

@@ -29,16 +29,15 @@
2929
if jac
3030
_jac = generate_jacobian(
3131
sys; expression,
32-
wrap_gfw = Val{true}, simplify, sparse, cse, eval_expression, eval_module,
32+
wrap_gfw = Val{true}, simplify, sparse, eval_expression, eval_module,
3333
checkbounds, kwargs...
3434
)
3535
else
3636
_jac = nothing
3737
end
3838

3939
observedfun = ObservedFunctionCache(
40-
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds,
41-
cse
40+
sys; steady_state = false, expression, eval_expression, eval_module, checkbounds
4241
)
4342

4443
if sparse

0 commit comments

Comments
 (0)