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

Gate class: error handling for non-native integer types + case where control and target qubits are identical #67

Closed
ValentinS4t1qbit opened this issue Oct 1, 2021 · 0 comments · Fixed by #88
Labels
bug Something isn't working enhancement New feature or request

Comments

@ValentinS4t1qbit
Copy link
Collaborator

ValentinS4t1qbit commented Oct 1, 2021

Example code:

from numpy.random import randint
from qsdk.backendbuddy import Gate

# Randomly generates 2 random numbers in {0, 1}
i, j = randint(0, 2, 2)
g = Gate("CNOT",  i, j)

Currently triggers:

    if not (isinstance(target, int) and target >= 0):
        raise ValueError("Qubit index must be a positive integer.")

Suggestions:

  • The error is triggered because the numpy int types are not captured by isinstance, here. To capture numpy int types, it should also include np.integer(https://stackoverflow.com/questions/37726830/how-to-determine-if-a-number-is-any-type-of-int-core-or-numpy-signed-or-not)
  • Because the circuits are converted in different formats and type differences may lead to sneaky errors, I think for simplicity we should test for types (control, target, ...) and if everything is alright cast them as built-in ints in the init method.
  • The error messages for target and control should be more useful and specific: Target qubit index must be a non-negative number (value: {target}) (likewise for control)
  • Additional statement returning a warning if control == target. There's no reason to forbid it, but it's an odd thing to do. In this situation, the author of the code did not realize this could happen.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant