Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach calibrations for gates used in calibration experiments #1160

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use has_template here as below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the purpose of this conditional is to avoid getting and attaching sx twice when running the sx cal (since then the self._sched_name call of add_calibration just above would do it). I was thinking that otherwise you would always want sx attached. We could make it provisional though but it would be

Suggested change
if self._sched_name != "sx":
if self._sched_name != "sx" and self.has_template("sx", self.physical_qubits):

and not just

        if self.has_template("sx", self.physical_qubits):

What do you think?

This kind of nuance was what was making me think that maybe we should try to use transpile() with routing="none" and translation="none" rather than a custom pass manager and attaching the calibrations directly because then we could defer to the pulse gate pass whether or not to attach calibrations for other gates in the circuit besides the one being tested.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me. We are essentially requiring that self._cals contains the sx gate. I think this is an okay assumption in a calibration context. My question would have perhaps been better placed on the rough_amplitude_cal.py file below. I can rephrase and ask: "Why use has_template at all"? The code in rough_amplitude_cal.py seems more permissive by allowing that self._cals to not contain an X gate. Do we need the has_template check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a workflow we make easy, so maybe we should not make an allowance for it here, but I have heard from other users who are interested in working with qutrits and my thought was that users might want to calibrate sx12 and x12 but still just rely on the defaults for sx and x. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes perfect sense. Is that worth a comment in the code?

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
6 changes: 6 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,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)
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>`_.