Skip to content

Commit

Permalink
Fix usage of QuantumCircuit.id (Qiskit#1945)
Browse files Browse the repository at this point in the history
Co-authored-by: Jun Doi <doichan@jp.ibm.com>
  • Loading branch information
Cryoris and doichanj authored Oct 2, 2023
1 parent 8f825d7 commit 73f0847
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 51 deletions.
4 changes: 2 additions & 2 deletions qiskit_aer/backends/backend_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def available_methods(controller, methods, devices):
"""Check available simulation methods by running a dummy circuit."""
# Test methods are available using the controller
dummy_circ = QuantumCircuit(1)
dummy_circ.i(0)
dummy_circ.id(0)

valid_methods = []
for device in devices:
Expand All @@ -462,7 +462,7 @@ def available_devices(controller, devices):
"""Check available simulation devices by running a dummy circuit."""
# Test methods are available using the controller
dummy_circ = QuantumCircuit(1)
dummy_circ.i(0)
dummy_circ.id(0)

valid_devices = []
for device in devices:
Expand Down
2 changes: 1 addition & 1 deletion test/terra/backends/simulator_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def check_cuStateVec(devices):
"""Return if the system supports cuStateVec or not"""
if "GPU" in devices:
dummy_circ = QuantumCircuit(1)
dummy_circ.i(0)
dummy_circ.id(0)
qobj = assemble(
dummy_circ,
optimization_level=0,
Expand Down
4 changes: 0 additions & 4 deletions test/terra/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

from qiskit_aer import AerProvider, AerSimulator

# Backwards compatibility for Terra <= 0.13
if not hasattr(QuantumCircuit, "i"):
QuantumCircuit.i = QuantumCircuit.iden


def is_method_available(backend, method):
"""Check if input method is available for the qasm simulator."""
Expand Down
2 changes: 1 addition & 1 deletion test/terra/noise/test_noise_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_amplitude_damping_error(self):
for _ in range(30):
# Add noisy identities
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
shots = 4000
Expand Down
2 changes: 1 addition & 1 deletion test/terra/noise/test_quantum_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_ideal(self):

# up to global phase
qc = QuantumCircuit(1, global_phase=0.5)
qc.i(0)
qc.id(0)
self.assertTrue(QuantumError(qc).ideal())
self.assertTrue(QuantumError(UnitaryGate(-1.0 * np.eye(2))).ideal())

Expand Down
6 changes: 1 addition & 5 deletions test/terra/reference/ref_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

# Backwards compatibility for Terra <= 0.13
if not hasattr(QuantumCircuit, "i"):
QuantumCircuit.i = QuantumCircuit.iden


def grovers_circuit(final_measure=True, allow_sampling=True):
"""Testing a circuit originated in the Grover algorithm"""
Expand Down Expand Up @@ -66,7 +62,7 @@ def grovers_circuit(final_measure=True, allow_sampling=True):
circuit.measure(qr[1], cr[1])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuits.append(circuit)

return circuits
Expand Down
6 changes: 1 addition & 5 deletions test/terra/reference/ref_kraus_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
from qiskit_aer.noise import NoiseModel
from qiskit_aer.noise.errors.standard_errors import amplitude_damping_error

# Backwards compatibility for Terra <= 0.13
if not hasattr(QuantumCircuit, "i"):
QuantumCircuit.i = QuantumCircuit.iden


# ==========================================================================
# Amplitude damping error
Expand All @@ -42,7 +38,7 @@ def kraus_gate_error_circuits():
for _ in range(30):
# Add noisy identities
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand Down
22 changes: 11 additions & 11 deletions test/terra/reference/ref_measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def measure_circuits_deterministic(allow_sampling=True):
circuit.measure(qr, cr)
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand All @@ -49,7 +49,7 @@ def measure_circuits_deterministic(allow_sampling=True):
circuit.measure(qr, cr)
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand All @@ -61,7 +61,7 @@ def measure_circuits_deterministic(allow_sampling=True):
circuit.measure(qr, cr)
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand All @@ -73,7 +73,7 @@ def measure_circuits_deterministic(allow_sampling=True):
circuit.measure(qr, cr)
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand All @@ -89,7 +89,7 @@ def measure_circuits_deterministic(allow_sampling=True):
circuit.measure(1, 0)
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(1, 0)
circuits.append(circuit)
Expand Down Expand Up @@ -185,7 +185,7 @@ def measure_circuits_nondeterministic(allow_sampling=True):
circuit.measure(qr, cr)
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand Down Expand Up @@ -228,7 +228,7 @@ def measure_n(num_qubits):
circuit.append(measure_n(2), [0, 1], [0, 1])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.append(measure_n(2), [0, 1], [0, 1])
circuits.append(circuit)
Expand All @@ -243,7 +243,7 @@ def measure_n(num_qubits):
circuit.append(measure_n(3), [0, 1, 2], [0, 1, 2])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.append(measure_n(3), [0, 1, 2], [0, 1, 2])
circuits.append(circuit)
Expand All @@ -258,7 +258,7 @@ def measure_n(num_qubits):
circuit.append(measure_n(4), [0, 1, 2, 3], [0, 1, 2, 3])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.append(measure_n(4), [0, 1, 2, 3], [0, 1, 2, 3])
circuits.append(circuit)
Expand Down Expand Up @@ -344,7 +344,7 @@ def measure_n(num_qubits):
circuit.append(measure_n(2), [0, 1], [0, 1])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.append(measure_n(2), [0, 1], [0, 1])
circuits.append(circuit)
Expand All @@ -359,7 +359,7 @@ def measure_n(num_qubits):
circuit.append(measure_n(3), [0, 1, 2], [0, 1, 2])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.append(measure_n(3), [0, 1, 2], [0, 1, 2])
circuits.append(circuit)
Expand Down
12 changes: 4 additions & 8 deletions test/terra/reference/ref_pauli_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
from qiskit_aer.noise import NoiseModel
from qiskit_aer.noise.errors.standard_errors import pauli_error

# Backwards compatibility for Terra <= 0.13
if not hasattr(QuantumCircuit, "i"):
QuantumCircuit.i = QuantumCircuit.iden


# ==========================================================================
# Pauli Gate Errors
Expand All @@ -39,28 +35,28 @@ def pauli_gate_error_circuits():

# 100% all-qubit Pauli error on "id" gate
circuit = QuantumCircuit(qr, cr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)

# 25% all-qubit Pauli error on "id" gates
circuit = QuantumCircuit(qr, cr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)

# 100% Pauli error on "id" gates on qubit-1
circuit = QuantumCircuit(qr, cr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)

# 25% all-qubit Pauli error on "id" gates on qubit-0
circuit = QuantumCircuit(qr, cr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand Down
8 changes: 2 additions & 6 deletions test/terra/reference/ref_reset_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
from qiskit_aer.noise import NoiseModel
from qiskit_aer.noise.errors.standard_errors import reset_error

# Backwards compatibility for Terra <= 0.13
if not hasattr(QuantumCircuit, "i"):
QuantumCircuit.i = QuantumCircuit.iden


# ==========================================================================
# Reset Gate Errors
Expand Down Expand Up @@ -65,7 +61,7 @@ def reset_gate_error_circuits():
qr = QuantumRegister(1, "qr")
cr = ClassicalRegister(1, "cr")
circuit = QuantumCircuit(qr, cr)
circuit.i(qr)
circuit.id(qr)
circuit.barrier(qr)
circuit.measure(qr, cr)
circuits.append(circuit)
Expand All @@ -74,7 +70,7 @@ def reset_gate_error_circuits():
qr = QuantumRegister(2, "qr")
cr = ClassicalRegister(2, "cr")
circuit = QuantumCircuit(qr, cr)
circuit.i(qr[0])
circuit.id(qr[0])
circuit.x(qr[1])
circuit.barrier(qr)
circuit.measure(qr, cr)
Expand Down
2 changes: 1 addition & 1 deletion test/terra/reference/ref_save_expval.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def save_expval_circuit_parameterized(
circuit.u(0, 0, 0, 1)
circuit.cu(0, 0, 0, 0, 0, 1)
circuit.u(0, 0, 0, 1)
circuit.i(0)
circuit.id(0)
if snapshot:
for label, (params, qubits) in save_expval_params(pauli=True).items():
circuit.save_expectation_value(
Expand Down
2 changes: 1 addition & 1 deletion tools/generate_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def grovers_circuit(final_measure=True, allow_sampling=True):
circuit.measure(qr[1], cr[1])
if not allow_sampling:
circuit.barrier(qr)
circuit.iden(qr)
circuit.id(qr)
circuits.append(circuit)

return circuits
Expand Down
6 changes: 1 addition & 5 deletions tools/verify_wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
from qiskit_aer import StatevectorSimulator
from qiskit_aer import UnitarySimulator

# Backwards compatibility for Terra <= 0.13
if not hasattr(QuantumCircuit, "i"):
QuantumCircuit.i = QuantumCircuit.iden


def assertAlmostEqual(first, second, places=None, msg=None, delta=None):
"""Test of 2 object are almost equal.
Expand Down Expand Up @@ -105,7 +101,7 @@ def grovers_circuit(final_measure=True, allow_sampling=True):
circuit.measure(qr[1], cr[1])
if not allow_sampling:
circuit.barrier(qr)
circuit.i(qr)
circuit.id(qr)
circuits.append(circuit)

return circuits
Expand Down

0 comments on commit 73f0847

Please sign in to comment.