Keno / SIUnits.jl

Efficient unit-checked computation
Other
70 stars 26 forks source link

SIUnits.jl as a dependency? #87

Closed ChrisRackauckas closed 8 years ago

ChrisRackauckas commented 8 years ago

I am wondering about what the effects of SIUnits as a dependency would be for DifferentialEquations.jl. First of all, the only reason it would be necessary would be for these lines of code:

    if typeof(Δt) <: SIUnits.SIQuantity
      Δt = Δt.val
    end

a few of those. I just need to make dimensionless a few quantities that have units before passing them to the solver, and couldn't find a good way to do so without having SIUnits itself. If there's a fix for that, the problem is moot (at least for me).

The problem is that it looks like this package overloads things like +,-,etc. Is there any performance impact? This is a package which is looking to get good performance using a lot of math repeatedly, so it wouldn't make sense to add something that has even a small impact if it effects the vast majority of uses for a small minority use.

However, I may add it as a conditional dependency... is there a way of knowing that a number has units without having SIUnits imported, so that I can import SIUnits as necessary (I have the conditional import part down, just not the way to check for unit'd values without the imports)

tomasaschan commented 8 years ago

I know that you closed this already, but I would say that things like making DifferentialEquations.jl unitful is exactly why this package exists in the first place. As long as all the relevant math operators are implemented for the unitful quantities in this package, they should Just Work(TM) in DifferentialEquations.jl without changes to that package; furthermore, passing floats or whatever native types should still be just as fast as before. The beauty of Julia is that this is quite easy to accomplish - just leave the type specifications on your functions as open as possible, and Julia will sort the rest out (and throw errors if someone tries to send in values that don't implement all the math, for example).

ChrisRackauckas commented 8 years ago

Yes. I noticed I read the +,-,etc. overloading wrong. It mostly does just work in DifferentialEquations.jl, just like all of the other number systems! (The only difference is the timestepping has to be dimensionless because you step forward by percentages of dt in Runge-Kutta methods, but this was easy to fix). The only thing I want to fix up is plotting #86 which is really just about getting the dispatch right for the recipes. Then I'll merge the branch I have which has everything working with SIUnits.jl which is mentioned here: ChrisRackauckas/DifferentialEquations.jl#34.

It's a lightweight enough dependency that I'll just be requiring it. Nice work.