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

[v1.0.1] Tune import time #92

Closed
adtzlr opened this issue Oct 23, 2021 · 9 comments
Closed

[v1.0.1] Tune import time #92

adtzlr opened this issue Oct 23, 2021 · 9 comments
Labels
enhancement New feature or request
Milestone

Comments

@adtzlr
Copy link
Owner

adtzlr commented Oct 23, 2021

Guess: if numba is installed, felupe compiles the parallel version of the integrate method of a form on import - even if it is not used. This should be handled in a better way in the future.

@adtzlr adtzlr added the enhancement New feature or request label Oct 23, 2021
@adtzlr adtzlr added this to the 2.0.0 milestone Oct 23, 2021
@adtzlr
Copy link
Owner Author

adtzlr commented Oct 23, 2021

A possible solution would be to update globals with felupe.use_numba() or something similar. For example, the __init__.py file contains an import statement for a function fun.

from ._python import fun

If form.assemble(parallel=True) is called, the functions should be replaced by numba-accelerated functions

def use_numba():
    from ._numba import fun
    globals().update(fun=fun)

@adtzlr
Copy link
Owner Author

adtzlr commented Oct 23, 2021

equivalent to globals()["fun"] = fun or globals().update(fun=fun) is also import sys; fe = sys.modules[__name__]; fe.fun=fun

@adtzlr
Copy link
Owner Author

adtzlr commented Oct 23, 2021

In the past (alpha versions) this was complicated but now that everything is organized in folders/files this should be an easy task.

@adtzlr adtzlr changed the title Long import time if Numba is installed due to JIT Long import time Oct 23, 2021
@adtzlr adtzlr changed the title Long import time Tune import time Oct 23, 2021
@adtzlr
Copy link
Owner Author

adtzlr commented Oct 23, 2021

@adtzlr
Copy link
Owner Author

adtzlr commented Oct 23, 2021

okay, it seems this commit slows down import time even more.

@adtzlr adtzlr changed the title Tune import time [v1.0.1] Tune import time Oct 23, 2021
@adtzlr
Copy link
Owner Author

adtzlr commented Oct 25, 2021

Inspecting __init__.py gives:

from .__about__ import __version__

import time 
t = []

t.append(time.time())
from . import math
t.append(time.time())
from . import mesh
t.append(time.time())
from . import quadrature
t.append(time.time())
from . import dof
t.append(time.time())
from . import element
t.append(time.time())
from . import tools
t.append(time.time())
from . import constitution
t.append(time.time())
from . import solve
t.append(time.time())
from . import region
t.append(time.time())

import numpy as np
print(np.diff(np.array(t)))
# ...

produces

In [1]: import felupe
[0.00519323 0.01053238 2.14523649 0.87573862 0.05784726 0.38405085
 0.00819564 0.         0.00375438]

@adtzlr
Copy link
Owner Author

adtzlr commented Oct 25, 2021

It seems most of the time is spent on importing quadrature due to quadpy followed by dof due to `sparse´.

@adtzlr
Copy link
Owner Author

adtzlr commented Oct 25, 2021

As we only use Legendre-Gauss rules quadpy could be removed - NumPy has them built-in. See https://numpy.org/doc/stable/reference/routines.polynomials.legendre.html

points, weights = numpy.polynomial.legendre.leggauss(deg)

@adtzlr
Copy link
Owner Author

adtzlr commented Oct 25, 2021

x, y = np.polynomial.legendre.leggauss(3)
w, v, u = np.meshgrid(x, x, x, indexing="ij")
points = np.vstack((u.ravel(), v.ravel(), w.ravel())).T
weights = np.einsum("i,j,k",y,y,y).ravel()

This was referenced Oct 25, 2021
@adtzlr adtzlr closed this as completed Nov 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant