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

Allow backend cal to export instmap #185

Closed
Closed
Changes from 2 commits
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
26 changes: 22 additions & 4 deletions qiskit_experiments/calibration/management/backend_calibrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

from datetime import datetime
from enum import Enum
from typing import List
from typing import List, Optional
import copy

from qiskit.pulse.instruction_schedule_map import CalibrationPublisher
from qiskit.providers.backend import BackendV1 as Backend
from qiskit.circuit import Parameter
from qiskit_experiments.calibration.management.calibrations import Calibrations, ParameterKey
Expand Down Expand Up @@ -147,18 +148,35 @@ def get_meas_frequencies(
"""
return self._get_frequencies(FrequencyElement.READOUT, group, cutoff_date)

def export_backend(self) -> Backend:
def export_backend(
self,
basis_gates: Optional[List[str]] = None,
group: str = "default",
cutoff_date: Optional[datetime] = None,
) -> Backend:
nkanazawa1989 marked this conversation as resolved.
Show resolved Hide resolved
"""
Exports the calibrations to a backend object that can be used.
Exports the calibrations to a backend object with overridden defaults field.

Returns:
calibrated backend: A backend with the calibrations in it.
"""
backend = copy.deepcopy(self._backend)

# override frequencies
backend.defaults().qubit_freq_est = self.get_qubit_frequencies()
backend.defaults().meas_freq_est = self.get_meas_frequencies()

# TODO: build the instruction schedule map using the stored calibrations
# override basis gates
basis_gates = basis_gates or backend.configuration().basis_gates
for sched_key in self._schedules.keys():
if sched_key.schedule in basis_gates:
# Override existing calibration
sched = self.get_schedule(*sched_key, group=group, cutoff_date=cutoff_date)
sched.metadata["publisher"] = CalibrationPublisher.ExperimentService
backend.defaults().instruction_schedule_map.add(
instruction=sched_key.schedule,
qubits=sched_key.qubits,
schedule=sched,
)

return backend