Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link

Summary

This PR improves interface compliance with SciML's array/number interface guidelines by making the Reaction and MaterialSource structs parametric:

  • Reaction{T<:Real} now allows arbitrary numeric types for stoichiometry (ν::Vector{T})
  • MaterialSource{T<:Real, R<:Reaction} now allows arbitrary numeric types for molar weights (Mw::Vector{T})

Interface Issues Found and Fixed

Issue 1: Hardcoded Float64 in Reaction struct

# Before
struct Reaction
    ν::Vector{Float64}  # Hardcoded Float64
    ...
end

# After
struct Reaction{T<:Real}
    ν::Vector{T}        # Parameterized
    ...
end

Issue 2: Hardcoded Float64 in MaterialSource struct

# Before
struct MaterialSource <: AbstractMaterialSource
    Mw::Vector{Float64}        # Hardcoded Float64
    reaction::Vector{Reaction} # Non-parametric
    ...
end

# After
struct MaterialSource{T<:Real, R<:Reaction} <: AbstractMaterialSource
    Mw::Vector{T}       # Parameterized
    reaction::Vector{R} # Parameterized reaction type
    ...
end

Testing Performed

  1. BigFloat compatibility: Verified that Reaction and MaterialSource can now be created with BigFloat arrays without type conversion
  2. Float32 compatibility: Verified that Float32 arrays work correctly
  3. Backward compatibility: Verified that existing code using Float64 continues to work unchanged
  4. Added interface tests: New test file test/interface_tests.jl tests all numeric type variants

Notes on JLArray/GPU Compatibility

This package uses ModelingToolkit for symbolic equation building. GPU compatibility for the actual ODE solving would be handled at the solver level (DifferentialEquations.jl), not in this package. The scalar indexing used in the package occurs during symbolic equation construction, not during numeric computation.

Test plan

  • Run julia --project=. -e 'using Test; include("test/interface_tests.jl")' - all 21 tests pass
  • CI tests should pass (note: existing tests have pre-existing failures unrelated to this PR)

cc @ChrisRackauckas

🤖 Generated with Claude Code

Make the `Reaction` and `MaterialSource` structs parametric to support
arbitrary numeric types (e.g., BigFloat, Float32) instead of hardcoded
Float64. This improves interface compliance with SciML's array/number
interface guidelines.

Changes:
- `Reaction{T<:Real}` now has `ν::Vector{T}` instead of `Vector{Float64}`
- `MaterialSource{T<:Real, R<:Reaction}` now has `Mw::Vector{T}` and
  `reaction::Vector{R}` instead of hardcoded Float64 types
- Updated MaterialSource constructor to properly infer type parameters
- Added interface compatibility tests for BigFloat, Float32, and Float64

This change is backward compatible - existing code using Float64 arrays
will continue to work unchanged.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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