Conversation
cudaq.to_cupy caught the `import cupy` ImportError, printed a message, and then fell through the except block. The subsequent `cp.complex128` (when no dtype is passed) dereferenced the never-bound local, so the user saw a confusing `NameError: ... 'cp' ...` instead of the intended diagnostic. Raise a RuntimeError carrying the existing message so the real cause -- CuPy not being installed -- is reported directly. This matches the RuntimeError already raised later in the same function for a non-GPU state. Signed-off-by: Udaya Tejas <udayatejas2004@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When CuPy is not installed,
cudaq.to_cupyraises a confusingNameErroraboutcpinstead of the intended "please install CuPy" message.Root cause
The
exceptbranch prints and then falls through, so the next use ofcpraisesNameError: name 'cp' is not defined, masking the real cause.Fix
Raise a
RuntimeErrorwith the existing message (matching theRuntimeErroralready raised later in the same function for the not-on-GPU case), so the import guard fails clearly before anything else is touched.Tests
Added
python/tests/builder/test_to_cupy_missing_cupy.py, which forces thecupyimport to fail (via__import__monkeypatch) regardless of whether CuPy/GPU are present, and asserts a clearRuntimeErrormentioning CuPy.