I've started using Numba to speed up MD simulations for our course in Molecular Statistics, which I teach together with +Jan Jensen and +Jimmy Charnley Kromann.
One exercise is using the Velo-Verlet algorithm to simulate a Lennard-Jones gas/liquid with periodic boundary conditions. Since we do everything in Python in this course, running the actual simulation is quite slow. What we do is we supply the students with a compiled FORTRAN module, compiled with F2PY which they can use when they've written their own Lennard-Jones gradient code.
The FORmula TRANslator module is extremely fast, compared to Python code. I rewrote the code from last year's course to a function I could use with Numba and compare directly to the F2PY module
For 100 particles:
- Numba: 0.146 ms/iteration (466x speed up)
- F2PY: 0.236 ms/iteration (289x speed up)
- Python: 68.06 ms/iteration
Now, there were a few issues I discovered:
1) @autojit vs. @jit(argtypes=[double[:,:], double[:]])
Since Numba has to decide what arguments a function takes before it's being compiled, it needs to know what possible type of arguments the function takes. If you're lucky, Numba decides on the right type and you can get away with @autojit, but sometimes autojitting makes the code SLOWER than standard, interpreted Python. In one case I got a factor of 10x slower with autojit, but explicitly stating the function argument types with @jit(argtypes = .... ) I got a speed up of 20x on the same code compared to interpreted Python.
2) Returning tuples in compiled code block
Numba does not allow a tuple to be returned inside a compiled code block. So don't do this.
3) Use Numpy properly
- Numba is NumPy aware, so code ran faster when numbers were stored in numpy.array types rather than just regular Python lists.
- At first I was numpy.round() to round to nearest integer in the periodic boundary condition code. Switching three numpy.round() calls to numpy.rint() gave a speed up of around 100x on the code execution.
- Use U[i, j] instead of U[i][j] on NumPy arrays. Not much of a difference in the vanilla Python code, but MASSIVE speed gains in compiled code.
Python Lennard-Jones code:
F2PY Lennard-Jones code:
Python Velo-Verlet solver:
This information was very useful to me and I thank you for this.keep sharing more like this.
ReplyDeleteccna course in Chennai
ccna institute in Chennai
Python course in Chennai
Python Training Institute in Chennai
Angularjs course in Chennai
ccna Training in Anna nagar
ccna Training in T nagar
This was a wondereful post being shared. The entire content in this blog is extremely helpful for me and gave me a clear idea on the concepts.
ReplyDeletegerman classes in mulund
german language classes in mulund
german classes in mulund west
German Course in Mulund East
French Classes in Mulund
French Classes in Mulund East
French Classes in Mulund West
French Language Classes in Mulund
Fabulous post admin, it was too good and helpful. Waiting for more updates.
ReplyDeleteAWS Training in Chennai
DevOps Training in Chennai
Data Science Course in Chennai
Blue Prism Training in Chennai
R Programming Training in Chennai
RPA Training in Chennai
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing.
ReplyDeleteDigital Marketing Training in Chennai
Digital Marketing Course in Chennai
CCNA Training in Chennai
DevOps Training in Chennai
SEO Training in Chennai
Digital Marketing Training in Anna Nagar
Digital Marketing Training in T Nagar
english to telugu typing
ReplyDeleteNice blog. I finally found great post here Very interesting to read this article and very pleased to find this site. Great work!
ReplyDeleteCyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
thanks for posting.valuable information about numpy and other stuffs
ReplyDeletehttps://thoughtsonqa.blogspot.com/2013/11/5-ways-to-screw-up-application-security.html?showComment=1614953609364#c8638992903928140269
computational biochemistry in a effective way.Thanks for blogging
ReplyDeletePython Training in chennai | Python Classes in Chennai
Awesome post Python Training in Chennai
ReplyDeleteAimore Technologies is the best Selenium training institute in Chennai with 6+ years of experience. We are offering online and classroom training.
ReplyDeleteVisit Us: Selenium Training in Chennai
Thank you for sharing this valuable information with us.
ReplyDeleteThirukkural pdf free download
Sai Satcharitra in English pdf
Sai Satcharitra in Tamil pdf
Sai Satcharitra in bengali pdf
Sai Satcharitra in gujarati pdf
Much obliged for sharing this brilliant substance. its extremely fascinating. Numerous web journals I see these days don't actually give whatever pulls in others however the manner in which you have plainly clarified everything it's truly awesome. There are loads of posts But your method of Writing is so Good and Knowledgeable. continue to post such helpful data and view my site too...
ReplyDeletehow to make a paper airplane eagle | how to make a boomerang airplane | the eagle paper airplane | best paper airplane design for distance and accuracy | best paper airplanes for distance and speed | what is the best paper airplane design for distance | paper airplane that flies far and straight | nakamura lock paper airplane instructions | paper airplane templates for distance | science behind paper airplanes
Get your Career in IT on track with our Career Accelerator Program by Premium Learnings
ReplyDeleteCheck our Youtube channel for our training videos - https://www.youtube.com/c/PremiumLearningssystem
For more info do visit us: https://www.premiumlearnings.com/
Hello,
ReplyDeleteCan I get some questions answers because I don't have any dating sitge account but I am getting dating messages.. Why am I getting Spam Emails for Dating Sites