Skip to content

Commit

Permalink
Attach calibrations for gates used in calibration experiments (#1160)
Browse files Browse the repository at this point in the history
### Summary

Previously `EFRoughXSXAmplitudeCal` and `FineXDragCal` only attached the
calibrations for the gates being calibrated by the experiments, not the
calibrations for the other gates used by the experiments.
  • Loading branch information
wshanks authored May 2, 2023
1 parent 9e2e988 commit 2a77748
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
19 changes: 19 additions & 0 deletions qiskit_experiments/calibration_management/calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,25 @@ def add_schedule(
for param in params_to_register:
self._register_parameter(param, qubits, schedule)

def has_template(self, schedule_name: str, qubits: Optional[Tuple[int, ...]] = None) -> bool:
"""Test if a template schedule is defined
Args:
schedule_name: The name of the template schedule.
qubits: The qubits under which the template schedule was registered.
Returns:
True if a template exists for the schedule name for the given qubits
"""
found = False
try:
self.get_template(schedule_name, qubits)
found = True
except CalibrationError:
pass

return found

def get_template(
self, schedule_name: str, qubits: Optional[Tuple[int, ...]] = None
) -> ScheduleBlock:
Expand Down
4 changes: 4 additions & 0 deletions qiskit_experiments/library/calibration/fine_drag_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def _attach_calibrations(self, circuit: QuantumCircuit):
"""Attach the calibrations to the circuit."""
schedule = self._cals.get_schedule(self._sched_name, self.physical_qubits)
circuit.add_calibration(self._sched_name, self.physical_qubits, schedule)
# FineDrag always uses sx so attach it if it is not sched_name
if self._sched_name != "sx":
schedule = self._cals.get_schedule("sx", self.physical_qubits)
circuit.add_calibration("sx", self.physical_qubits, schedule)

def update_calibrations(self, experiment_data: ExperimentData):
"""Update the drag parameter of the pulse in the calibrations."""
Expand Down
9 changes: 9 additions & 0 deletions qiskit_experiments/library/calibration/rough_amplitude_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,12 @@ def _pre_circuit(self) -> QuantumCircuit:
circ = QuantumCircuit(1)
circ.x(0)
return circ

def _attach_calibrations(self, circuit: QuantumCircuit):
"""Attach an x calibration if it is defined."""
# Attach the x calibration as well if it is in self._cals. We allow for
# it not to be present in case a user wants to rely on the default x
# calibration and only calibrate the pulses between levels 1 and 2.
if self._cals.has_template("x", self.physical_qubits):
schedule = self._cals.get_schedule("x", self.physical_qubits)
circuit.add_calibration("x", self.physical_qubits, schedule)
13 changes: 13 additions & 0 deletions releasenotes/notes/attach-other-cals-2f539e7799ceb6c8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
features:
- |
A new method :meth:`.qiskit_experiments.calibration_management.Calibrations.has_template`
has been added to :class:`.qiskit_experiments.calibration_management.Calibrations`
to check if a template schedule exists for a particular set of qubits.
fixes:
- |
:class:`.qiskit_experiments.library.FineXDragCal` and
:class:`.qiskit_experiments.library.EFRoughXSXAmplitudeCal` were updated to
attach `"sx"` and `"x"` calibrations to their circuits, respectively.
Previously, they only attached the `"x"` and `"x12"` calibrations that they
were calibrating. See issue `#1158 <https://github.com/Qiskit/qiskit-experiments/issues/1158>`_.

0 comments on commit 2a77748

Please sign in to comment.