-
Notifications
You must be signed in to change notification settings - Fork 87
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
Incompatibility with DynamicQuantities.jl #688
Comments
I think there are three potential solutions:
Cheers, |
Thank you all for reporting the issue. We will take a look at it, and probably implement approach (1) as suggested. @mikeingold do you have any comment regarding Unitful.jl versus DynamicQuantities.jl for coordinate types? |
I just took another look through the stack trace. For the expression Vec(coords::NTuple{Dim,T}) where {Dim,T} = new{Dim,float(T)}(coords) I took a quick look through Unitful to get a sense of how this works for that package. I didn't see a |
I’ve been using Unitful types for a while but DynamicQuantities seems like it has a better architecture for dimensional types moving forward. It’s getting more popular but has required some work in tracking down these kinds of compatibility issues. |
Do you have a specific reason to prefer DynamicQuantities.jl in the case of coordinates? Did you experience better performance with distance, area, or other geometric calculations? |
I was going to link you to this Discourse thread for it but it looks like you've already seen it, so providing as reference here for anyone interested. I've been implementing it in some of my packages and seen some significant performance improvements. I discovered this while testing a new testing package for composing Meshes with QuadGK to compute line integrals over 1-Dim polytopes. You can see a some usage examples in the |
I don't see any real reason why the current Vec struct can't contain a DQ
Quantity type, so this specific hurdle seems like it could be solved by
just implementing another constructor. I'm not on a terminal at the moment,
but maybe we could just add a modified method something like the following?
Vec(coords::NTuple{Dim,T}) where {Dim,T<:AbstractQuantity} =
new{Dim,T}(coords)
…On Wed, Jan 17, 2024 at 11:40 AM Júlio Hoffimann ***@***.***> wrote:
Do you have a specific reason to prefer DynamicQuantities.jl in the case
of coordinates? Did you experience better performance with distance, area,
or other geometric calculations?
—
Reply to this email directly, view it on GitHub
<#688 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA657OVL6IRIY6CIZM4FQFDYO75HXAVCNFSM6AAAAABB6PU452VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJWGE4DSMJSGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Looks like the Point constructor just wraps a Vec, a similarly other types
like the polytopes mostly just wrap Point's, so I don't see any obvious
hurdles that we'd run into once the Vec{Dim,Quantity} is constructed.
On Wed, Jan 17, 2024 at 2:02 PM Michael Ingold ***@***.***>
wrote:
… I don't see any real reason why the current Vec struct can't contain a DQ
Quantity type, so this specific hurdle seems like it could be solved by
just implementing another constructor. I'm not on a terminal at the moment,
but maybe we could just add a modified method something like the following?
Vec(coords::NTuple{Dim,T}) where {Dim,T<:AbstractQuantity} =
new{Dim,T}(coords)
On Wed, Jan 17, 2024 at 11:40 AM Júlio Hoffimann ***@***.***>
wrote:
> Do you have a specific reason to prefer DynamicQuantities.jl in the case
> of coordinates? Did you experience better performance with distance, area,
> or other geometric calculations?
>
> —
> Reply to this email directly, view it on GitHub
> <#688 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AA657OVL6IRIY6CIZM4FQFDYO75HXAVCNFSM6AAAAABB6PU452VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJWGE4DSMJSGE>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
@MilesCranmer Do you think this could be a good candidate for a DQ extension? I suspect that at least this specific issue could be addressed with something like the suggested |
Yeah, sure! |
Ok, that idea might have been a little too optimistic. I forked DQ and added an extension for Meshes. What I didn't consider was that it doesn't seem like we can access the special |
This might be because |
If it does, then you could do for (type, _, _) in ABSTRACT_QUANTITY_TYPES
@eval Vec(coords::NTuple{Dim,T}) where {Dim,T<:$type} = Vec{Dim,T}(coords)
end which is the same thing as doing |
I tried again with the suggestion to reduce |
Ah yeah you're right, this prevents it: struct Vec{Dim,T} <: StaticVector{Dim,T}
coords::NTuple{Dim,T}
Vec(coords::NTuple{Dim,T}) where {Dim,T} = new{Dim,float(T)}(coords)
end Actually one thing we can easily do in DynamicQuantities.jl is simply implement float(::Type{Q}) where {T,D,Q<:AbstractQuantity{T,D}} = with_type_parameters(Q, float(T), D) Since I believe this does not violate any rules about identity (which is why we can't safely define Edit 2: actually this would work. Let me try again... |
I actually just got a workaround implemented as a DQ extension in my fork here. It's a bit of a hack, as it circumvents the The "solution" I came up with was essentially to shadow |
I think I might have found a way to fix the root cause here – SymbolicML/DynamicQuantities.jl#110 do you want to try this out? It looks like But in principle there's no reason we can't just implement |
Well, no need for the hacky workaround. I just set up a temp environment with just Meshes and the |
Awesome! Okay I'll merge that one then. Let me know if there are any other issues that come up |
Based on this new development I’m marking this issue as closed. I’m planning to continue testing and integrating with these two packages and will let you guys know if I run into other snags. |
Background
DynamicQuantities.jl defines
Quantity
s, like those in Unitful.jl, that are statically-typed to avoid issues like type instability. Instead of the dimensions of aQuantity
being stored in the type-domain they're stored in the value-domain.Issue
Meshes.jl doesn't currently compose with DynamicQuantities.jl because
zero(::Type)
for theseQuantity
s doesn't have access to the dimensions stored in the value (not in the type). This is mentioned in a currently-open Issue over there.A similar Issue came up previously in composition of DynamicQuantities.jl and QuadGK.jl over implementation of
one
vsoneunit
. It's not obvious to me whether the solution for this current issue would need to be implemented in which package (or both).MWE
Example error stack trace
The text was updated successfully, but these errors were encountered: