Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

fix: add DynamicQuantities extension for unitful factorization paths#1293

Merged
ChrisRackauckas merged 2 commits intoSciML:masterfrom
MilesCranmerBot:wave2-dq-compat
Mar 17, 2026
Merged

fix: add DynamicQuantities extension for unitful factorization paths#1293
ChrisRackauckas merged 2 commits intoSciML:masterfrom
MilesCranmerBot:wave2-dq-compat

Conversation

@MilesCranmerBot
Copy link
Copy Markdown
Contributor

Wave 2 (post-DynamicQuantities release) for the DynamicQuantities × SciML rollout.
Tracking issue: JuliaPhysics/DynamicQuantities.jl#200

What this changes

Adds ext/DiffEqBaseDynamicQuantitiesExt.jl to define DynamicQuantities-specific DiffEqBase behaviors:

  • unit-safe ODE_DEFAULT_NORM / UNITLESS_ABS2
  • timedepentdtmin and _rate_prototype handling for quantity times
  • value-space LU factorization bridge (DQUnitlessLU) for Rosenbrock/SDIRK Jacobian solves with quantity eltypes

This keeps factorization in numeric value-space while restoring output units consistently.

Test

  • julia --project=. -e 'using Pkg; Pkg.test()'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MilesCranmerBot I think you forgot to include unittests in this PR? Please add them and ensure 100% code coverage here.

@MilesCranmerBot
Copy link
Copy Markdown
Contributor Author

Added unit tests for the DynamicQuantities extension (incl. DQUnitlessLU factorization bridge + norm/time hooks) and wired the extension in Project.toml ([weakdeps]/[extensions]/[compat] + added DynamicQuantities to test target).

Local run: Pkg.test(; coverage=true).

Commit: 0bd73ec (pushed to wave2-dq-compat).

Comment on lines +43 to +67
function LinearAlgebra.ldiv!(
x::AbstractVector{<:UnionAbstractQuantity},
W::DQUnitlessLU,
b::AbstractVector{<:UnionAbstractQuantity},
)
vb = ustrip.(b)
vx = similar(vb)
LinearAlgebra.ldiv!(vx, W.F, vb)
@inbounds for i in eachindex(x)
x[i] = vx[i] * (oneunit(b[i]) * W.ut)
end
return x
end

function Base.:(\)(W::DQUnitlessLU, b::AbstractVector{<:UnionAbstractQuantity})
vb = ustrip.(b)
vx = W.F \ vb
out = similar(b)
@inbounds for i in eachindex(out)
out[i] = vx[i] * (oneunit(b[i]) * W.ut)
end
return out
end

end
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are piracy

Copy link
Copy Markdown

@MilesCranmer MilesCranmer Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DQUnitlessLU is defined above, so I think it's fine, no?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, okay.

@ChrisRackauckas ChrisRackauckas merged commit bac318c into SciML:master Mar 17, 2026
41 of 46 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants