Skip to content

Conversation

ChrisRackauckas
Copy link
Member

Summary

  • Add DataStructures.jl v0.19 compatibility to Project.toml
  • Fix deprecated function calls for v0.19 compatibility:
    • Replace enqueue! with push!
    • Replace dequeue! with popfirst!
    • Replace IntDisjointSets with IntDisjointSet
    • Add proper import for IntDisjointSet

Test plan

  • Updated Project.toml compat entry
  • Fixed all deprecated DataStructures function calls
  • Added necessary imports
  • CI tests pass

🤖 Generated with Claude Code

@ChrisRackauckas
Copy link
Member Author

This one probably needs to wait.

claude and others added 3 commits October 8, 2025 09:20
- Replace enqueue! with push!
- Replace dequeue! with popfirst!
- Replace IntDisjointSets with IntDisjointSet
- Import IntDisjointSet to fix compilation

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

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas ChrisRackauckas force-pushed the update-datastructures-v0.19 branch from 2acb404 to ea30297 Compare October 8, 2025 09:20
Copy link
Contributor

github-actions bot commented Oct 8, 2025

Benchmark Results (Julia vlts)

Time benchmarks
master ea30297... master / ea30297...
ODEProblem 0.0831 ± 0.0059 s 0.0855 ± 0.0069 s 0.972 ± 0.1
init 0.0571 ± 0.0014 ms 0.0571 ± 0.0015 ms 0.999 ± 0.036
large_parameter_init/ODEProblem 1.05 ± 0.0032 s 1.04 ± 0.0038 s 1.01 ± 0.0048
large_parameter_init/init 0.107 ± 0.0023 ms 0.107 ± 0.0021 ms 0.998 ± 0.03
mtkcompile 0.034 ± 0.00074 s 0.0358 ± 0.0011 s 0.951 ± 0.036
time_to_load 4.94 ± 0.023 s 5.01 ± 0.018 s 0.985 ± 0.0059
Memory benchmarks
master ea30297... master / ea30297...
ODEProblem 0.606 M allocs: 20.6 MB 0.606 M allocs: 20.7 MB 0.999
init 0.892 k allocs: 0.0463 MB 0.892 k allocs: 0.0463 MB 1
large_parameter_init/ODEProblem 4.3 M allocs: 0.166 GB 4.33 M allocs: 0.168 GB 0.991
large_parameter_init/init 1.74 k allocs: 0.0858 MB 1.74 k allocs: 0.0858 MB 1
mtkcompile 0.237 M allocs: 8.75 MB 0.237 M allocs: 8.75 MB 1
time_to_load 0.153 k allocs: 14.5 kB 0.153 k allocs: 14.5 kB 1

Copy link
Contributor

github-actions bot commented Oct 8, 2025

Benchmark Results (Julia v1)

Time benchmarks
master ea30297... master / ea30297...
ODEProblem 0.0914 ± 0.0071 s 0.0893 ± 0.006 s 1.02 ± 0.11
init 0.0437 ± 0.011 ms 0.0439 ± 0.011 ms 0.996 ± 0.35
large_parameter_init/ODEProblem 1.26 ± 0.043 s 1.2 ± 0.039 s 1.05 ± 0.05
large_parameter_init/init 0.0775 ± 0.017 ms 0.0764 ± 0.018 ms 1.01 ± 0.33
mtkcompile 0.0374 ± 0.0011 s 0.0365 ± 0.0017 s 1.03 ± 0.057
time_to_load 4.66 ± 0.04 s 4.67 ± 0.049 s 0.998 ± 0.014
Memory benchmarks
master ea30297... master / ea30297...
ODEProblem 0.616 M allocs: 19.7 MB 0.616 M allocs: 19.7 MB 1
init 0.797 k allocs: 30.9 kB 0.797 k allocs: 30.9 kB 1
large_parameter_init/ODEProblem 4.58 M allocs: 0.166 GB 4.54 M allocs: 0.165 GB 1.01
large_parameter_init/init 1.64 k allocs: 0.0598 MB 1.64 k allocs: 0.0598 MB 1
mtkcompile 0.242 M allocs: 8.3 MB 0.242 M allocs: 8.3 MB 1
time_to_load 0.151 k allocs: 11.5 kB 0.151 k allocs: 11.5 kB 1

@ChrisRackauckas-Claude
Copy link

Updated PR to support both DataStructures v0.18 and v0.19

I've modified the PR to maintain backward compatibility with DataStructures v0.18 while adding support for v0.19. The changes use compile-time version checking with @static if to select the appropriate APIs.

Changes Made:

  1. Project.toml (line 101):

    • Changed: DataStructures = "0.19"
    • To: DataStructures = "0.18, 0.19"
  2. src/ModelingToolkit.jl (lines 32-37):

    • Added conditional imports based on DataStructures version
    • v0.19: imports IntDisjointSet
    • v0.18: imports IntDisjointSets and creates alias const IntDisjointSet = IntDisjointSets
  3. src/systems/alias_elimination.jl (lines 429-455):

    • Added conditional Queue operations:
      • v0.19: push!(q, x) and popfirst!(q)
      • v0.18: enqueue!(q, x) and dequeue!(q)

Testing:

✅ Package successfully instantiated and precompiled with DataStructures v0.19.1
✅ All changes use @static if pkgversion(DataStructures) >= v"0.19" for compile-time branching

Note:

The commit is ready in /tmp/mtk_clone but I don't have push permissions to the branch. The changes need to be pushed by someone with write access to the repository.

Patch file available at: /tmp/0001-Add-version-branching-for-DataStructures-v0.18-and-v.patch

@ChrisRackauckas-Claude
Copy link

Instructions to Apply the Changes

The changes have been committed locally but cannot be pushed due to permission restrictions. Here's how to apply them:

Option 1: Apply the patch file

# Download the patch
curl -O https://gist.githubusercontent.com/ChrisRackauckas-Claude/[GIST_ID]/raw/0001-Add-version-branching-for-DataStructures-v0.18-and-v.patch

# Or manually create it from the diff below and save as changes.patch

# Apply the patch
git checkout update-datastructures-v0.19
git am < changes.patch
git push origin update-datastructures-v0.19

Option 2: Manual file edits

1. Project.toml (line 101)
-DataStructures = "0.19"
+DataStructures = "0.18, 0.19"
2. src/ModelingToolkit.jl (lines 31-37)
 using DataStructures
-import DataStructures: IntDisjointSet
+@static if pkgversion(DataStructures) >= v"0.19"
+    import DataStructures: IntDisjointSet
+else
+    import DataStructures: IntDisjointSets
+    const IntDisjointSet = IntDisjointSets
+end
3. src/systems/alias_elimination.jl (3 locations)

Location 1 (line ~429):

     q = Queue{Int}(neqs)
     for (i, d) in enumerate(degrees)
-        d == 0 && push!(q, i)
+        @static if pkgversion(DataStructures) >= v"0.19"
+            d == 0 && push!(q, i)
+        else
+            d == 0 && enqueue!(q, i)
+        end
     end

Location 2 (line ~441):

     while !isempty(q)
-        𝑠eq = popfirst!(q)
+        @static if pkgversion(DataStructures) >= v"0.19"
+            𝑠eq = popfirst!(q)
+        else
+            𝑠eq = dequeue!(q)
+        end

Location 3 (line ~451):

         for 𝑑eq in 𝑑neighbors(graph, var)
             degree = degrees[𝑑eq] = degrees[𝑑eq] - 1
-            degree == 0 && push!(q, 𝑑eq)
+            @static if pkgversion(DataStructures) >= v"0.19"
+                degree == 0 && push!(q, 𝑑eq)
+            else
+                degree == 0 && enqueue!(q, 𝑑eq)
+            end
         end

Complete Patch File

Click to expand full patch
diff --git a/Project.toml b/Project.toml
index 3a005fedec..abea2786b5 100644
--- a/Project.toml
+++ b/Project.toml
@@ -98,7 +98,7 @@ CommonSolve = "0.2.4"
 Compat = "3.42, 4"
 ConstructionBase = "1"
 DataInterpolations = "7, 8"
-DataStructures = "0.19"
+DataStructures = "0.18, 0.19"
 DeepDiffs = "1"
 DelayDiffEq = "5.61"
 DiffEqBase = "6.189.1"
diff --git a/src/ModelingToolkit.jl b/src/ModelingToolkit.jl
index dd8562340c..6c79eb4fb1 100644
--- a/src/ModelingToolkit.jl
+++ b/src/ModelingToolkit.jl
@@ -29,7 +29,12 @@ using LinearAlgebra, SparseArrays
 using InteractiveUtils
 using JumpProcesses
 using DataStructures
-import DataStructures: IntDisjointSet
+@static if pkgversion(DataStructures) >= v"0.19"
+    import DataStructures: IntDisjointSet
+else
+    import DataStructures: IntDisjointSets
+    const IntDisjointSet = IntDisjointSets
+end
 using Base.Threads
 using Latexify, Unitful, ArrayInterface
 using Setfield, ConstructionBase
diff --git a/src/systems/alias_elimination.jl b/src/systems/alias_elimination.jl
index f23a863782..dc25378b4a 100644
--- a/src/systems/alias_elimination.jl
+++ b/src/systems/alias_elimination.jl
@@ -426,20 +426,32 @@ function topsort_equations(eqs, unknowns; check = true)
 
     q = Queue{Int}(neqs)
     for (i, d) in enumerate(degrees)
-        d == 0 && push!(q, i)
+        @static if pkgversion(DataStructures) >= v"0.19"
+            d == 0 && push!(q, i)
+        else
+            d == 0 && enqueue!(q, i)
+        end
     end
 
     idx = 0
     ordered_eqs = similar(eqs, 0)
     sizehint!(ordered_eqs, neqs)
     while !isempty(q)
-        𝑠eq = popfirst!(q)
+        @static if pkgversion(DataStructures) >= v"0.19"
+            𝑠eq = popfirst!(q)
+        else
+            𝑠eq = dequeue!(q)
+        end
         idx += 1
         push!(ordered_eqs, eqs[𝑠eq])
         var = assigns[𝑠eq]
         for 𝑑eq in 𝑑neighbors(graph, var)
             degree = degrees[𝑑eq] = degrees[𝑑eq] - 1
-            degree == 0 && push!(q, 𝑑eq)
+            @static if pkgversion(DataStructures) >= v"0.19"
+                degree == 0 && push!(q, 𝑑eq)
+            else
+                degree == 0 && enqueue!(q, 𝑑eq)
+            end
         end
     end

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.

3 participants