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

Unitary doesnt accept int param for single qubit unitary matrix #997

Closed
Manvi-Agrawal opened this issue Jun 6, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@Manvi-Agrawal
Copy link

Describe the bug
A clear and concise description of what the bug is.
Cuurently circ = Circuit().unitary(matrix=np.array([[0, 1],[1, 0]]), targets=0) is compile-time error on dev variant based on branch in

#993

To reproduce
A clear, step-by-step set of instructions to reproduce the bug.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots or logs
If applicable, add screenshots or logs to help explain your problem.

System information
A description of your system. Please provide:

  • Amazon Braket Python SDK version:
  • Amazon Braket Python Schemas version:
  • Amazon Braket Python Default Simulator version:
  • Python version:

Additional context
Add any other context about the problem here.
See #993 (comment)

@Manvi-Agrawal Manvi-Agrawal added the bug Something isn't working label Jun 6, 2024
@peterkomar-aws
Copy link
Contributor

Hi @Manvi-Agrawal , thanks for pointing this out. You are right that the following code

import numpy as np
from braket.circuits import Circuit

circ = Circuit().unitary(matrix=np.array([[0, 1],[1, 0]]), targets=0)

raises the following TypeError:

...
-> 3621 if 2 ** len(targets) != matrix.shape[0]:
   3622     raise ValueError("Dimensions of the supplied unitary are incompatible with the targets")
   3624 return Instruction(Unitary(matrix, display_name), target=targets)

TypeError: object of type 'int' has no len()

While surprising, this is not unexpected. The docstring of Circuit.unitary says

...
Args:
    targets (QubitSet): Target qubits.
...

In alignment with this, the following code work without error:

import numpy as np
from braket.circuits import Circuit, QubitSet

target_qubit_indexes = (0,)
target_qubits = QubitSet(target_qubit_indexes)

circ0 = Circuit().unitary(matrix=np.array([[0, 1],[1, 0]]), targets=target_qubit_indexes)
circ1 = Circuit().unitary(matrix=np.array([[0, 1],[1, 0]]), targets=target_qubits)

I close this issue. If you think there is more to this problem than what I found, feel free to reopen and provide more information. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants