Skip to content

Commit

Permalink
Fix test cases for Qiskit 0.45.2 (Qiskit#2035)
Browse files Browse the repository at this point in the history
* fix test cases for Qiskit 0.45.2

* format

* revert  testtools.TestCase to unittest.TestCase
  • Loading branch information
doichanj committed Feb 6, 2024
1 parent f5f93ed commit 819ef0b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/benchmark/vqe_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/terra/backends/aer_simulator/test_truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions test/terra/reference/ref_diagonal_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 819ef0b

Please sign in to comment.