-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #7267: reorder cirq + cirq-rigetti module installation & import #7268
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
Conversation
Pasting the following code into a cell in a fresh notebook in colab.research.google.com, ```python try: import cirq import cirq_rigetti except ImportError: print("installing cirq-rigetti...") !pip install --quiet cirq-rigetti print("installed cirq-rigetti.") import cirq import cirq_rigetti ``` produces the error described in issue quantumlib#7267. The reason is the following. The `cirq-rigetti` module requires NumPy version 1.x, so pip-installing the Rigetti module causes NumPy 1.x to be installed. However, the Colab environment comes with version 2.x preloaded. When Cirq is imported, it results in an import of `numpy`, which (because the NumPy module outside the Python environment has been changed) results in NumPy 1.x being imported into a Python runtime that already has NumPy 2 loaded. Changing the order a little bit seems to work: pip-install Cirq first, import it (which doesn't result in errors because it doesn't load a conflicting version of NumPy), then after that, pip-install cirq-rigetti separately, followed by importing it. This allows the packages to load. Unfortunately, I can't get the forest-sdk package to install in my Colab environment, so I can't go far in testing whether the rest of the notebook works.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7268 +/- ##
==========================================
- Coverage 98.67% 98.67% -0.01%
==========================================
Files 1106 1106
Lines 96054 96054
==========================================
- Hits 94778 94777 -1
- Misses 1276 1277 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Here's a gist showing the results of running the changed install+import code: https://gist.github.com/mhucka/5fe2fbf5457f7f01612c9c14b028f34a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change indeed prevents numpy error showing up at cirq-rigetti installation time by importing numpy modules before downgrade to numpy-1. I would however not rely on it to work further down the line. cirq_rigetti depends on qcs-sdk-python which has a rust language extensions compiled with numpy-1. It is uncertain rust-numpy bindings would function across major version change and even if they would be very fragile. The notebook has other errors anyway and I could not get it to pass without it becoming a debug chore.
cirq-rigetti is deprecated and it does not seem worthwhile trying to fix its notebook which is also broken in other ways. We can reconsider if we get user reports and requests to the contrary.
If you feel inclined, you can add a short note advising users to restart their colab session (Ctrl+M .
) after installing cirq-rigetti. I would not mind to leave it as is, because the notebook seems unused and posed for removal.
Yeah, I suspected other things wouldn't work. Thanks for checking. Let's just leave it, then, since it will be removed anyway. |
Pasting the following code into a cell in a fresh notebook in colab.research.google.com,
produces the error described in issue #7267. The reason is the following. The
cirq-rigetti
module requires NumPy version 1.x, so pip-installing the Rigetti module causes NumPy 1.x to be installed. However, the Colab environment comes with version 2.x preloaded. When Cirq is imported, it results in an import ofnumpy
, which (because the NumPy module outside the Python environment has been changed) results in NumPy 1.x being imported into a Python runtime that already has NumPy 2 loaded.Changing the order a little bit seems to work: pip-install Cirq first, import it (which doesn't result in errors because it doesn't load a conflicting version of NumPy), then after that, pip-install cirq-rigetti separately, followed by importing it.
This allows the packages to load into the notebook without error. Unfortunately, I can't get the forest-sdk package to install in my Colab environment, so I can't go far in testing whether the rest of the notebook works.