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 all 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
47 changes: 43 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, Dict, Union, Tuple
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 @@ -185,18 +186,56 @@ def get_meas_frequencies(
"""
return self._get_frequencies(FrequencyElement.READOUT, group, cutoff_date)

def export_backend(self) -> Backend:
def export_backend(
self,
outputs: Dict[str, List[Union[int, Tuple[int, ...]]]],
basis_gates: Optional[List[str]] = None,
coupling_map: Optional[List[List[int]]] = None,
group: str = "default",
cutoff_date: Optional[datetime] = None,
) -> Backend:
"""
Exports the calibrations to a backend object that can be used.
Exports the calibrations to a backend object with overridden defaults field.

Args:
outputs: Dictionary of gate to export. For example,
``{"sx": [0], "cx": [[0, 1]]}`` outputs SX gate for qubit 0, and
SX gate for qubit pair (0, 1).
basis_gates: List of gate names that the exported backend overrides the default gate
implementation. If nothing specified, the backend takes
``basis_gates`` information from the backend configuration.
coupling_map: List of qubit coupling map if need to override. For example,
if gate calibration is missing for specific qubit pair,
that coupling might be removed from the list.
group: Target calibration group. This defaults to ``default`` group.
cutoff_date: A valid calibration datetime. If nothing specified,
gate calibrations are created based on the latest calibration results.

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
if basis_gates:
backend.configuration().basis_gates = basis_gates

# override coupling map
if coupling_map:
backend.configuration().coupling_map = coupling_map

for gate, qubit_list in outputs.items():
for qubits in qubit_list:
sched = self.get_schedule(gate, qubits, group=group, cutoff_date=cutoff_date)
sched.metadata["publisher"] = CalibrationPublisher.EXPERIMENT_SERVICE
backend.defaults().instruction_schedule_map.add(
instruction=sched,
qubits=qubits,
schedule=sched,
)

return backend