# Problem with SwitchCase in qiskit while using general unitary gate

I am trying to run a circuit using SwithCase Op on one of the 127 qubits backends. My code is the following:

def unitary(Theta, Phi):
matrix = [[ cos(Theta), exp(Phi*1j)*sin(Theta) ],
[-exp(-Phi*1j)*sin(Theta), cos(Theta)]]
Unitary = qiskit.extensions.UnitaryGate(matrix, label=r'$$U_{Con}$$')
return Unitary

qreg = QuantumRegister(3)
creg = ClassicalRegister(3)
qc = QuantumCircuit(qreg, creg)
qc.h([0, 1, 2])
qc.measure([0, 1, 2], [0, 1, 2])

with qc.switch(creg) as case:
with case(0):
Theta = pi/3
Phi = 2*pi/3
u = unitary(Theta, Phi)
qc.append(u, [0])
with case(1, 2):
Theta = 2*pi/3
Phi = 4*pi/3
u = unitary(Theta, Phi)
qc.append(u, [0])
with case(case.DEFAULT):
Theta = 2*pi/3
Phi = 5*pi/3
u = unitary(Theta, Phi)
qc.append(u, [0])

qc.measure([0, 1, 2], [0, 1, 2])
qc = transpile(qc, backend=backend)
job = backend.run(qc, shots = 10000)
results = job.result()


Unfortunately, every time that I want to run the circuit I arrive at the following error:

---------------------------------------------------------------------------
IBMJobFailureError                        Traceback (most recent call last)
Cell In[27], line 52
50 qc = transpile(qc, backend=backend)
51 job = backend.run(qc, shots = 1024)
---> 52 results = job.result()
53 counts = results.get_counts()

File /opt/conda/lib/python3.10/site-packages/qiskit_ibm_provider/job/ibm_circuit_job.py:251, in IBMCircuitJob.result(self, timeout, refresh)
249     if self._status == JobStatus.ERROR:
250         error_message = self.error_message()
--> 251         raise IBMJobFailureError(f"Job failed: " f"{error_message}")
252     self._retrieve_result(refresh=refresh)
253 return self._result

IBMJobFailureError: 'Job failed: Error while executing OpenQASM 3 circuit.


Surprisingly, if I execute the code using the Aer simulator it does not return any errors. On the contrary, on real backends, it pops up with the above error. Another peculiar thing is that if I replace the general unitary gate with Pauli Gates in each case, the code would be executed which is evidence that the backends support dynamic circuits. It will be an immense help if you can help me out with this matter.

• what backend are you using? could you post the Python package imports and any other code needed to run your code block above? what is the version of your qiskit packages, pip list | grep qiskit?
– Reza
Jan 26 at 19:52