Git Product home page Git Product logo

Comments (6)

MilesCranmer avatar MilesCranmer commented on June 11, 2024

Hi @cadojo,

Thanks for the report. Excited to hear about the package you are making!

Is this Julia 1.10? Does it go away on Julia 1.9?

One thing to note is that the SymbolicDimensions symbols (e.g., us"m") don’t exist during precompilation. The reason for this is that there are so many, it makes startup time slow unless you are using them. So I wonder if it’s related to that.

Best,
Miles

from dynamicquantities.jl.

MilesCranmer avatar MilesCranmer commented on June 11, 2024

The quick fix would be to change

+ flux_distance(m, M) = 10^((m - M + 5) // 5) * u"Constants.pc"
- flux_distance(m, M) = 10^((m - M + 5) // 5) * us"Constants.pc"

us (SymbolicDimensions) is intended to be for display, whereas u (Dimensions) is intended to be for calculations.

us would not be available during precompilation because the variables are created upon first call. But maybe we can change that.

from dynamicquantities.jl.

cadojo avatar cadojo commented on June 11, 2024

Thanks Miles! I did change all instances of us"Constants.pc" to just Constants.pc, and that worked also. I'm using Julia 1.9 — my versioninfo() is shown below.

Julia Version 1.9.3
Commit bed2cd540a1 (2023-08-24 14:43 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin22.4.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
  Threads: 1 on 4 virtual cores

from dynamicquantities.jl.

MilesCranmer avatar MilesCranmer commented on June 11, 2024

Awesome. Okay I think we should go with that, what do you think? Then for display, I think @gaurav-arya has a good strategy proposed in #48

Basically, one can display units with as_u (name pending) e.g.,

u"Constants.pc" / 0.05 |> as_u(us"Constants.kpc)

which would display 0.02 kpc, even though the calculation happens with the faster Dimensions.

from dynamicquantities.jl.

cadojo avatar cadojo commented on June 11, 2024

Works for me, and I like the unit conversion feature and syntax. The |> is convenient. I also like the Unitful.uconvert syntax, I see some benefit to having multiple different methods for as_u so there are different options for converting one quantity's units to another: as_u(u"km", 100u"m") or 100u"m" |> as_u(u"km").

So all of this is good for display and for my purposes, but could this issue pop up again? If I understand correctly, symbolic units can't be used in any Julia package, because they're created on-the-fly. With native code cacheing in Julia v1.9 and later, I wonder how much slower the package would be if all of the symbolic units are created at once? If no one has done that experiment yet, and if there's interest in the future, I'd be interested in trying that out.

from dynamicquantities.jl.

MilesCranmer avatar MilesCranmer commented on June 11, 2024

Okay now this issue is fixed for real – please try it out! You can do, e.g.,

const my_unit = us"ohm"

just fine, and precompilation should be good

from dynamicquantities.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.