henry2004y / TestParticle.jl

Test particle tracing in electromagnetic field
https://henry2004y.github.io/TestParticle.jl/dev/
MIT License
14 stars 3 forks source link

Instability detected in `is_time_dependent` #97

Closed henry2004y closed 8 months ago

henry2004y commented 8 months ago

The current implementation of is_time_dependent is type unstable, most likely due to the usage of methods: https://github.com/henry2004y/TestParticle.jl/blob/fd5d83ee3e2e6cd77c589dde1e44660517c90a9c/src/TestParticle.jl#L171-L186

One way to keep type stability is to mark the function with Base.@pure or Base.@assume_effects :total. However, this approach does not work with precompile.jl. Based on the Discourse discussion, methods() has world age problems with either Base.@pure or Base.@assume_effects. I don't know the details about this issue, but I don't like this solution.


There is an alternative way of checking number of args:

function is_time_dependent(f::Function)
   applicable(f, zeros(6), 0.0) ? true : false
end

Maybe let's switch to this method first and see how it works.

TCLiuu commented 8 months ago

This is a very simple and applicable solution.