Skip to content

Commit

Permalink
Fix for supporting BackendV2 simulators
Browse files Browse the repository at this point in the history
  • Loading branch information
itoko committed Nov 9, 2023
1 parent d9ea243 commit fd9c575
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions qiskit_experiments/library/randomized_benchmarking/standard_rb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down

0 comments on commit fd9c575

Please sign in to comment.