Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No cachedrule for DynamicQuantities types #88

Closed
mikeingold opened this issue Sep 17, 2023 · 4 comments
Closed

No cachedrule for DynamicQuantities types #88

mikeingold opened this issue Sep 17, 2023 · 4 comments

Comments

@mikeingold
Copy link

I just started experimenting with the recent DynamicQuantities.jl package, which aims to provide the same functionality as Unitful.jl but with a statically-typed Quantity to improve performance. It looks like QuadGK currently doesn't support these DynamicQuantities Quantity types, but I'm not familiar enough with the codebase to quite understand why.

I'm interested in contributing by generating a PR for this, but would really appreciate a nudge in the right direction. It looks like the issue spawns from approximately here, where either a @generated cachedrule isn't being produced at compile-time or maybe the generic cachedrule below it isn't working.

Any ideas that might help me understand what I can do to help integrate this functionality?

Thanks,
Mike

Minimal reproduction (Julia v1.9.3):

julia> using DynamicQuantities  # [06fc5a27] DynamicQuantities v0.7.0

julia> using QuadGK  # [1fd47b50] QuadGK v2.8.2

julia> quadgk(t -> 5u"m/s"*t, 0u"s", 10u"s")
ERROR: MethodError: no method matching cachedrule(::Type{Quantity{Float64, Dimensions{DynamicQuantities.FixedRational{Int32, 25200}}}}, ::Int64)

Closest candidates are:
  cachedrule(::Union{Type{Complex{BigFloat}}, Type{BigFloat}}, ::Integer)
   @ QuadGK C:\Users\*\.julia\packages\QuadGK\XqIlh\src\gausskronrod.jl:253
  cachedrule(::Type{T}, ::Integer) where T<:Number
   @ QuadGK C:\Users\*\.julia\packages\QuadGK\XqIlh\src\gausskronrod.jl:264
@stevengj
Copy link
Member

stevengj commented Sep 17, 2023

You need to provide a way to strip the units from the type. Currently, we use:

cachedrule(::Type{T}, n::Integer) where {T<:Number} =
_cachedrule(typeof(float(real(one(T)))), Int(n))

which assumes that one(T) returns the underlying dimensionless numeric type.

See e.g. JuliaPhysics/Measurements.jl#134

@mikeingold
Copy link
Author

Thanks! I'll see what I can do to get these packages working together.

@stevengj
Copy link
Member

Closing in favor of SymbolicML/DynamicQuantities.jl#40

@mikeingold
Copy link
Author

Concur. Looks like this is due to DynamicQuantities’ current interpretation of the Base.one spec.

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

No branches or pull requests

2 participants