You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
I believe this is a duplicate of #10036, so the fix should have been released in Terra 0.24.1. Could you try upgrading and see if the problem persists?
sharipr
changed the title
Gate.control method throwing unexpected errorGate.control method throwing error
Sep 6, 2023
@jakelishman@ewinston I see the lines of code that are meant to fix this (from 2 months ago). Lines 246 and 247 are:
if not ind2q:
return ccirc
I could be wrong but it also seems like if the list ind2q has just one element, the for loop that comes next will not be executed and the variable mat2 will never be initialized, thus throwing the same error.
Environment
What is happening?
Given a quantum circuit object, we execute the
to_gate()
method and attempt to call theGate.control()
method with appropriate parameters and sometimes observe the following error:*** UnboundLocalError: local variable 'mat2'
referenced before assignmentHow can we reproduce the issue?
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 listind2q
(line 234) has only one element. The for loop that starts on line 242 is thus never executed and the the variablemat2
is never initialized.The text was updated successfully, but these errors were encountered: