From 68c145c7af350ee2f3ef556bda685020228170cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elena=20Pe=C3=B1a=20Tapia?= Date: Tue, 28 Nov 2023 18:18:06 +0100 Subject: [PATCH] Include missing tests --- qiskit/providers/fake_provider/__init__.py | 2 +- .../operators/symplectic/test_sparse_pauli_op.py | 8 ++++---- test/python/transpiler/test_normalize_rx_angle.py | 8 ++++---- test/python/transpiler/test_unitary_synthesis.py | 10 ++++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/qiskit/providers/fake_provider/__init__.py b/qiskit/providers/fake_provider/__init__.py index cb8268451957..d66a29222e00 100644 --- a/qiskit/providers/fake_provider/__init__.py +++ b/qiskit/providers/fake_provider/__init__.py @@ -265,4 +265,4 @@ # Configurable fake backend from .utils.configurable_backend import ConfigurableFakeBackend -from .fake_generic import FakeGeneric +from .fake_generic import FakeGeneric, GenericTarget diff --git a/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py b/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py index c519855faa6f..65f7a0bfa50c 100644 --- a/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py +++ b/test/python/quantum_info/operators/symplectic/test_sparse_pauli_op.py @@ -26,7 +26,7 @@ from qiskit.test import QiskitTestCase from qiskit.circuit.library import EfficientSU2 from qiskit.primitives import BackendEstimator -from qiskit.providers.fake_provider import FakeNairobiV2 +from qiskit.providers.fake_provider import FakeGeneric from qiskit.compiler.transpiler import transpile @@ -1033,7 +1033,7 @@ def test_apply_layout_with_transpile(self): """Test the apply_layout method with a transpiler layout.""" psi = EfficientSU2(4, reps=4, entanglement="circular") op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)]) - backend = FakeNairobiV2() + backend = FakeGeneric(num_qubits=7, basis_gates=["cx", "x", "id", "sx", "rz"]) transpiled_psi = transpile(psi, backend, optimization_level=3, seed_transpiler=12345) permuted_op = op.apply_layout(transpiled_psi.layout) identity_op = SparsePauliOp("I" * 7) @@ -1048,7 +1048,7 @@ def test_permute_sparse_pauli_op_estimator_example(self): """Test using the apply_layout method with an estimator workflow.""" psi = EfficientSU2(4, reps=4, entanglement="circular") op = SparsePauliOp.from_list([("IIII", 1), ("IZZZ", 2), ("XXXI", 3)]) - backend = FakeNairobiV2() + backend = FakeGeneric(num_qubits=7, basis_gates=["cx", "x", "id", "sx", "rz"], seed=0) backend.set_options(seed_simulator=123) estimator = BackendEstimator(backend=backend, skip_transpilation=True) thetas = list(range(len(psi.parameters))) @@ -1056,7 +1056,7 @@ def test_permute_sparse_pauli_op_estimator_example(self): permuted_op = op.apply_layout(transpiled_psi.layout) job = estimator.run(transpiled_psi, permuted_op, thetas) res = job.result().values - np.testing.assert_allclose(res, [1.35351562], rtol=0.5, atol=0.2) + np.testing.assert_allclose(res, [5.859375], rtol=0.5, atol=0.2) def test_apply_layout_invalid_qubits_list(self): """Test that apply_layout with an invalid qubit count raises.""" diff --git a/test/python/transpiler/test_normalize_rx_angle.py b/test/python/transpiler/test_normalize_rx_angle.py index b3669b841afe..719c3516a0b3 100644 --- a/test/python/transpiler/test_normalize_rx_angle.py +++ b/test/python/transpiler/test_normalize_rx_angle.py @@ -22,7 +22,7 @@ NormalizeRXAngle, ) from qiskit.test import QiskitTestCase -from qiskit.providers.fake_provider import FakeBelemV2 +from qiskit.providers.fake_provider import FakeGeneric from qiskit.transpiler import Target from qiskit.circuit.library.standard_gates import SXGate @@ -60,7 +60,7 @@ def test_rz_added_for_negative_rotation_angles(self): """Check that RZ is added before and after RX, if RX rotation angle is negative""" - backend = FakeBelemV2() + backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]) tp = NormalizeRXAngle(target=backend.target) # circuit to transpile and test @@ -83,7 +83,7 @@ def test_rz_added_for_negative_rotation_angles(self): ) def test_angle_wrapping_works(self, raw_theta, correct_wrapped_theta): """Check that RX rotation angles are correctly wrapped to [0, pi]""" - backend = FakeBelemV2() + backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]) tp = NormalizeRXAngle(target=backend.target) # circuit to transpile and test @@ -118,7 +118,7 @@ def test_quantize_angles(self, resolution, rx_angles, correct_num_of_cals): """Test that quantize_angles() adds a new calibration only if the requested angle is not in the vicinity of the already generated angles. """ - backend = FakeBelemV2() + backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]) tp = NormalizeRXAngle(backend.target, resolution_in_radian=resolution) qc = QuantumCircuit(1) diff --git a/test/python/transpiler/test_unitary_synthesis.py b/test/python/transpiler/test_unitary_synthesis.py index d93b03934173..6de3a7600c05 100644 --- a/test/python/transpiler/test_unitary_synthesis.py +++ b/test/python/transpiler/test_unitary_synthesis.py @@ -24,7 +24,7 @@ from qiskit import transpile from qiskit.test import QiskitTestCase -from qiskit.providers.fake_provider import FakeVigo, FakeMumbaiFractionalCX, FakeBelemV2 +from qiskit.providers.fake_provider import FakeVigo, FakeMumbaiFractionalCX, FakeGeneric from qiskit.providers.fake_provider.fake_backend_v2 import FakeBackendV2, FakeBackend5QV2 from qiskit.circuit import QuantumCircuit, QuantumRegister, ClassicalRegister from qiskit.circuit.library import QuantumVolume @@ -846,7 +846,8 @@ def test_single_qubit_with_target(self): qc = QuantumCircuit(1) qc.append(ZGate(), [qc.qubits[0]]) dag = circuit_to_dag(qc) - unitary_synth_pass = UnitarySynthesis(target=FakeBelemV2().target) + backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]) + unitary_synth_pass = UnitarySynthesis(target=backend.target) result_dag = unitary_synth_pass.run(dag) result_qc = dag_to_circuit(result_dag) self.assertEqual(qc, result_qc) @@ -856,7 +857,8 @@ def test_single_qubit_identity_with_target(self): qc = QuantumCircuit(1) qc.unitary([[1.0, 0.0], [0.0, 1.0]], 0) dag = circuit_to_dag(qc) - unitary_synth_pass = UnitarySynthesis(target=FakeBelemV2().target) + backend = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]) + unitary_synth_pass = UnitarySynthesis(target=backend.target) result_dag = unitary_synth_pass.run(dag) result_qc = dag_to_circuit(result_dag) self.assertEqual(result_qc, QuantumCircuit(1)) @@ -866,7 +868,7 @@ def test_unitary_synthesis_with_ideal_and_variable_width_ops(self): qc = QuantumCircuit(2) qc.unitary(np.eye(4), [0, 1]) dag = circuit_to_dag(qc) - target = FakeBelemV2().target + target = FakeGeneric(num_qubits=5, basis_gates=["cx", "x", "id", "sx", "rz"]).target target.add_instruction(IfElseOp, name="if_else") target.add_instruction(ZGate()) target.add_instruction(ECRGate())