-
Notifications
You must be signed in to change notification settings - Fork 4
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
Dependent Package of Morse Potential #3
Comments
Is there any reason not to add a dependency on SpecialFunctions.jl? |
Thank you for your question. No, there is not. I have already added it (Please check Project.toml. Is it correct?). The problem is that julia> using Antique
julia> MP1 = Antique.MorsePotential
Antique.MorsePotential
julia> MP2 = antique(:MorsePotential)
Base.Meta.MorsePotential1669411154543485985
julia> parentmodule(MP1)
Antique
julia> parentmodule(MP2)
Base.Meta The module |
Hm, I think we don't need metaprogramming for the features in this package. abstract type Model end
@kwdef struct InfinitePotentialWell{T<:Real} <: Model
L::T = 1.0
m::T = 1.0
ℏ::T = 1.0
end
# Potential
function V(model::InfinitePotentialWell{T}, x) where T
L = model.L
return 0<x<L ? zero(float(T)) : T(Inf)
end
# Wave Function
function ψ(model::InfinitePotentialWell{T}, x; n=1) where T
L = model.L
return 0<x<L ? sqrt(2/L) * sin(n*π*x/L) : zero(float(T))
end
# Energy
function E(model::InfinitePotentialWell; n=1)
m = model.m
L = model.L
ℏ = model.ℏ
return (ℏ^2*n^2*π^2) / (2*m*L^2)
end |
Thanks for the clarification! The |
Thank you for your suggestions. It is good example for me to learn Julia coding. I agree that your suggestion is the correct approach for Julia programming based on multiple dispatch. But I avoided this coding style for some reasons:
For the time being, this problem has been solved by replacing using Pkg
Pkg.rm("SpecialFunctions")
Pkg.rm("Antique")
Pkg.add(url="https://github.com/ohno/Antique.jl.git")
using Antique
MP = antique(:MorsePotential) And also thank you for your commnets about Project.toml. I will update it. |
I think we currently don't have a plan to migrate to other languages, right?
Julia does not have We can still use just
I don't quite understand this point. There will be no problems with
The dynamic code loading is not recommended for the following reasons.
|
Right. There are no definite plans. However, I am sure that someone (including me) will migrate to other languages because analytical solutions are important as benchmarks regardless of language. It is better that codes can be easily migrate to other language (especially Fortran, because I am often forced to use Fortran). I aimed for each module to be the reference implementation independent from the language. Actually, the portability it is just a bonus. The highest priority is on similarity between the code and the formulae. Because the language of physics is mathematical formulae. Programs should mimic mathematical formulae as much as possible. Other languages could not satisfy it. This is my request to Julia as a greedy Julia user. Be mathematical formulae!
I want to use class. The function
Yes. I meant that I multi-dispatch was not necessary if used within the scope of a module (I did not have enough words). Regardless of using multi-dispatch, functions will be concluded in one module for each model to help using
This comment has some new points of view for me. I offer one compromise to this problem. My key issues are following two about design philosophy:
Both of my answers are yes. |
IMO, mathematical coding is good for readability and has high priority only inside functions, however, other parts such as API (exported function names, type names, field names etc.) should not be mathematical symbols.
As I said before, a "model" does not have to own methods. Multiple dispatches can handle it. One good example is julia> using Random
julia> rng = Random.MersenneTwister(42)
MersenneTwister(42)
julia> rng isa AbstractRNG
true
julia> rand(rng)
0.5331830160438613 Of course in Python, In [1]: import numpy as np
In [2]: rng = np.random.default_rng(42)
In [3]: rng.random()
Out[3]: 0.7739560485559633 |
The initial problem has been resolved. We are discussing no longer the initial issue. I changed the title of issue from "Dependent Package of Morse Potential" to "Programming paradigm & style" for saving the logs. I will postpone the dicision about your points because there are currently no major problems. |
You can just close this issue and open a new issue 😄 |
In:
Out:
The text was updated successfully, but these errors were encountered: