quantum-exeter / SpiDy.jl

:spider: Non-Markovian stochastic SPIn (and harmonic oscillator) DYnamics.
GNU General Public License v3.0
11 stars 2 forks source link

Make default distribution argument of bfield more explicit #2

Closed cerisola closed 2 years ago

cerisola commented 2 years ago

Currently, the bfield distribution argument takes a default value of nothing, i.e.

function bfield(N, Δt, J::GenericSD, noise::Noise, distro=nothing)
    if isnothing(distro)
        distro = Normal(0., 1/sqrt(Δt))
    end
   ...
end

which is then initialised to a Normal distribution as shown.

Apparently, Julia allows for default arguments to depend on the mandatory values. That is, something like this should work:

function bfield(N, Δt, J::GenericSD, noise::Noise, distro=Normal(0., 1/sqrt(Δt)))
   ...
end

If possible to do it this way, I think it would be an improvement as it would be clearer to the user what the default of nothing is actually doing.

mekise commented 2 years ago

Tested and working. Much nicer.