Skip to content

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

Closed
wants to merge 2 commits into from

Conversation

mhucka
Copy link
Contributor

@mhucka mhucka commented Apr 13, 2025

Pasting the following code into a cell in a fresh notebook in colab.research.google.com,

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 #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 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.

mhucka added 2 commits April 13, 2025 11:32
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.
Copy link

codecov bot commented Apr 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.67%. Comparing base (da14476) to head (39067a9).
Report is 4 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mhucka mhucka marked this pull request as ready for review April 13, 2025 19:05
@mhucka mhucka requested review from vtomole and a team as code owners April 13, 2025 19:05
@mhucka mhucka requested a review from mpharrigan April 13, 2025 19:05
@mhucka
Copy link
Contributor Author

mhucka commented Apr 13, 2025

Here's a gist showing the results of running the changed install+import code: https://gist.github.com/mhucka/5fe2fbf5457f7f01612c9c14b028f34a

Copy link
Collaborator

@pavoljuhas pavoljuhas left a 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.

@mhucka
Copy link
Contributor Author

mhucka commented Apr 15, 2025

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.

@mhucka mhucka closed this Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants