SymbolicML / DynamicQuantities.jl

Efficient and type-stable physical quantities in Julia
https://symbolicml.org/DynamicQuantities.jl/dev/
Apache License 2.0
132 stars 17 forks source link

WIP: add methods for automatic unit conversion for SymbolicDimensions #63

Open MilesCranmer opened 11 months ago

MilesCranmer commented 11 months ago

cc @gaurav-arya

This makes it so that you can add 1.5us"km" with 1500us"m" and there won't be a dimension error. It will choose to convert to the leftmost dimension.

I'm not sure if that's the best thing to do though (maybe we should force users to stay in the same dimensions), so any thoughts appreciated!

e.g., this would make your chemistry example possible with symbolic dimensions throughout. You could add J and eV and not have it be converted to SI units.

github-actions[bot] commented 11 months ago

Benchmark Results

main 1590e79a93613b... t[main]/t[1590e79a93613b...]
Quantity/creation/Quantity(x) 4.4 ± 0.3 ns 3.6 ± 0.3 ns 1.22
Quantity/creation/Quantity(x, length=y) 4.5 ± 0.1 ns 4 ± 0.3 ns 1.12
Quantity/with_numbers/*real 3.8 ± 0.3 ns 3.8 ± 0.3 ns 1
Quantity/with_numbers/^int 13.7 ± 4.8 ns 12.7 ± 4.1 ns 1.08
Quantity/with_numbers/^int * real 14.1 ± 5.2 ns 14.1 ± 4.3 ns 1
Quantity/with_quantity/+y 7.6 ± 0.6 ns 9.3 ± 0.1 ns 0.817
Quantity/with_quantity//y 4.5 ± 0.1 ns 4.5 ± 0.4 ns 1
Quantity/with_self/dimension 1.9 ± 0.1 ns 1.9 ± 0.1 ns 1
Quantity/with_self/inv 4.5 ± 0.1 ns 4.1 ± 0.3 ns 1.1
Quantity/with_self/ustrip 2 ± 0.1 ns 1.9 ± 0.1 ns 1.05
QuantityArray/broadcasting/multi_array_of_quantities 0.269 ± 0.023 ms 0.268 ± 0.046 ms 1
QuantityArray/broadcasting/multi_normal_array 0.0902 ± 0.0071 ms 0.0927 ± 0.0074 ms 0.973
QuantityArray/broadcasting/multi_quantity_array 0.304 ± 0.024 ms 0.305 ± 0.023 ms 0.998
QuantityArray/broadcasting/x^2_array_of_quantities 0.0493 ± 0.0047 ms 0.0465 ± 0.0037 ms 1.06
QuantityArray/broadcasting/x^2_normal_array 10.1 ± 1.9 μs 10 ± 1.8 μs 1.01
QuantityArray/broadcasting/x^2_quantity_array 11.4 ± 1.1 μs 11.5 ± 1 μs 0.991
QuantityArray/broadcasting/x^4_array_of_quantities 0.16 ± 0.013 ms 0.158 ± 0.0046 ms 1.02
QuantityArray/broadcasting/x^4_normal_array 0.0818 ± 0.0068 ms 0.0818 ± 0.0062 ms 1
QuantityArray/broadcasting/x^4_quantity_array 0.123 ± 0.0096 ms 0.114 ± 0.013 ms 1.08
time_to_load 0.195 ± 0.00064 s 0.196 ± 0.00077 s 0.993

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).