From fd9c5755fb825a22aad807974fd974ad5ad18c1d Mon Sep 17 00:00:00 2001 From: Toshinari Itoko Date: Thu, 9 Nov 2023 12:32:33 +0900 Subject: [PATCH] Fix for supporting BackendV2 simulators --- .../randomized_benchmarking/standard_rb.py | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/qiskit_experiments/library/randomized_benchmarking/standard_rb.py b/qiskit_experiments/library/randomized_benchmarking/standard_rb.py index 61c3bb03a7..fe3344200d 100644 --- a/qiskit_experiments/library/randomized_benchmarking/standard_rb.py +++ b/qiskit_experiments/library/randomized_benchmarking/standard_rb.py @@ -233,21 +233,26 @@ def _get_synthesis_options(self) -> Dict[str, Optional[Any]]: coupling_map = coupling_map.reduce(self.physical_qubits) if not (basis_gates and coupling_map) and self.backend: if isinstance(self.backend, BackendV2) and self.backend.target: - backend_basis_gates = [] - backend_cmap = None - for op in self.backend.target.operations: - if op.num_qubits == 2: - cmap = self.backend.target.build_coupling_map(op.name) - if cmap: - reduced = cmap.reduce(self.physical_qubits) - if rx.is_weakly_connected(reduced.graph): + if "simulator" in self.backend.name: + basis_gates = basis_gates if basis_gates else self.backend.target.operation_names + coupling_map = coupling_map if coupling_map else None + else: + backend_basis_gates = [op.name for op in self.backend.target.operations if op.num_qubits != 2] + backend_cmap = None + for op in self.backend.target.operations: + if op.num_qubits == 2: + cmap = self.backend.target.build_coupling_map(op.name) + if cmap is None: backend_basis_gates.append(op.name) - backend_cmap = reduced - break - else: - backend_basis_gates.append(op.name) - basis_gates = basis_gates if basis_gates else backend_basis_gates - coupling_map = coupling_map if coupling_map else backend_cmap + else: + reduced = cmap.reduce(self.physical_qubits) + if rx.is_weakly_connected(reduced.graph): + backend_basis_gates.append(op.name) + backend_cmap = reduced + # take the first non-global 2q gate if the backend supports multiple 2q gates + break + basis_gates = basis_gates if basis_gates else backend_basis_gates + coupling_map = coupling_map if coupling_map else backend_cmap elif isinstance(self.backend, BackendV1): backend_basis_gates = self.backend.configuration().basis_gates backend_cmap = self.backend.configuration().coupling_map @@ -377,8 +382,8 @@ def _transpiled_circuits(self) -> List[QuantumCircuit]: _transpile_clifford_circuit(circ, physical_qubits=self.physical_qubits) for circ in self.circuits() ] - # Set custom calibrations provided in backend - if isinstance(self.backend, BackendV2): + # Set custom calibrations provided in backend (excluding simulators) + if isinstance(self.backend, BackendV2) and "simulator" not in self.backend.name: qargs_patterns = [self.physical_qubits] # for 1q or 3q+ case if self.num_qubits == 2: qargs_patterns = [