diff --git a/releasenotes/notes/fix_test_for_Qiskit0.45.2-e0544949be8e77fb.yaml b/releasenotes/notes/fix_test_for_Qiskit0.45.2-e0544949be8e77fb.yaml new file mode 100644 index 0000000000..db24067919 --- /dev/null +++ b/releasenotes/notes/fix_test_for_Qiskit0.45.2-e0544949be8e77fb.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Fixes test cases failed due to upgrade of Qiskit. + + Removed importing Aer from qiskit. + + QuantumCircuit.diagonal was deprecated, using circuit.library.Diagonal instead diff --git a/test/benchmark/vqe_application.py b/test/benchmark/vqe_application.py index fc4e0d91f8..fb94168e8c 100644 --- a/test/benchmark/vqe_application.py +++ b/test/benchmark/vqe_application.py @@ -16,13 +16,13 @@ import numpy as np import multiprocessing from time import time -from qiskit import Aer from qiskit.aqua.algorithms import VQE from qiskit.aqua.components.optimizers import SLSQP from qiskit.chemistry.applications import MolecularGroundStateEnergy from qiskit.chemistry.components.initial_states import HartreeFock from qiskit.chemistry.components.variational_forms import UCCSD from qiskit.chemistry.drivers import PySCFDriver, UnitsType +from qiskit_aer import AerProvider class UCCSDBenchmarkSuite: @@ -67,7 +67,7 @@ def cb_create_solver( optimizer=SLSQP(maxiter=5000), max_evals_grouped=256, ) - vqe.quantum_instance = Aer.get_backend("qasm_simulator") + vqe.quantum_instance = AerProvider.get_backend("qasm_simulator") vqe.quantum_instance.backend_options["backend_options"] = { "max_parallel_experiments": threads, "method": method, diff --git a/test/terra/backends/aer_simulator/test_truncate.py b/test/terra/backends/aer_simulator/test_truncate.py index 5963143580..eb98b10546 100644 --- a/test/terra/backends/aer_simulator/test_truncate.py +++ b/test/terra/backends/aer_simulator/test_truncate.py @@ -9,7 +9,7 @@ AerSimulator Integration Tests """ from ddt import ddt -from qiskit import transpile, QuantumCircuit, Aer +from qiskit import transpile, QuantumCircuit from qiskit.providers.fake_provider import FakeQuito from qiskit_aer.noise import NoiseModel from test.terra.backends.simulator_test_case import SimulatorTestCase, supported_methods diff --git a/test/terra/reference/ref_diagonal_gate.py b/test/terra/reference/ref_diagonal_gate.py index 72f506b9c1..00b49e8072 100644 --- a/test/terra/reference/ref_diagonal_gate.py +++ b/test/terra/reference/ref_diagonal_gate.py @@ -17,10 +17,7 @@ import numpy as np from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister - -# Backwards compatibility for Terra <= 0.13 -if not hasattr(QuantumCircuit, "diagonal"): - QuantumCircuit.diagonal = QuantumCircuit.diag_gate +from qiskit.circuit.library import Diagonal def diagonal_gate_circuits_deterministic(final_measure=True): @@ -41,7 +38,7 @@ def diagonal_gate_circuits_deterministic(final_measure=True): for diag in [arg, np.array(arg), np.array(arg, dtype=float), np.array(arg, dtype=complex)]: circuit = QuantumCircuit(*regs) circuit.h(qubit) - circuit.diagonal(list(diag), [qubit]) + circuit.append(Diagonal(diag), [qubit]) circuit.h(qubit) if final_measure: circuit.barrier(qr) @@ -53,7 +50,7 @@ def diagonal_gate_circuits_deterministic(final_measure=True): for diag in [arg, np.array(arg), np.array(arg, dtype=float), np.array(arg, dtype=complex)]: circuit = QuantumCircuit(*regs) circuit.h(qr) - circuit.diagonal(list(diag), qr) + circuit.append(Diagonal(diag), qr) circuit.h(qr) if final_measure: circuit.barrier(qr) @@ -64,7 +61,7 @@ def diagonal_gate_circuits_deterministic(final_measure=True): for diag in [np.array([1, 1, 1, np.exp(-1j * np.pi / k)]) for k in [10, 100, 1000, 10000]]: circuit = QuantumCircuit(*regs) circuit.x(qr) - circuit.diagonal(list(diag), qr) + circuit.append(Diagonal(diag), qr) if final_measure: circuit.barrier(qr) circuit.measure(qr, cr)