Skip to content

Commit

Permalink
Fix a bug where calibrations are not added to RB circuit for 3q custo…
Browse files Browse the repository at this point in the history
…m pulse gates
  • Loading branch information
itoko committed Oct 18, 2023
1 parent 2cb8f02 commit 800075f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,8 @@ def _transpiled_circuits(self) -> List[QuantumCircuit]:
]
# Set custom calibrations provided in backend
if isinstance(self.backend, BackendV2):
qargs_patterns = []
if self.num_qubits == 1:
qargs_patterns = [self.physical_qubits]
elif self.num_qubits == 2:
qargs_patterns = [self.physical_qubits] # for 1q or 3q+ case
if self.num_qubits == 2:
qargs_patterns = [
(self.physical_qubits[0],),
(self.physical_qubits[1],),
Expand Down
26 changes: 26 additions & 0 deletions test/library/randomized_benchmarking/test_interleaved_rb.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
from test.library.randomized_benchmarking.mixin import RBTestMixin
from ddt import ddt, data, unpack

from qiskit import pulse
from qiskit.circuit import Delay, QuantumCircuit, Parameter, Gate
from qiskit.circuit.library import SXGate, CXGate, TGate, CZGate
from qiskit.exceptions import QiskitError
from qiskit.providers.fake_provider import FakeManila, FakeManilaV2, FakeWashington
from qiskit.transpiler import InstructionProperties
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel, depolarizing_error
from qiskit_experiments.library import randomized_benchmarking as rb
Expand Down Expand Up @@ -281,6 +283,30 @@ def test_interleaving_cnot_gate_with_non_supported_direction(self):
with self.assertRaises(QiskitError):
exp.circuits()

def test_interleaving_three_qubit_gate_with_calibration(self):
"""Test if circuits for 3Q InterleavedRB contain custom calibrations supplied via target."""
my_backend = FakeManilaV2()
with pulse.build(my_backend) as custom_3q_sched: # meaningless schedule
pulse.play(pulse.GaussianSquare(1600, 0.2, 64, 1300), pulse.drive_channel(0))

physical_qubits = (2, 1, 3)
custom_3q_gate = self.ThreeQubitGate()
my_backend.target.add_instruction(
custom_3q_gate, {physical_qubits: InstructionProperties(calibration=custom_3q_sched)}
)

exp = rb.InterleavedRB(
interleaved_element=custom_3q_gate,
physical_qubits=physical_qubits,
lengths=[3],
num_samples=1,
backend=my_backend,
seed=1234,
)
circuits = exp._transpiled_circuits()
qubits = tuple(circuits[0].qubits[q] for q in physical_qubits)
self.assertTrue(circuits[0].has_calibration_for((custom_3q_gate, qubits, [])))


class TestRunInterleavedRB(QiskitExperimentsTestCase, RBTestMixin):
"""Test for running InterleavedRB."""
Expand Down

0 comments on commit 800075f

Please sign in to comment.