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 PennyLane load time #1961

Closed
cvjjm opened this issue Dec 1, 2021 · 3 comments · Fixed by #1962
Closed

Speed up PennyLane load time #1961

cvjjm opened this issue Dec 1, 2021 · 3 comments · Fixed by #1962
Labels
enhancement ✨ New feature or request

Comments

@cvjjm
Copy link
Contributor

cvjjm commented Dec 1, 2021

Feature details

I have noticed that PennyLane import time is growing longer and longer and did a quick profiling session following this guide. The results look like this:

image

So, over 60% of the time is spent on importing qchem and most of that is attributable to openfermion. Now of course you can say that I should approach the openfermion people and tell them to speed up their load time, but clearly there are many programs that use pennylane, but don't need qchem and openfermion and in that case, even if those are installed, it would be nice if pennylane would start up fast.

Can qchem maybe be imported on demand?

Implementation

No response

How important would you say this feature is?

1: Not important. Would be nice to have.

Additional information

No response

@cvjjm cvjjm added the enhancement ✨ New feature or request label Dec 1, 2021
@cvjjm cvjjm changed the title Speed uo PennyLane load time Speed up PennyLane load time Dec 1, 2021
@josh146
Copy link
Member

josh146 commented Dec 1, 2021

Nice catch @cvjjm! Speeding up the import time would be a huge quality-of-life improvement.

Currently, we dynamically import qchem here, if the entry point exists:

for entry in pkg_resources.iter_entry_points("pennylane.qchem"):
if entry.name == "OpenFermion":
qchem = entry.load()

but I'm sure we can somehow make this a 'lazy' import that is only loaded when first called.

@josh146
Copy link
Member

josh146 commented Dec 1, 2021

@cvjjm I'm suddenly a bit confused. I can't recreate this behaviour locally; when I import pennylane as qml, I don't have OpenFermion automatically imported.

It seems we are already taking care of this in the qchem package:

def __getattr__(name):
"""Allow for lazy importing of openfermion"""
try:
return importlib.import_module("openfermion." + name)
except ModuleNotFoundError:
mod = importlib.import_module("openfermion")
return getattr(mod, name)

Are you using an older version of qchem?

@josh146 josh146 linked a pull request Dec 1, 2021 that will close this issue
@cvjjm
Copy link
Contributor Author

cvjjm commented Dec 1, 2021

Indeed!! Looks like I picked a bad conda env for this test. This was with qchem 15.1 :-) Well, happy that at least this lead you to looking into making the whole qchem import lazy :-)

@cvjjm cvjjm closed this as completed Dec 1, 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

Successfully merging a pull request may close this issue.

2 participants