From 077fd066bfc9426da15097d46c722b32ca222b57 Mon Sep 17 00:00:00 2001 From: Will Shanks Date: Fri, 28 Apr 2023 15:20:05 -0400 Subject: [PATCH 1/2] Attach calibrations for gates used in calibration experiments 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. --- .../calibration_management/calibrations.py | 19 +++++++++++++++++++ .../library/calibration/fine_drag_cal.py | 4 ++++ .../calibration/rough_amplitude_cal.py | 6 ++++++ .../attach-other-cals-2f539e7799ceb6c8.yaml | 13 +++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 releasenotes/notes/attach-other-cals-2f539e7799ceb6c8.yaml diff --git a/qiskit_experiments/calibration_management/calibrations.py b/qiskit_experiments/calibration_management/calibrations.py index 8a91ce6182..5e68af388e 100644 --- a/qiskit_experiments/calibration_management/calibrations.py +++ b/qiskit_experiments/calibration_management/calibrations.py @@ -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: diff --git a/qiskit_experiments/library/calibration/fine_drag_cal.py b/qiskit_experiments/library/calibration/fine_drag_cal.py index f8814ee042..e21b4489d9 100644 --- a/qiskit_experiments/library/calibration/fine_drag_cal.py +++ b/qiskit_experiments/library/calibration/fine_drag_cal.py @@ -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.""" diff --git a/qiskit_experiments/library/calibration/rough_amplitude_cal.py b/qiskit_experiments/library/calibration/rough_amplitude_cal.py index c33642d6b3..8c15eb8838 100644 --- a/qiskit_experiments/library/calibration/rough_amplitude_cal.py +++ b/qiskit_experiments/library/calibration/rough_amplitude_cal.py @@ -278,3 +278,9 @@ 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.""" + 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) diff --git a/releasenotes/notes/attach-other-cals-2f539e7799ceb6c8.yaml b/releasenotes/notes/attach-other-cals-2f539e7799ceb6c8.yaml new file mode 100644 index 0000000000..5d8ff140f7 --- /dev/null +++ b/releasenotes/notes/attach-other-cals-2f539e7799ceb6c8.yaml @@ -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 `_. From 3714f358cc4bdf42306be9c74449496ceed0ae50 Mon Sep 17 00:00:00 2001 From: Will Shanks Date: Tue, 2 May 2023 18:22:08 -0400 Subject: [PATCH 2/2] Add comment about x cal attachment for EF cal --- qiskit_experiments/library/calibration/rough_amplitude_cal.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/qiskit_experiments/library/calibration/rough_amplitude_cal.py b/qiskit_experiments/library/calibration/rough_amplitude_cal.py index 8c15eb8838..be17a3d93b 100644 --- a/qiskit_experiments/library/calibration/rough_amplitude_cal.py +++ b/qiskit_experiments/library/calibration/rough_amplitude_cal.py @@ -281,6 +281,9 @@ def _pre_circuit(self) -> QuantumCircuit: 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)