Skip to content

Commit

Permalink
Address c_if and Permutation deprecations in Qiskit 1.3
Browse files Browse the repository at this point in the history
The `c_if` usage on conditional gates has been replaced with `if_test`
blocks around those gates.

The `Permutation` instances have been replaced with `PermutationGate`
instances that work the same way for the cases in Experiments.
  • Loading branch information
wshanks committed Nov 5, 2024
1 parent 05d7487 commit d1f2618
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import Union, Optional, Iterable, List, Tuple, Sequence
from itertools import product
from qiskit.circuit import QuantumCircuit, Instruction, ClassicalRegister, Clbit
from qiskit.circuit.library import Permutation
from qiskit.circuit.library import PermutationGate
from qiskit.providers.backend import Backend
from qiskit.quantum_info.operators.base_operator import BaseOperator

Expand Down Expand Up @@ -278,7 +278,7 @@ def _permute_circuit(self) -> QuantumCircuit:
prep_qargs = list(self._prep_indices)
if len(self._prep_indices) != total_qubits:
prep_qargs += [i for i in range(total_qubits) if i not in self._prep_indices]
perm_circ.append(Permutation(total_qubits, prep_qargs).inverse(), range(total_qubits))
perm_circ.append(PermutationGate(prep_qargs).inverse(), range(total_qubits))

# Apply original circuit
if total_clbits:
Expand All @@ -291,6 +291,6 @@ def _permute_circuit(self) -> QuantumCircuit:
meas_qargs = list(self._meas_indices)
if len(self._meas_indices) != total_qubits:
meas_qargs += [i for i in range(total_qubits) if i not in self._meas_indices]
perm_circ.append(Permutation(total_qubits, meas_qargs), range(total_qubits))
perm_circ.append(PermutationGate(meas_qargs), range(total_qubits))

return perm_circ
12 changes: 8 additions & 4 deletions test/library/tomography/tomo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ def teleport_circuit(flatten_creg=True):
teleport.measure(0, creg[0])
teleport.measure(1, creg[1])
# Conditionals
teleport.z(2).c_if(creg[0], 1)
teleport.x(2).c_if(creg[1], 1)
with teleport.if_test((creg[0], True)):
teleport.z(2)
with teleport.if_test((creg[1], True)):
teleport.x(2)
return teleport


Expand All @@ -76,8 +78,10 @@ def teleport_bell_circuit(flatten_creg=True):
teleport.h(0)
teleport.measure(0, creg[0])
teleport.measure(1, creg[1])
teleport.z(2).c_if(creg[0], 1)
teleport.x(2).c_if(creg[1], 1)
with teleport.if_test((creg[0], True)):
teleport.z(2)
with teleport.if_test((creg[1], True)):
teleport.x(2)
return teleport


Expand Down

0 comments on commit d1f2618

Please sign in to comment.