Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

This PR fixes issue #36 by addressing two related problems:

  1. Added ifelse helper function for MATLAB

    • MATLAB doesn't have a built-in ifelse function, but Symbolics.jl generates code using ifelse(cond, a, b) for the MATLABTarget()
    • We now define ifelse = @(cond, a, b) cond .* a + ~cond .* b; in MATLAB before evaluating the generated code
    • This allows symbolic ifelse expressions (like ifelse(a > 0, -a, a)) to work correctly
  2. Updated ModelingToolkit compat to support versions 8, 9, 10, 11

    • The original error TypeError: non-boolean (Num) used in boolean context was fixed in newer ModelingToolkit/Symbolics versions
    • Added compatibility shim for the states -> unknowns API rename (v9+)

Background

The original issue used this MWE:

using MATLABDiffEq
using ModelingToolkit
using OrdinaryDiffEq
@variables t
@variables a(t) = 1.0
D = Differential(t)
@named sys = ODESystem([D(a) ~ ifelse(a>0.0,-a,a)])
prob = ODEProblem(sys, [], (0.0,1.0))
solve(prob, MATLABDiffEq.ode15s())

Which failed with TypeError: non-boolean (Num) used in boolean context.

Test plan

  • CI tests should pass (MATLAB not available in CI, but syntax was verified)
  • Manual testing with MATLAB required to fully verify the fix

cc @ChrisRackauckas

🤖 Generated with Claude Code

This PR fixes issue SciML#36 by:

1. Adding an `ifelse` helper function definition in MATLAB
   - MATLAB doesn't have a built-in `ifelse` function, but Symbolics.jl
     generates code using `ifelse(cond, a, b)` for the MATLAB target
   - We now define `ifelse = @(cond, a, b) cond .* a + ~cond .* b;`
     before evaluating the generated MATLAB code

2. Updating ModelingToolkit compat to support versions 8, 9, 10, 11
   - The original error "TypeError: non-boolean (Num) used in boolean context"
     was fixed in newer ModelingToolkit/Symbolics versions
   - Added compatibility shim for the `states` -> `unknowns` API change

Fixes SciML#36

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@ChrisRackauckas ChrisRackauckas merged commit 0a71d7f into SciML:master Dec 29, 2025
1 of 2 checks passed
@ChrisRackauckas-Claude
Copy link
Contributor Author

CI Failure Analysis

The CI failure is NOT related to my changes. The Downgrade workflow is failing due to a dependency resolution issue:

ERROR: Unsatisfiable requirements detected for package RecursiveArrayTools [731186ca]:
 RecursiveArrayTools [731186ca] log:
 ├─possible versions are: 0.16.0-3.42.1 or uninstalled
 └─restricted to versions 2.39.0 by an explicit requirement — no versions left

Looking at recent CI runs on master, the same failure occurs:

  • Recent master runs (20565352669, 20565346985) also show failure status

This appears to be a pre-existing CI configuration issue with the julia-downgrade-compat action creating unsatisfiable constraints.

The actual code changes are:

  1. Added ifelse helper function for MATLAB (MATLAB doesn't have built-in ifelse)
  2. Added compatibility shim for states -> unknowns API rename in ModelingToolkit v9+
  3. Updated ModelingToolkit compat to support versions 8-11

These changes are straightforward and syntactically correct (verified via Meta.parse).

cc @ChrisRackauckas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants