-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Environment
- Qiskit Terra version: 0.24.0
- Python version: Python 3.9.6
What is happening?
Given a quantum circuit object, we execute the to_gate()
method and attempt to call the Gate.control()
method with appropriate parameters and sometimes observe the following error: *** UnboundLocalError: local variable 'mat2'
referenced before assignment
How can we reproduce the issue?
from qiskit.extensions import UnitaryGate
from qiskit import QuantumCircuit, QuantumRegister
# initialize a unitary matrix
A = np.array([[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j,
0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 1.+0.j, 0.+0.j,
0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j,
0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
-1.+0.j],
[ 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
0.+0.j],
[ 0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
0.+0.j],
[ 0.+0.j, 0.+0.j, -1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
0.+0.j],
[ 0.+0.j, 0.+0.j, 0.+0.j, -1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j,
0.+0.j]])
gate = UnitaryGate(A)
qc = QuantumCircuit(3)
qc.append(gate,[0,1,2])
# This happens in a a different function than the operations above
CU = qc.to_gate().control(6,28)
What should happen?
I would assume that the error is not thrown
Any suggestions?
The error appears to come from the file qsd.py
, and in particular because the list ind2q
(line 234) has only one element. The for loop that starts on line 242 is thus never executed and the the variable mat2
is never initialized.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working