Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed Up with Numba #79

Closed
Marco-Pellegrino opened this issue Sep 13, 2021 · 6 comments
Closed

Speed Up with Numba #79

Marco-Pellegrino opened this issue Sep 13, 2021 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed stale This issue hasn't received enough love

Comments

@Marco-Pellegrino
Copy link

Hi Robbie.
Have you ever tried to use Numba instead of Numpy?
It seens it can speed up everything :)

Is it worth it to have a look at?

@robbievanleeuwen
Copy link
Owner

Hi Marco,

Thanks for the suggestion, I must admit this is the first time I've heard of Numba!

Do you have any experience in using it? At the moment (from what I remember), a lot of the computational time is spent in performing element level calculations and assembling these results into sparse matrices. Do you think this is something numba would improve significantly?

If you are interested, you could do a small test case to see if there are any performance gains?

Robbie

@robbievanleeuwen robbievanleeuwen added the enhancement New feature or request label Sep 19, 2021
@Marco-Pellegrino
Copy link
Author

Hi @robbievanleeuwen .
I don't have personal experience with numba unfortunately but it looks like that can become 10-100x faster.
Your tool is cool anyway but... you know. People like to have a solution in 300 ms ;)

@Spectre5
Copy link
Contributor

Numba could be a good solution to some of the python for loops (depending on how exactly they are written), as it essentially turns them into machine code using LLVM. Numba is a really cool project. That said, I think it would be even better to fully vectorize the code in numpy, which is something I wanted to do and one of the reasons I wanted to get some benchmarking code in the project using pytest-benchmark.

@Marco-Pellegrino
Copy link
Author

Hi @Spectre5 !
I thought that Section properties was already using most of the numpy vectorisation power.
If not, it will definitely get a good amount of speed.
Can you point me to some part of the code where there is no use of Numpy?

I do like the way this conversation is going

@Spectre5
Copy link
Contributor

Spectre5 commented Sep 20, 2021

See all of these Python loops in this file and this file to calculate the results? It loops on each element and each Gauss point of each element. So it uses all (slow) Python loops. Those might be sped up using Numba, or at least could be with some reorganization. However, you could also setup the analysis using larger numpy arrays and then perform the computations once using fully vectorized calculations, at the expense of using more memory. This would be ever better than Numba.

One idea that I've played around with is to make a fully vectorized version (max speed with higher memory usage) and then also keep the Python loop version (and/or using Numba) that would be slower, but less memory usage. Just in case some really large or complicated section actually got big enough to be a memory problem. But we'd need to see how much memory a large section actually uses to know if that'd be needed.

@DougAJ4
Copy link

DougAJ4 commented Jan 15, 2022

I am no Numba expert, but I have done a fair bit of Numba coding recently forming structural stiffness matrices (for solution with Scipy functions). The main problem I found was Numba reverting to Python code, with the end result being even slower than pure Python. The main two lessons I took from this were:

  1. Use the "no Python" option, so the problem is picked up at compile time, rather than being hidden by reverting to Python.
  2. Work from the lowest level routines upwards, making sure all the bottom level routines work in no Python mode, before starting on the next level up.

More details at:
https://newtonexcelbach.com/2021/08/15/more-on-numba/

@robbievanleeuwen robbievanleeuwen added good first issue Good for newcomers help wanted Extra attention is needed labels Jan 15, 2022
@robbievanleeuwen robbievanleeuwen added the stale This issue hasn't received enough love label Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed stale This issue hasn't received enough love
Projects
None yet
Development

No branches or pull requests

4 participants