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/qiskit/providers/fake_provider/fake_generic.py b/qiskit/providers/fake_provider/fake_generic.py index e8f3a0f07907..6a4b10cc0753 100644 --- a/qiskit/providers/fake_provider/fake_generic.py +++ b/qiskit/providers/fake_provider/fake_generic.py @@ -77,8 +77,8 @@ def __init__( control_flow (bool): Flag to enable control flow directives on the backend (defaults to False). - calibrate_gates (list[str] | None): List of gate names which should contain - default calibration entries. These must be a subset of ``basis_gates``. + calibrate_gates (list[str] | None): List of gate names (subset of basis_gates) + to add default calibration entries to. rng (np.random.Generator): Optional fixed-seed generator for default random values. """ @@ -111,9 +111,10 @@ def __init__( ) # ensure that Reset, Delay and Measure are in basis_gates - self._basis_gates = set(basis_gates) + self._basis_gates = basis_gates for name in ["reset", "delay", "measure"]: - self._basis_gates.add(name) + if name not in self._basis_gates: + self._basis_gates.append(name) # iterate over gates, generate noise params. from defaults # and add instructions to target @@ -121,7 +122,7 @@ def __init__( if name not in self.supported_operations: raise QiskitError( f"Provided base gate {name} is not a supported " - f"operation ({self.supported_operations})." + f"operation ({self.supported_operations.keys()})." ) gate = self.supported_operations[name] noise_params = self.noise_defaults[name] @@ -228,7 +229,7 @@ def add_calibrations_from_instruction_schedule_map( """Add calibration entries from provided pulse defaults to target. Args: - defaults (PulseDefaults): pulse defaults with instruction schedule map + inst_map (InstructionScheduleMap): pulse defaults with instruction schedule map Returns: None @@ -390,9 +391,8 @@ def __init__( control_flow (bool): Flag to enable control flow directives on the backend (defaults to False). - calibrate_gates (list[str] | None): List of gate names which should contain - default calibration entries (overriden if an ``instruction_schedule_map`` is - provided). These must be a subset of ``basis_gates``. + calibrate_gates (list[str] | None): List of gate names (subset of basis_gates) + to add default calibration entries to. seed (int): Optional seed for generation of default values. """ diff --git a/test/python/primitives/test_backend_estimator.py b/test/python/primitives/test_backend_estimator.py index 80e96db433a9..bccd55721d90 100644 --- a/test/python/primitives/test_backend_estimator.py +++ b/test/python/primitives/test_backend_estimator.py @@ -394,7 +394,7 @@ def test_layout(self, backend): value = estimator.run(qc, op, shots=10000).result().values[0] if optionals.HAS_AER and not isinstance(backend, FakeBackendSimple): - self.assertEqual(value, -0.9154) + self.assertEqual(value, -0.916) else: self.assertEqual(value, -1) @@ -410,7 +410,7 @@ def test_layout(self, backend): value = estimator.run(qc, op, shots=10000).result().values[0] if optionals.HAS_AER and not isinstance(backend, FakeBackendSimple): - self.assertEqual(value, -0.8908) + self.assertEqual(value, -0.8902) else: self.assertEqual(value, -1) 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_sabre_layout.py b/test/python/transpiler/test_sabre_layout.py index 64959df83d82..517978e50f33 100644 --- a/test/python/transpiler/test_sabre_layout.py +++ b/test/python/transpiler/test_sabre_layout.py @@ -434,7 +434,7 @@ def test_integration_with_pass_manager(self): qct_initial_layout = qct.layout.initial_layout self.assertEqual( [qct_initial_layout[q] for q in self.circuit.qubits], - [1, 6, 5, 10, 11, 12, 16, 17, 18, 13, 14, 9, 8, 3, 2, 0], + [8, 9, 14, 13, 18, 19, 17, 16, 11, 10, 5, 6, 1, 2, 3, 7], ) 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()) diff --git a/test/python/transpiler/test_vf2_post_layout.py b/test/python/transpiler/test_vf2_post_layout.py index 5c12ff11a815..9d8a72963316 100644 --- a/test/python/transpiler/test_vf2_post_layout.py +++ b/test/python/transpiler/test_vf2_post_layout.py @@ -300,8 +300,12 @@ def test_2q_circuit_5q_backend_max_trials(self): def test_best_mapping_ghz_state_full_device_multiple_qregs_v2(self): """Test best mappings with multiple registers""" backend = FakeGeneric( - num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], coupling_map=LIMA_CM + num_qubits=5, basis_gates=["cx", "id", "rz", "sx", "x"], coupling_map=LIMA_CM, seed=123 ) + + for i in range(len(backend.target.instructions)): + print(backend.target.instructions[i], backend.target.instruction_properties(i)) + qr_a = QuantumRegister(2) qr_b = QuantumRegister(3) qc = QuantumCircuit(qr_a, qr_b)