In yesterday’s notes you guys wrote:
- Particle Tracker
* What is easier to package
* Nick and I will review in tandem
* Which is faster.
* How difficult is it to put Julia in a pip-installed package?
* Topic came up because crew at BaPSF are looking into developing a Particle Tracker
And while I couldn’t be there in person, I think it’s a good call to keep this discussion up.
- Cython will be easier to package for a Python package. It’s not even close - the ecosystem is stable. I do still have to read up on PyJulia, and I’ve seen some packages include it, so it looks like it’s getting there.
- In a vacuum, Julia code is way easier to write than Cython code is.
- However, we’re not in a vacuum and some of our functionality is already in Python (mostly magnetostatics, etc). This is additional code we’d have to transfer to Julia, or call from Julia using PyCall.jl (at the risk of them being slow-ish).
- At the same time, I’m pretty sure Cython is going to be slower than Julia would, because the Cython compiler is not all that smart to optimize stuff, while a ton of effort is going into doing that in Julia.
- It might be a local news bubble effect, but it seems like everyone’s moving away from writing low level C code; writing stuff in Cython feels like doing exactly that.
There is a third option - numba, that might have been missing in that discussion. Numba’s neat because
- VERY easy packaging nowadays
- The code isn’t significantly harder to write
- Goes well with existing code
But it has its own set of issues, the chief of which is that you often can’t call Python code from JIT code, so you can’t do
with numba.jit: # not real syntax but bear with me for a minute for timestep in iterations: interpolate_fields_to_particles() # currently on scipy.interpolate push_particles() # JIT atm scatter_particle_charge() # hypothetical code for PIC recalculate_fields() # likewise
but instead you have to do this in a pure Python loop. This means that, instead of dropping from the Python interpreter into JIT code once, you drop in and out of it twice per loop execution. This is going to do terrible things to our performance, and I don’t want to do it that way.
So… I don’t know what the best call here is. There isn’t that much code we have in Python that ParticleTracker would rely on (like I said, magnetostatics mostly). Might be best to rewrite this stuff, honestly.