From bdb3d8d60be0645253f8ea0ab873c543928adbe9 Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Tue, 16 Jan 2024 15:24:02 +0900 Subject: [PATCH 1/9] Fixes of tests for the latest Qiskit (#2026) * fix test_aer_statevector * fix daily test * remove test case test.terra.states.test_aer_statevector.TestAerStatevector.test_number_to_latex_terms because of deprecation * add release note and remove temporal on push --- .../fix_for_daily_tests-3fa9df70fb3e53ee.yaml | 9 +++++++ test/terra/noise/test_device_models.py | 4 +++- test/terra/states/test_aer_statevector.py | 24 +------------------ 3 files changed, 13 insertions(+), 24 deletions(-) create mode 100644 releasenotes/notes/fix_for_daily_tests-3fa9df70fb3e53ee.yaml diff --git a/releasenotes/notes/fix_for_daily_tests-3fa9df70fb3e53ee.yaml b/releasenotes/notes/fix_for_daily_tests-3fa9df70fb3e53ee.yaml new file mode 100644 index 0000000000..784cda289f --- /dev/null +++ b/releasenotes/notes/fix_for_daily_tests-3fa9df70fb3e53ee.yaml @@ -0,0 +1,9 @@ +--- +fixes: + - | + Removed deprecate function test in + test.terra.states.test_aer_statevector.TestAerStatevector.test_number_to_latex_terms + + Sorted the output properties in + test.terra.noise.test_device_models.test_basic_device_gate_errors_from_target_and_properties + to compare correctly. diff --git a/test/terra/noise/test_device_models.py b/test/terra/noise/test_device_models.py index 0035f38bdb..aad6c1e38c 100644 --- a/test/terra/noise/test_device_models.py +++ b/test/terra/noise/test_device_models.py @@ -59,7 +59,9 @@ def test_basic_device_gate_errors_from_target_and_properties(self): errors_from_properties = basic_device_gate_errors(properties=FakeNairobi().properties()) errors_from_target = basic_device_gate_errors(target=FakeNairobiV2().target) self.assertEqual(len(errors_from_properties), len(errors_from_target)) - for err_properties, err_target in zip(errors_from_properties, errors_from_target): + errors_from_properties_s = sorted(errors_from_properties) + errors_from_target_s = sorted(errors_from_target) + for err_properties, err_target in zip(errors_from_properties_s, errors_from_target_s): name1, qargs1, err1 = err_properties name2, qargs2, err2 = err_target self.assertEqual(name1, name2) diff --git a/test/terra/states/test_aer_statevector.py b/test/terra/states/test_aer_statevector.py index 4de8c9af2e..43ef209b6b 100644 --- a/test/terra/states/test_aer_statevector.py +++ b/test/terra/states/test_aer_statevector.py @@ -32,7 +32,7 @@ from qiskit.quantum_info.operators.operator import Operator from qiskit.quantum_info.operators.symplectic import Pauli, SparsePauliOp from qiskit.quantum_info.operators.predicates import matrix_equal -from qiskit.visualization.state_visualization import numbers_to_latex_terms, state_to_latex +from qiskit.visualization.state_visualization import state_to_latex from qiskit.circuit.library import QFT, HGate from test.terra import common @@ -1373,28 +1373,6 @@ def test_state_to_latex_for_large_sparse_statevector(self): latex_representation = state_to_latex(sv) self.assertEqual(latex_representation, " |000000000000000\\rangle") - def test_number_to_latex_terms(self): - """Test conversions of complex numbers to latex terms""" - - cases = [ - ([1 - 8e-17, 0], ["", None]), - ([0, -1], [None, "-"]), - ([0, 1], [None, ""]), - ([0, 1j], [None, "i"]), - ([-1, 1], ["-", "+"]), - ([0, 1j], [None, "i"]), - ([-1, 1j], ["-", "+i"]), - ([1e-16 + 1j], ["i"]), - ([-1 + 1e-16 * 1j], ["-"]), - ([-1, -1 - 1j], ["-", "+(-1 - i)"]), - ([np.sqrt(2) / 2, np.sqrt(2) / 2], ["\\frac{\\sqrt{2}}{2}", "+\\frac{\\sqrt{2}}{2}"]), - ([1 + np.sqrt(2)], ["(1 + \\sqrt{2})"]), - ] - with self.assertWarns(DeprecationWarning): - for numbers, latex_terms in cases: - terms = numbers_to_latex_terms(numbers, 15) - self.assertListEqual(terms, latex_terms) - def test_statevector_draw_latex_regression(self): """Test numerical rounding errors are not printed""" sv = AerStatevector(np.array([1 - 8e-17, 8.32667268e-17j])) From f5f93ed1013d18eae4311b4a8785453e312ff973 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Wed, 17 Jan 2024 20:23:05 -0500 Subject: [PATCH 2/9] Fix GPU wheel builds on release (#2034) For the previous few releases the GPU wheel builds have failed to upload. The root cause of this issue was that an earlier CI stage was deleting on the locally cached docker images to free up space for installing CUDA and all the GPU build requirements in the test VM. Removing these docker images prevented the upstream action we run to publish the wheels from working as it relied on having a docker image available that couldn't be fetched from the default image repository. This commit fixes this issue for future releases by ensuring we don't delete the local docker cache in the GPU publish jobs. For the 0.13.2 releases this was manually applied and run to publish the wheels and this PR is applying the fix for future releases. --- .github/workflows/deploy.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6c92ad004b..c5cc5e9a03 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -135,7 +135,6 @@ jobs: remove-android: 'true' remove-haskell: 'true' remove-codeql: 'true' - remove-docker-images: 'true' - uses: actions/checkout@v3 - uses: actions/setup-python@v4 name: Install Python @@ -179,7 +178,6 @@ jobs: remove-android: 'true' remove-haskell: 'true' remove-codeql: 'true' - remove-docker-images: 'true' - uses: actions/checkout@v3 - uses: actions/setup-python@v4 name: Install Python From 819ef0bda1abcbe210fb34f4613e075e5b1d5ba6 Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Tue, 23 Jan 2024 13:23:57 +0900 Subject: [PATCH 3/9] Fix test cases for Qiskit 0.45.2 (#2035) * fix test cases for Qiskit 0.45.2 * format * revert testtools.TestCase to unittest.TestCase --- .../fix_test_for_Qiskit0.45.2-e0544949be8e77fb.yaml | 8 ++++++++ test/benchmark/vqe_application.py | 4 ++-- test/terra/backends/aer_simulator/test_truncate.py | 2 +- test/terra/reference/ref_diagonal_gate.py | 11 ++++------- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/fix_test_for_Qiskit0.45.2-e0544949be8e77fb.yaml 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) From afdde76371cb7146e208bde14b69bc5aff6510b4 Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Mon, 29 Jan 2024 20:58:07 +0900 Subject: [PATCH 4/9] Remove remaining diagonal, isometry and uc (#2040) * Remove remaining diagonal * remove unused import transpile, replace isometry, uc to Isometry, UCGate * format --- test/terra/backends/aer_simulator/test_conditional.py | 6 +++--- test/terra/reference/ref_diagonal_gate.py | 8 ++++---- test/terra/reference/ref_multiplexer.py | 5 +++-- test/terra/states/test_aer_state.py | 8 +++++--- test/terra/states/test_aer_statevector.py | 3 ++- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/test/terra/backends/aer_simulator/test_conditional.py b/test/terra/backends/aer_simulator/test_conditional.py index c5ec4e1ed1..ec33fd404b 100644 --- a/test/terra/backends/aer_simulator/test_conditional.py +++ b/test/terra/backends/aer_simulator/test_conditional.py @@ -12,12 +12,12 @@ """ AerSimulator Integration Tests """ - from ddt import ddt from test.terra.reference import ref_conditionals from test.terra.backends.simulator_test_case import SimulatorTestCase, supported_methods from qiskit import QuantumCircuit +from qiskit.circuit.library import DiagonalGate @ddt @@ -366,13 +366,13 @@ def test_conditional_diagonal(self): circuit0 = QuantumCircuit(4, 4) for i in range(1, 4): circuit0.h(i) - circuit0.diagonal([-1, -1], [1]).c_if(circuit0.clbits[0], 0) + circuit0.append(DiagonalGate([-1, -1]), [1]).c_if(circuit0.clbits[0], 0) circuit0.save_statevector(label="diff") circuit1 = QuantumCircuit(4, 4) for i in range(1, 4): circuit1.h(i) - circuit1.diagonal([-1, -1], [1]).c_if(circuit1.clbits[0], 1) + circuit1.append(DiagonalGate([-1, -1]), [1]).c_if(circuit1.clbits[0], 1) circuit1.save_statevector(label="equal") result = backend.run([circuit, circuit0, circuit1], shots=1).result() diff --git a/test/terra/reference/ref_diagonal_gate.py b/test/terra/reference/ref_diagonal_gate.py index 00b49e8072..f6c7162273 100644 --- a/test/terra/reference/ref_diagonal_gate.py +++ b/test/terra/reference/ref_diagonal_gate.py @@ -17,7 +17,7 @@ import numpy as np from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister -from qiskit.circuit.library import Diagonal +from qiskit.circuit.library import DiagonalGate def diagonal_gate_circuits_deterministic(final_measure=True): @@ -38,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.append(Diagonal(diag), [qubit]) + circuit.append(DiagonalGate(diag), [qubit]) circuit.h(qubit) if final_measure: circuit.barrier(qr) @@ -50,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.append(Diagonal(diag), qr) + circuit.append(DiagonalGate(diag), qr) circuit.h(qr) if final_measure: circuit.barrier(qr) @@ -61,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.append(Diagonal(diag), qr) + circuit.append(DiagonalGate(diag), qr) if final_measure: circuit.barrier(qr) circuit.measure(qr, cr) diff --git a/test/terra/reference/ref_multiplexer.py b/test/terra/reference/ref_multiplexer.py index 028cdf78ae..865ddea9ad 100644 --- a/test/terra/reference/ref_multiplexer.py +++ b/test/terra/reference/ref_multiplexer.py @@ -25,6 +25,7 @@ ccx_gate_counts_deterministic, ) from qiskit.quantum_info.states import Statevector +from qiskit.circuit.library import Isometry, UCGate def multiplexer_cx_gate_circuits_deterministic(final_measure=True): @@ -289,14 +290,14 @@ def multiplexer_no_control_qubits(final_measure=True): qc = QuantumCircuit(1, 1) vector = [0.2, 0.1] vector_circuit = QuantumCircuit(1) - vector_circuit.isometry(vector / np.linalg.norm(vector), [0], None) + vector_circuit.append(Isometry(vector / np.linalg.norm(vector), 0, 0), [0]) vector_circuit = vector_circuit.inverse() qc.append(vector_circuit, [0]) sv = Statevector(qc) gate_list = [np.array([[sv[0], -sv[1]], [sv[1], sv[0]]])] qc = QuantumCircuit(1, 1) - qc.uc(gate_list, [], [0]) + qc.append(UCGate(gate_list), [0]) if final_measure: qc.measure(0, 0) diff --git a/test/terra/states/test_aer_state.py b/test/terra/states/test_aer_state.py index 501a538281..52e49928b5 100644 --- a/test/terra/states/test_aer_state.py +++ b/test/terra/states/test_aer_state.py @@ -20,6 +20,8 @@ from qiskit.circuit import QuantumCircuit, Gate from qiskit.quantum_info.random import random_unitary from qiskit.quantum_info import random_statevector, random_density_matrix +from qiskit.circuit.library import DiagonalGate + from qiskit_aer import AerSimulator from test.terra import common @@ -375,9 +377,9 @@ def test_appply_diagonal(self): circuit = QuantumCircuit(5) circuit.initialize(init_state, [0, 1, 2, 3, 4]) - circuit.diagonal(diag_1, [0]) - circuit.diagonal(diag_2, [1, 2]) - circuit.diagonal(diag_3, [3, 4, 0]) + circuit.append(DiagonalGate(diag_1), [0]) + circuit.append(DiagonalGate(diag_2), [1, 2]) + circuit.append(DiagonalGate(diag_3), [3, 4, 0]) circuit.save_statevector() aer_simulator = AerSimulator(method="statevector") diff --git a/test/terra/states/test_aer_statevector.py b/test/terra/states/test_aer_statevector.py index 43ef209b6b..0797d6178e 100644 --- a/test/terra/states/test_aer_statevector.py +++ b/test/terra/states/test_aer_statevector.py @@ -34,6 +34,7 @@ from qiskit.quantum_info.operators.predicates import matrix_equal from qiskit.visualization.state_visualization import state_to_latex from qiskit.circuit.library import QFT, HGate +from qiskit.circuit.library import DiagonalGate from test.terra import common from qiskit_aer import AerSimulator @@ -289,7 +290,7 @@ def test_diagonal(self): circuit = QuantumCircuit(3) circuit.h(range(3)) diagonal = [1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, -1.0] - circuit.diagonal(diagonal, list(range(3))) + circuit.append(DiagonalGate(diagonal), list(range(3))) target = AerStatevector.from_label("000").evolve(Operator(circuit)) psi = AerStatevector.from_instruction(circuit) self.assertEqual(psi, target) From 47cf6e91ee6bc266f4d54fae6908aa488434eb18 Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Fri, 2 Feb 2024 15:09:27 +0900 Subject: [PATCH 5/9] remove import execute (#2041) --- test/terra/decorators.py | 2 +- tools/verify_wheels.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/terra/decorators.py b/test/terra/decorators.py index faed729d68..8c92e9eaa2 100644 --- a/test/terra/decorators.py +++ b/test/terra/decorators.py @@ -17,7 +17,7 @@ import multiprocessing import unittest -from qiskit import QuantumCircuit, execute +from qiskit import QuantumCircuit from qiskit.utils import wrap_method from qiskit_aer import AerProvider, AerSimulator diff --git a/tools/verify_wheels.py b/tools/verify_wheels.py index 1de976ddb9..7a1004b8bb 100644 --- a/tools/verify_wheels.py +++ b/tools/verify_wheels.py @@ -9,7 +9,6 @@ from qiskit import ClassicalRegister from qiskit.compiler import assemble, transpile -from qiskit import execute from qiskit import QuantumCircuit from qiskit import QuantumRegister from qiskit.quantum_info import Operator, Statevector From 3935efa2322692bb409900d529e565d90df6eab0 Mon Sep 17 00:00:00 2001 From: Ian Hincks Date: Fri, 2 Feb 2024 13:15:55 -0500 Subject: [PATCH 6/9] Add private primitive attributes removed by qiskit (#2048) * Add private primitive attributes removed by qiskit * wrong url * call private submit method * Make submission compatible with qiskit <=0.45 * Skip Operator test is qiskit >=1.0 * grr lint --- qiskit_aer/primitives/estimator.py | 8 +++++++- qiskit_aer/primitives/sampler.py | 8 +++++++- test/terra/primitives/test_estimator.py | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/qiskit_aer/primitives/estimator.py b/qiskit_aer/primitives/estimator.py index a337567ea4..d4f9f65790 100644 --- a/qiskit_aer/primitives/estimator.py +++ b/qiskit_aer/primitives/estimator.py @@ -97,6 +97,11 @@ def __init__( If approximation is True, this parameter is ignored and assumed to be False. """ super().__init__(options=run_options) + # These three private attributes used to be created by super, but were deprecated in Qiskit + # 0.46. See https://github.com/Qiskit/qiskit/pull/11051 + self._circuits = [] + self._parameters = [] + self._observables = [] backend_options = {} if backend_options is None else backend_options method = ( @@ -204,7 +209,8 @@ def _run( parameter_values, **run_options, ) - job.submit() + # The public submit method was removed in Qiskit 0.46 + (job.submit if hasattr(job, "submit") else job._submit)() # pylint: disable=no-member return job def _compute(self, circuits, observables, parameter_values, run_options): diff --git a/qiskit_aer/primitives/sampler.py b/qiskit_aer/primitives/sampler.py index fa988dfbd9..7f06124289 100644 --- a/qiskit_aer/primitives/sampler.py +++ b/qiskit_aer/primitives/sampler.py @@ -67,6 +67,11 @@ def __init__( skip_transpilation: if True, transpilation is skipped. """ super().__init__(options=run_options) + # These two private attributes used to be created by super, but were deprecated in Qiskit + # 0.46. See https://github.com/Qiskit/qiskit/pull/11051 + self._circuits = [] + self._parameters = [] + self._backend = AerSimulator() backend_options = {} if backend_options is None else backend_options self._backend.set_options(**backend_options) @@ -157,7 +162,8 @@ def _run( self._circuits.append(circuit) self._parameters.append(circuit.parameters) job = PrimitiveJob(self._call, circuit_indices, parameter_values, **run_options) - job.submit() + # The public submit method was removed in Qiskit 0.46 + (job.submit if hasattr(job, "submit") else job._submit)() # pylint: disable=no-member return job @staticmethod diff --git a/test/terra/primitives/test_estimator.py b/test/terra/primitives/test_estimator.py index dfd658e05c..7a357bd6d2 100644 --- a/test/terra/primitives/test_estimator.py +++ b/test/terra/primitives/test_estimator.py @@ -20,6 +20,7 @@ import numpy as np from ddt import data, ddt +import qiskit from qiskit.circuit import Parameter, QuantumCircuit from qiskit.circuit.library import RealAmplitudes from qiskit.exceptions import QiskitError @@ -84,6 +85,10 @@ def test_estimator(self, abelian_grouping): np.testing.assert_allclose(result.values, [-0.4], rtol=0.02) @data(True, False) + @unittest.skipUnless( + qiskit.__version__.startswith("0."), + reason="Operator support in primitives was removed following Qiskit 0.46", + ) def test_init_observable_from_operator(self, abelian_grouping): """test for evaluate without parameters""" circuit = self.ansatz.assign_parameters([0, 1, 1, 2, 3, 5]) From a21f6a08156d7c5d43e4e231429f26030bf3af91 Mon Sep 17 00:00:00 2001 From: Jake Lishman Date: Fri, 2 Feb 2024 21:31:05 +0000 Subject: [PATCH 7/9] Prepare for Qiskit 1.0 (#2047) * Resolve CI dependencies in a single step and add qiskit==1.0.0rc1 job This modifies the dependency-resolution steps to do their job in a single step; Aer should have no dependencies pinning Qiskit, so we can use the preferable form more eagerly. This also adds a test run to the PR CI for Qiskit 1.0.0rc1 (or rc2, etc) that always runs, so Aer doesn't regress. Co-authored-by: Luciano Bello * Fix test suite to work with Qiskit<1.0 and >=1.0 This commit *does not* touch the primitives, which appear to be broken at a relatively basic level with Qiskit 1.0 - hopefully the primitives team can fix that separately. This modifies the test suite to work with both Qiskit 0.46 and 1.0.0rc1 simultaneously. Unfortunately, some of the new-style fake backends aren't in 0.46, so I just put in some import switches for my ease here. A few tests, particularly in the noise model sections, were asserting specific things about the properties/calibrations of Terra's fake backends, which was quite fragile already, so in those particular cases I replaced them with a manually constructed `Target` with properties entirely under Aer's control. * Run black --------- Co-authored-by: Luciano Bello --- .github/workflows/tests.yml | 51 ++++++--- .../workflows/unit-tests-latest-qiskit.yml | 15 +-- README.md | 10 +- .../aer_simulator/test_from_backend.py | 54 --------- .../backends/aer_simulator/test_options.py | 14 ++- .../backends/aer_simulator/test_truncate.py | 11 +- test/terra/noise/test_device_models.py | 71 ++++++++++-- test/terra/noise/test_noise_model.py | 105 ++++++++++-------- test/terra/states/test_aer_statevector.py | 29 ++--- 9 files changed, 193 insertions(+), 167 deletions(-) delete mode 100644 test/terra/backends/aer_simulator/test_from_backend.py diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2a6f245ee1..2bd6e3020c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -87,13 +87,18 @@ jobs: aer-test/bin/pip check shell: bash tests_linux: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest + name: Linux Python ${{ matrix.python-version }}${{ matrix.qiskit-extra && format(' ({0})', matrix.qiskit-extra) }} needs: [sdist, lint] timeout-minutes: 60 strategy: matrix: python-version: [3.8, 3.9, "3.10", "3.11", "3.12.0"] - os: ["ubuntu-latest"] + qiskit-extra: [""] + include: + - python-version: "3.10" + qiskit-extra: "'qiskit>=1.0.0rc1'" + env: AER_THRUST_BACKEND: OMP QISKIT_TEST_CAPTURE_STREAMS: 1 @@ -116,17 +121,19 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}-pip-test- ${{ runner.os }}-${{ matrix.python-version}}-pip- ${{ runner.os }}-${{ matrix.python-version}}- - - name: Install Deps - run: python -m pip install -U -c constraints.txt -r requirements-dev.txt wheel - name: Install openblas run: | set -e sudo apt-get update sudo apt-get install -y libopenblas-dev shell: bash - - name: Install Aer + - name: Install Aer and dependencies run: | - python -m pip install -U . + python -m pip install -U \ + -c constraints.txt \ + -r requirements-dev.txt \ + ${{ matrix.qiskit-extra }} \ + . - name: Run Tests run: | set -e @@ -185,13 +192,13 @@ jobs: stestr run --slowest shell: bash tests_macos: - runs-on: ${{ matrix.os }} + runs-on: macOS-latest + name: macOS Python ${{ matrix.python-version }} needs: [sdist, lint] timeout-minutes: 60 strategy: matrix: python-version: [3.8, 3.9, "3.10", '3.11', "3.12.0"] - os: ["macOS-latest"] env: AER_THRUST_BACKEND: OMP QISKIT_TEST_CAPTURE_STREAMS: 1 @@ -214,12 +221,13 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}-pip-test- ${{ runner.os }}-${{ matrix.python-version}}-pip- ${{ runner.os }}-${{ matrix.python-version}}- - - name: Install Deps + - name: Install Aer and dependencies run: | set -e - pip install -U -c constraints.txt -r requirements-dev.txt - - name: Install Aer - run: python -m pip install -U . + pip install -U \ + -c constraints.txt \ + -r requirements-dev.txt \ + . - name: Run Tests run: | set -e @@ -228,13 +236,13 @@ jobs: stestr run --slowest shell: bash tests_windows: - runs-on: ${{ matrix.os }} + runs-on: windows-2019 + name: Windows Python ${{ matrix.python-version }} needs: ["lint", "sdist"] timeout-minutes: 60 strategy: matrix: python-version: [3.8, 3.9, "3.10", "3.11", "3.12.0"] - os: ["windows-2019"] env: AER_THRUST_BACKEND: OMP QISKIT_TEST_CAPTURE_STREAMS: 1 @@ -259,15 +267,22 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}- - name: Add msbuild to PATH uses: microsoft/setup-msbuild@v1.0.2 - - name: Install Deps - run: python -m pip install -U -c constraints.txt -r requirements-dev.txt wheel build - - name: Install Aer Windows + - name: Build Aer Windows env: CMAKE_GENERATOR: "Visual Studio 16 2019" run: | set -e + pip install build python -I -m build --wheel - pip install -U dist/*.whl + shell: bash + - name: Install Aer and dependencies + run: | + set -e + shopt -s failglob + pip install -U \ + -c constraints.txt \ + -r requirements-dev.txt \ + dist/*.whl shell: bash - name: Run Tests env: diff --git a/.github/workflows/unit-tests-latest-qiskit.yml b/.github/workflows/unit-tests-latest-qiskit.yml index 425538529c..a0ecd9f7a1 100644 --- a/.github/workflows/unit-tests-latest-qiskit.yml +++ b/.github/workflows/unit-tests-latest-qiskit.yml @@ -31,19 +31,20 @@ jobs: ${{ runner.os }}-${{ matrix.python-version}}-pip-test- ${{ runner.os }}-${{ matrix.python-version}}-pip- ${{ runner.os }}-${{ matrix.python-version}}- - - name: Install Deps - run: | - python -m pip install -U -c constraints.txt -r requirements-dev.txt wheel - pip install -U git+https://github.com/Qiskit/qiskit.git - name: Install openblas run: | set -e sudo apt-get update sudo apt-get install -y libopenblas-dev shell: bash - - name: Install Aer + - name: Install dependencies and Aer run: | - python -m pip install -U . + python -m pip install -U setuptools wheel + python -m pip install -U \ + -c constraints.txt \ + -r requirements-dev.txt \ + 'git+https://github.com/Qiskit/qiskit.git@main' \ + . - name: Run Tests run: | set -e @@ -51,4 +52,4 @@ jobs: rm -rf qiskit_aer stestr run --slowest shell: bash - \ No newline at end of file + diff --git a/README.md b/README.md index 40492f4f3c..b579bd3a7a 100755 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ $ python ```python import qiskit from qiskit_aer import AerSimulator -from qiskit.providers.fake_provider import FakeManilaV2 +from qiskit_ibm_runtime import QiskitRuntimeService # Generate 3-qubit GHZ state circ = qiskit.QuantumCircuit(3) @@ -73,10 +73,10 @@ counts_ideal = result_ideal.get_counts(0) print('Counts(ideal):', counts_ideal) # Counts(ideal): {'000': 493, '111': 531} -# Construct a noisy simulator backend from an IBMQ backend -# This simulator backend will be automatically configured -# using the device configuration and noise model -backend = FakeManilaV2() +# Construct a simulator using a noise model +# from a real backend. +provider = QiskitRuntimeService() +backend = provider.get_backend("ibm_kyoto") aersim_backend = AerSimulator.from_backend(backend) # Perform noisy simulation diff --git a/test/terra/backends/aer_simulator/test_from_backend.py b/test/terra/backends/aer_simulator/test_from_backend.py deleted file mode 100644 index 0231f574f5..0000000000 --- a/test/terra/backends/aer_simulator/test_from_backend.py +++ /dev/null @@ -1,54 +0,0 @@ -# This code is part of Qiskit. -# -# (C) Copyright IBM 2022 -# -# This code is licensed under the Apache License, Version 2.0. You may -# obtain a copy of this license in the LICENSE.txt file in the root directory -# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. -# -# Any modifications or derivative works of this code must retain this -# copyright notice, and modified files need to carry a notice indicating -# that they have been altered from the originals. -""" -AerSimulator Integration Tests -""" - -from test.terra.backends.simulator_test_case import SimulatorTestCase - -from qiskit.providers.fake_provider import FakeNairobi, FakeNairobiV2 -from qiskit.circuit import QuantumCircuit -from qiskit.compiler import transpile - -from qiskit_aer import AerSimulator - - -class TestAlgorithms(SimulatorTestCase): - """AerSimulator algorithm tests in the default basis""" - - def setUp(self): - super().setUp() - self.qc = QuantumCircuit(2) - self.qc.h(0) - self.qc.cx(0, 1) - self.qc.measure_all() - - def test_backend_v1(self): - """Test from_backend_v1 works.""" - backend = FakeNairobi() - sim_backend = AerSimulator.from_backend(backend) - tqc = transpile(self.qc, backend) - self.assertEqual( - backend.run(tqc, shots=1024, seed_simulator=12345678942).result().get_counts(), - sim_backend.run(tqc, shots=1024, seed_simulator=12345678942).result().get_counts(), - ) - - def test_backend_v2(self): - """Test from_backend_v2 works.""" - backend = FakeNairobiV2() - sim_backend = AerSimulator.from_backend(backend) - tqc = transpile(self.qc, backend) - self.assertDictAlmostEqual( - backend.run(tqc, shots=1024, seed_simulator=12345678942).result().get_counts(), - sim_backend.run(tqc, shots=1024, seed_simulator=12345678942).result().get_counts(), - delta=100, - ) diff --git a/test/terra/backends/aer_simulator/test_options.py b/test/terra/backends/aer_simulator/test_options.py index e670177866..79a8911585 100644 --- a/test/terra/backends/aer_simulator/test_options.py +++ b/test/terra/backends/aer_simulator/test_options.py @@ -14,12 +14,18 @@ """ from ddt import ddt, data -from qiskit import QuantumCircuit, transpile from qiskit_aer.noise import NoiseModel from test.terra.backends.simulator_test_case import SimulatorTestCase, supported_methods + +import qiskit +from qiskit import QuantumCircuit, transpile from qiskit.quantum_info.random import random_unitary from qiskit.quantum_info import state_fidelity -from qiskit.providers.fake_provider import FakeMontreal + +if qiskit.__version__.startswith("0."): + from qiskit.providers.fake_provider import FakeAlmaden as Fake20QV1 +else: + from qiskit.providers.fake_provider import Fake20QV1 from qiskit_aer import AerSimulator @@ -299,6 +305,6 @@ def test_statevector_memory(self): def test_num_qubits(self, method): """Test number of qubits is correctly checked""" - num_qubits = FakeMontreal().configuration().num_qubits - backend = AerSimulator.from_backend(FakeMontreal(), method=method) + num_qubits = Fake20QV1().configuration().num_qubits + backend = AerSimulator.from_backend(Fake20QV1(), method=method) self.assertGreaterEqual(backend.configuration().num_qubits, num_qubits) diff --git a/test/terra/backends/aer_simulator/test_truncate.py b/test/terra/backends/aer_simulator/test_truncate.py index eb98b10546..136623b9e5 100644 --- a/test/terra/backends/aer_simulator/test_truncate.py +++ b/test/terra/backends/aer_simulator/test_truncate.py @@ -9,8 +9,15 @@ AerSimulator Integration Tests """ from ddt import ddt + +import qiskit from qiskit import transpile, QuantumCircuit -from qiskit.providers.fake_provider import FakeQuito + +if qiskit.__version__.startswith("0."): + from qiskit.providers.fake_provider import FakeQuito as Fake5QV1 +else: + from qiskit.providers.fake_provider import Fake5QV1 + from qiskit_aer.noise import NoiseModel from test.terra.backends.simulator_test_case import SimulatorTestCase, supported_methods @@ -46,7 +53,7 @@ def create_circuit_for_truncate(self): return circuit def device_backend(self): - return FakeQuito() + return Fake5QV1() def test_truncate_ideal_sparse_circuit(self): """Test qubit truncation for large circuit with unused qubits.""" diff --git a/test/terra/noise/test_device_models.py b/test/terra/noise/test_device_models.py index aad6c1e38c..43d90fda91 100644 --- a/test/terra/noise/test_device_models.py +++ b/test/terra/noise/test_device_models.py @@ -16,29 +16,73 @@ import numpy as np from test.terra.common import QiskitAerTestCase -from qiskit.circuit.library.standard_gates import XGate -from qiskit.providers.fake_provider import FakeNairobi, FakeNairobiV2 -from qiskit.transpiler import Target, QubitProperties, InstructionProperties +import qiskit +from qiskit.circuit import library, Reset, Measure, Parameter +from qiskit.providers import convert_to_target +from qiskit.transpiler import CouplingMap, Target, QubitProperties, InstructionProperties + +if qiskit.__version__.startswith("0."): + from qiskit.providers.fake_provider import FakeQuito as Fake5QV1 +else: + from qiskit.providers.fake_provider import Fake5QV1 + from qiskit_aer.noise.device.models import basic_device_gate_errors from qiskit_aer.noise.errors.standard_errors import thermal_relaxation_error +def target_7q(): + """Build an arbitrary 7q ``Target`` with noisy instructions.""" + num_qubits = 7 + qubit_properties = [ + QubitProperties(t1=1.5e-4, t2=1.5e-4, frequency=4_700_000_000.0 + q * 50_000_000.0) + for q in range(num_qubits) + ] + target = Target(num_qubits=7, qubit_properties=qubit_properties) + for gate in (library.SXGate(), library.XGate(), library.RZGate(Parameter("a"))): + target.add_instruction( + gate, + properties={ + (q,): InstructionProperties(duration=50e-9, error=2e-4) for q in range(num_qubits) + }, + ) + target.add_instruction( + library.CXGate(), + properties={ + link: InstructionProperties(duration=300e-9, error=1e-3) + for link in CouplingMap.from_ring(num_qubits) + }, + ) + target.add_instruction( + Reset(), + properties={ + (q,): InstructionProperties(duration=4e-6, error=None) for q in range(num_qubits) + }, + ) + target.add_instruction( + Measure(), + properties={ + (q,): InstructionProperties(duration=3e-6, error=1.5e-2) for q in range(num_qubits) + }, + ) + return target + + class TestDeviceNoiseModel(QiskitAerTestCase): """Testing device noise model""" def test_basic_device_gate_errors_from_target(self): """Test if the resulting gate errors never include errors on non-gate instructions""" - target = FakeNairobiV2().target + target = target_7q() gate_errors = basic_device_gate_errors(target=target) errors_on_measure = [name for name, _, _ in gate_errors if name == "measure"] errors_on_reset = [name for name, _, _ in gate_errors if name == "reset"] self.assertEqual(len(errors_on_measure), 0) self.assertEqual(len(errors_on_reset), 7) - self.assertEqual(len(gate_errors), 40) + self.assertEqual(len(gate_errors), 42) def test_basic_device_gate_errors_from_target_with_non_operational_qubits(self): """Test if no thermal relaxation errors are generated for qubits with undefined T1 and T2.""" - target = FakeNairobiV2().target + target = target_7q() # tweak target to have non-operational qubits faulty_qubits = (1, 2) for q in faulty_qubits: @@ -47,7 +91,7 @@ def test_basic_device_gate_errors_from_target_with_non_operational_qubits(self): gate_errors = basic_device_gate_errors(target=target, gate_error=False) errors_on_sx = {qubits: error for name, qubits, error in gate_errors if name == "sx"} errors_on_cx = {qubits: error for name, qubits, error in gate_errors if name == "cx"} - self.assertEqual(len(gate_errors), 40) + self.assertEqual(len(gate_errors), 42) # check if no errors are added on sx gates on qubits without T1 and T2 definitions for q in faulty_qubits: self.assertTrue(errors_on_sx[(q,)].ideal()) @@ -56,8 +100,13 @@ def test_basic_device_gate_errors_from_target_with_non_operational_qubits(self): def test_basic_device_gate_errors_from_target_and_properties(self): """Test if the device same gate errors are produced both from target and properties""" - errors_from_properties = basic_device_gate_errors(properties=FakeNairobi().properties()) - errors_from_target = basic_device_gate_errors(target=FakeNairobiV2().target) + backend = Fake5QV1() + target = convert_to_target( + configuration=backend.configuration(), + properties=backend.properties(), + ) + errors_from_properties = basic_device_gate_errors(properties=backend.properties()) + errors_from_target = basic_device_gate_errors(target=target) self.assertEqual(len(errors_from_properties), len(errors_from_target)) errors_from_properties_s = sorted(errors_from_properties) errors_from_target_s = sorted(errors_from_target) @@ -71,7 +120,7 @@ def test_basic_device_gate_errors_from_target_and_properties(self): def test_basic_device_gate_errors_from_target_with_no_t2_value(self): """Test if gate errors are successfully created from a target with qubits not reporting T2. See https://github.com/Qiskit/qiskit-aer/issues/1896 for the details.""" - target = FakeNairobiV2().target + target = target_7q() target.qubit_properties[0].t2 = None basic_device_gate_errors(target=target) @@ -80,7 +129,7 @@ def test_non_zero_temperature(self): See https://github.com/Qiskit/qiskit-aer/issues/1937 for the details.""" t1, t2, frequency, duration = 1e-4, 1e-4, 5e9, 5e-8 target = Target(qubit_properties=[QubitProperties(t1=t1, t2=t2, frequency=frequency)]) - target.add_instruction(XGate(), {(0,): InstructionProperties(duration=duration)}) + target.add_instruction(library.XGate(), {(0,): InstructionProperties(duration=duration)}) errors = basic_device_gate_errors(target=target, gate_error=False, temperature=100) _, _, x_error = errors[0] no_excitation_error = thermal_relaxation_error(t1, t2, duration, excited_state_population=0) diff --git a/test/terra/noise/test_noise_model.py b/test/terra/noise/test_noise_model.py index d851288459..ebad6ffe75 100644 --- a/test/terra/noise/test_noise_model.py +++ b/test/terra/noise/test_noise_model.py @@ -29,21 +29,39 @@ from qiskit_aer.noise.errors.standard_errors import thermal_relaxation_error from qiskit_aer.utils.noise_transformation import transform_noise_model +import qiskit from qiskit.circuit import QuantumRegister, ClassicalRegister, QuantumCircuit from qiskit.circuit.library.generalized_gates import PauliGate from qiskit.circuit.library.standard_gates import IGate, XGate from qiskit.compiler import transpile -from qiskit.providers import QubitProperties -from qiskit.providers.fake_provider import ( - FakeBackend, - FakeAlmaden, - FakeLagos, - FakeSingapore, - FakeMumbai, - FakeKolkata, - FakeBackendV2, - FakeLagosV2, -) +from qiskit.transpiler import CouplingMap, Target +from qiskit.providers import QubitProperties, BackendV2, Options + +if qiskit.__version__.startswith("0."): + from qiskit.providers.fake_provider import ( + FakeBackend, + FakeAlmaden as Fake20QV1, + FakeMumbai as Fake27QPulseV1, + FakeLagosV2, + ) + + def fake_7q_v2(): + """Generate a dummy 7q V2 backend.""" + return FakeLagosV2() + +else: + from qiskit.providers.fake_provider import ( + FakeBackend, + Fake20QV1, + Fake27QPulseV1, + GenericBackendV2, + ) + + def fake_7q_v2(): + """Generate a dummy 7q V2 backend.""" + return GenericBackendV2(num_qubits=7, coupling_map=CouplingMap.from_ring(7), seed=0) + + from test.terra.common import QiskitAerTestCase @@ -197,62 +215,37 @@ def test_noise_models_not_equal(self): model2 = NoiseModel(basis_gates=["u3", "cx"]) model2.add_all_qubit_quantum_error(error, ["u3"], False) - def test_noise_model_from_backend_singapore(self): + def test_noise_model_from_backend_20(self): circ = QuantumCircuit(2) circ.x(0) circ.x(1) circ.measure_all() - backend = FakeSingapore() + backend = Fake20QV1() noise_model = NoiseModel.from_backend(backend) circ = transpile(circ, backend, optimization_level=0) result = AerSimulator().run(circ, noise_model=noise_model).result() self.assertTrue(result.success) - def test_noise_model_from_backend_almaden(self): + def test_noise_model_from_backend_27_pulse(self): circ = QuantumCircuit(2) circ.x(0) circ.x(1) circ.measure_all() - backend = FakeAlmaden() - noise_model = NoiseModel.from_backend(backend) - circ = transpile(circ, backend, optimization_level=0) - result = AerSimulator().run(circ, noise_model=noise_model).result() - self.assertTrue(result.success) - - def test_noise_model_from_mumbai(self): - circ = QuantumCircuit(2) - circ.x(0) - circ.x(1) - circ.measure_all() - - backend = FakeMumbai() + backend = Fake27QPulseV1() noise_model = NoiseModel.from_backend(backend) circ = transpile(circ, backend, optimization_level=0) result = AerSimulator().run(circ, noise_model=noise_model).result() self.assertTrue(result.success) def test_noise_model_from_backend_v2(self): - circ = QuantumCircuit(2) - circ.x(0) - circ.x(1) - circ.measure_all() - - backend = FakeBackendV2() - noise_model = NoiseModel.from_backend(backend) - self.assertEqual([0, 1], noise_model.noise_qubits) - circ = transpile(circ, backend, optimization_level=0) - result = AerSimulator().run(circ, noise_model=noise_model).result() - self.assertTrue(result.success) - - def test_noise_model_from_lagos_v2(self): circ = QuantumCircuit(2) circ.x(0) circ.cx(0, 1) circ.measure_all() - backend = FakeLagosV2() + backend = fake_7q_v2() noise_model = NoiseModel.from_backend(backend) self.assertEqual([0, 1, 2, 3, 4, 5, 6], noise_model.noise_qubits) circ = transpile(circ, backend, optimization_level=0) @@ -262,7 +255,7 @@ def test_noise_model_from_lagos_v2(self): def test_noise_model_from_backend_v2_with_non_operational_qubits(self): """Test if possible to create a noise model from backend with non-operational qubits. See issues #1779 and #1815 for the details.""" - backend = FakeLagosV2() + backend = fake_7q_v2() # tweak target to have non-operational qubits faulty_qubits = [0, 1] for qubit in faulty_qubits: @@ -342,9 +335,29 @@ def properties(self): def test_create_noise_model_without_user_warnings(self): """Test if never issue user warnings when creating a noise model from backend. See issue#1631 for the details.""" - # FakeKolkata has a qubit with T_2 > 2 * T_1 + + class BadlyCalibratedBackendV2(BackendV2): + """A backend with `t2 > 2*t1` due to awkward calibration statistics.""" + + @property + def target(self): + return Target( + num_qubits=1, qubit_properties=[QubitProperties(t1=1.2e-3, t2=2.5e-3)] + ) + + @property + def max_circuits(self): + return None + + @classmethod + def _default_options(cls): + return Options() + + def run(self, run_input, **options): + raise NotImplementedError + with warnings.catch_warnings(record=True) as warns: - NoiseModel.from_backend(FakeKolkata()) + NoiseModel.from_backend(BadlyCalibratedBackendV2()) user_warnings = [w for w in warns if issubclass(w.category, UserWarning)] self.assertEqual(len(user_warnings), 0) @@ -354,7 +367,7 @@ def test_noise_model_from_backend_properties(self): circ.x(1) circ.measure_all() - backend = FakeAlmaden() + backend = Fake20QV1() backend_propeties = backend.properties() noise_model = NoiseModel.from_backend_properties(backend_propeties) circ = transpile(circ, backend, optimization_level=0) @@ -388,7 +401,7 @@ def test_can_run_circuits_with_delay_noise(self): circ.cx(0, 1) circ.measure_all() - backend = FakeLagosV2() + backend = fake_7q_v2() noise_model = NoiseModel.from_backend(backend) qc = transpile(circ, backend, scheduling_method="alap") diff --git a/test/terra/states/test_aer_statevector.py b/test/terra/states/test_aer_statevector.py index 0797d6178e..0a78d681d5 100644 --- a/test/terra/states/test_aer_statevector.py +++ b/test/terra/states/test_aer_statevector.py @@ -14,17 +14,16 @@ """ import unittest -from math import pi -import numpy as np import logging from itertools import permutations from ddt import ddt, data + +import numpy as np from numpy.testing import assert_allclose from qiskit import transpile from qiskit.exceptions import QiskitError from qiskit.circuit import QuantumCircuit, QuantumRegister -from qiskit.providers.basicaer import QasmSimulatorPy from qiskit.quantum_info.random import random_unitary, random_statevector, random_pauli from qiskit.quantum_info.states import Statevector from qiskit.circuit.library import QuantumVolume @@ -35,13 +34,12 @@ from qiskit.visualization.state_visualization import state_to_latex from qiskit.circuit.library import QFT, HGate from qiskit.circuit.library import DiagonalGate +from qiskit.quantum_info.operators.predicates import ATOL_DEFAULT, RTOL_DEFAULT -from test.terra import common -from qiskit_aer import AerSimulator -from qiskit_aer.aererror import AerError -from qiskit_aer.noise import pauli_error, QuantumError +from qiskit_aer.noise import pauli_error from qiskit_aer.quantum_info.states import AerStatevector -from qiskit.quantum_info.operators.predicates import ATOL_DEFAULT, RTOL_DEFAULT + +from test.terra import common logger = logging.getLogger(__name__) @@ -1311,18 +1309,9 @@ def test_probabilities_qargs(self, qargs): probs = state.probabilities(qargs) # Estimate target probs from simulator measurement - sim = QasmSimulatorPy() - shots = 5000 - seed = 100 - circ = transpile(state_circ, sim) - circ.measure(qargs, range(nc)) - result = sim.run(circ, shots=shots, seed_simulator=seed).result() - target = np.zeros(2**nc, dtype=float) - for i, p in result.get_counts(0).int_outcomes().items(): - target[i] = p / shots - # Compare - delta = np.linalg.norm(probs - target) - self.assertLess(delta, 0.05) + terra_state = Statevector(state_circ) + terra_probs = terra_state.probabilities(qargs) + assert_allclose(probs, terra_probs) def test_global_phase(self): """Test global phase is handled correctly when evolving statevector.""" From 890a42d15ad1c156705eaed7abd8ed0eeb7da18a Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Tue, 6 Feb 2024 11:34:55 +0900 Subject: [PATCH 8/9] add prelude --- releasenotes/notes/release0.13.3-b144015572a25737.yaml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 releasenotes/notes/release0.13.3-b144015572a25737.yaml diff --git a/releasenotes/notes/release0.13.3-b144015572a25737.yaml b/releasenotes/notes/release0.13.3-b144015572a25737.yaml new file mode 100644 index 0000000000..71533ba2f7 --- /dev/null +++ b/releasenotes/notes/release0.13.3-b144015572a25737.yaml @@ -0,0 +1,3 @@ +--- +prelude: > + Aer 0.13.3 is a minor release to support Qiskit 0.46 and 1.0. From 5baadeedaff8402b1d5efc2fb2aa7c2f5d9d744c Mon Sep 17 00:00:00 2001 From: Jun Doi Date: Tue, 6 Feb 2024 15:53:29 +0900 Subject: [PATCH 9/9] fix version numbers --- docs/conf.py | 4 ++-- qiskit_aer/VERSION.txt | 2 +- .../notes/{ => 0.13}/release0.13.1-a07688e4eb04b9d6.yaml | 0 3 files changed, 3 insertions(+), 3 deletions(-) rename releasenotes/notes/{ => 0.13}/release0.13.1-a07688e4eb04b9d6.yaml (100%) diff --git a/docs/conf.py b/docs/conf.py index da1adfa30f..cbc8c94ccc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -45,9 +45,9 @@ author = 'Qiskit Development Team' # The short X.Y version -version = '0.13.1' +version = '0.13.3' # The full version, including alpha/beta/rc tags -release = '0.13.1' +release = '0.13.3' templates_path = ['_templates'] diff --git a/qiskit_aer/VERSION.txt b/qiskit_aer/VERSION.txt index 9beb74d490..288adf538f 100644 --- a/qiskit_aer/VERSION.txt +++ b/qiskit_aer/VERSION.txt @@ -1 +1 @@ -0.13.2 +0.13.3 diff --git a/releasenotes/notes/release0.13.1-a07688e4eb04b9d6.yaml b/releasenotes/notes/0.13/release0.13.1-a07688e4eb04b9d6.yaml similarity index 100% rename from releasenotes/notes/release0.13.1-a07688e4eb04b9d6.yaml rename to releasenotes/notes/0.13/release0.13.1-a07688e4eb04b9d6.yaml