-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Use Macros to define new variables #102
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes problem with AcceleratorLattice.
I am getting the error for atoms:
|
We can’t ignore the types or reassign constants, that is very dangerous and does not work. Instead @setunits should be called in the global scope of the package using AAPC, not in init. Then this will work just fine.Sent from my iPhoneOn Nov 19, 2024, at 10:16 PM, David Sagan ***@***.***> wrote:
I am getting the error for atoms:
julia> Species("He")
ERROR: type AtomicSpecies has no field mass_in_amu
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because your review was requested.Message ID: ***@***.***>
|
|
Allow macro to be set with keyword parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the latest code I get:
julia> using AtomicAndPhysicalConstants
Precompiling AtomicAndPhysicalConstants...
Info Given AtomicAndPhysicalConstants was explicitly requested, output will be shown live
┌ Warning: Symbol ħ was found in multiple registered unit modules.
│ We will use the one from AtomicAndPhysicalConstants.NewUnits.
└ @ Unitful ~/.julia/packages/Unitful/GYzMo/src/user.jl:715
┌ Warning: Symbol ħ was found in multiple registered unit modules.
│ We will use the one from AtomicAndPhysicalConstants.NewUnits.
└ @ Unitful ~/.julia/packages/Unitful/GYzMo/src/user.jl:715
┌ Warning: Symbol ħ was found in multiple registered unit modules.
│ We will use the one from AtomicAndPhysicalConstants.NewUnits.
└ @ Unitful ~/.julia/packages/Unitful/GYzMo/src/user.jl:715
... And lots more lines like this...
julia> f = Species("electron")
Species("electron", -1 e, 0.51099895069 MeV c⁻², 0.5 ħ, -9.2847646917e-24 J T⁻¹, 0)
julia> chargeof(f)
ERROR: UndefVarError: `chargeof` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Stacktrace:
[1] top-level scope
@ REPL[3]:1
Also if a "null"
species can be defined that would be helpful.
@DavidSagan Don't you need to call I'm not sure about the hbar thing though |
@mattsignorelli Yes I had forgot that. The package should be configured to throw an error message in this case that tells the user they need to use |
Also still getting the error:
|
That wouldn't work because |
@mattsignorelli Can dummy functions be defined initially with the |
One more point: The default for |
This is dangerous because then every package using AAPC will need to do type piracy on these functions |
One more problem:
The code in AL that triggers this is:
|
@mattsignorelli Since AAPC is controlling things, I would not call this type piracy. In this case, it is definitely not dangerous. From the Julia manual:
|
This is the problem, However @lllx125 the macro should just define |
I removed the |
@lllx125 You need to change |
Now setunits works as a macro that accepts a unit system and reassigns constants exported from AtomicAndPhysicalConstants with value in the proper unit.
Example:
@setunits MKS
This is because @setunits is called in init(), so I can't define constants in a function. However, this makes the constants type unstable.
The code should work properly if we ignore typing.