Closed astrojuanlu closed 3 years ago
Interesting, thanks for sharing! I have a backlog of other issues at the moment, so it might be a few weeks before I can check this branch out locally to compare the fast
files to the normal ones and see all that has changed. In the meantime I'll think about whether this is something that python-sgp4
itself can host and support indefinitely going forward, or whether I should encourage you to publish a separate Python package that would let you support directly the users that need this specially crafted version of the code.
To clarify: this helps the case where the C++ SGP4 fails to compile on a machine (or isn't available as a pre-compiled Python wheel), and the library falls back to doing pure Python?
Interesting, thanks for sharing! I have a backlog of other issues at the moment, so it might be a few weeks before I can check this branch out locally to compare the fast files to the normal ones and see all that has changed. In the meantime I'll think about whether this is something that python-sgp4 itself can host and support indefinitely going forward, or whether I should encourage you to publish a separate Python package that would let you support directly the users that need this specially crafted version of the code.
Excellent, thanks a lot!
To clarify: this helps the case where the C++ SGP4 fails to compile on a machine (or isn't available as a pre-compiled Python wheel), and the library falls back to doing pure Python?
It would be a way to have "native performance" without needing to compile C++. The trade-off here would be the installation of numba & llvmlite itself - they support a lot of platforms and produce binary wheels for several architectures, but I am not sure what's the intersection between "platforms in which C++ cannot be compiled or isn't available as pre-compiled wheel" and "platforms in which numba is available as pre-compiled wheel and doesn't require compiling LLVM".
(And about "native performance": I still didn't benchmark your C++ wrapper against my Numba version, but I will do it very soon)
(And about "native performance": I still didn't benchmark your C++ wrapper against my Numba version, but I will do it very soon)
Hey, @astrojuanlu! Looking at open issues and pull requests on my dashboard, I thought I'd circle back to this PR and start the conversation up again. Did you ever get a chance to check the performance against the C++ wrapper?
Looking back over the code, I suspect that this would work best as a separate project. It could be named “NumbaSGP4” or somesuch, and I could add a mention of it to the docs for folks who need (a) a faster-than-Python SGP4 module, but (b) can't install or compile the C++ version bundled here in this library.
The big reason I suspect this code doesn't belong here in this package is compatibility: sgp4
works to remain compatible with Python 2.7, whereas the syntax used by @jitclass
— which, wow, by the way, is really cool, I've never seen a class decorated with C types so succinctly in Python before! — weren't available until Python 3.5. As a separate Python package, your code would be able to state its Python 3.5 compatibility right in its metadata. But as a mere subdirectory fast/
in this package, it wouldn't carry its own metadata.
But maybe I'm being overly finicky? Since several months have passed since I was last able to take a look at it, let me know where things stand from your end, and we can figure out what to do with this PR. Thanks!
Hi @brandon-rhodes ! I ended up benchmarking the C++ wrapper as well, yes :) You can see that in https://github.com/astrojuanlu/sgp4-benchmarks/blob/master/benchmarks/test_cpp_wrapper.py, and the report is in https://opensatcom.org/2020/12/28/omm-assessment-sgp4-benchmarks/ (second link)
I understand your concerns and I'm fine with making this its own package. Besides, if it breaks for whatever reason people will complain here, but I fear I might not have enough free time available to maintain it (since the project started I have left the space industry... for a job at Read the Docs!).
I will close this PR without removing my branch, and will publish these changes as a standalone package with a different name.
Thanks a lot again @brandon-rhodes ! 🙌🏽
I understand your concerns and I'm fine with making this its own package.
Thanks for understanding why I don't want this package to take on a third SGP4 implementation! It’s always awkward to say “no” to a pull request that involved hard work that really accomplished something, so thanks for your gracious answer.
I have left the space industry... for a job at Read the Docs
WOW! Congratulations! I enjoyed the one Write the Docs conference I attended (in Portland), it was interesting to see how wide a community the effort has gathered, even outside of traditional programming documentation projects.
And, again, if you'd like to comment back here later with the package name (numba_sgp4
might be better than the name I suggested above, by the way), I'll be happy to add a mention in this package's README.
In gh-17 there was an attempt to accelerate the code using Numba, but as described in gh-46 after the change was released, it ended up making the code slower.
However, I am quite stubborn and was disappointed to see Numba go, so I gave it a try. I am happy to see that some basic tests pass, and that the code is 6.5x faster :tada:
This departs from gh-17 in three ways:
@jit(nopython=True)
or@njit
). In turn, this requires jitting more functions and making compilation times slower, but the resulting code should be way faster.Satrec
class had to be created using the experimental@jitclass
functionality.sgp4.fast
package. This of course is open to discussion, but made testing the code easier. The advantage is that, as compilation times are so slow (~5 seconds on my laptop) it's only worth it if the propagation is called many times.propagation.py
to simplify the error messages, and make them static. This is the only real code modification I had to make, everything else works.Some other comments:
ephtype
andrevnum
strings, but in the C++ code, they areint
andlong
respectively. I wonder if this difference is intentional :warning:np.datetime64
objects around, but not creating them in nopython mode https://github.com/numba/numba/issues/6555. Besides,datetime.datetime
objects are not supported at all. As a result, I didn't include an.epoch
attribute.Hope that this serves at least as a conversation starter on what would be the best way to add this functionality to python-sgp4.