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

Saving and loading calibration data with json format loses does not fully restore non-schedule parameters #1355

Closed
wshanks opened this issue Jan 12, 2024 · 0 comments · Fixed by #1357
Assignees
Labels
bug Something isn't working

Comments

@wshanks
Copy link
Collaborator

wshanks commented Jan 12, 2024

Informations

  • Qiskit Experiments version: 79e0a69
  • Python version: 3.11
  • Operating system: Fedora Linux 39

What is the current behavior?

When you run Calibrations.save("json"), if the Calibrations object holds parameters not associated with a schedule (such as drive_freq which gets added when using the FixedFrequencyTransmon gate library), those parameters are not fully reloaded.

Steps to reproduce the problem

from qiskit_experiments.calibration_management import Calibrations, FixedFrequencyTransmon
from qiskit.providers.fake_provider import FakeArmonkV2


library = FixedFrequencyTransmon()
backend = FakeArmonkV2()
cals = Calibrations.from_backend(backend, libraries=[library])

cals.save(file_type="json", overwrite=True, file_prefix="tmp")

loaded = Calibrations.load("tmp.json")

# Works because schedules were reloaded and their parameters were stored
loaded.get_parameter_value("amp", (0,), "x")
# Does not work because nothing stored this schedule-free parameter
loaded.get_parameter_value("drive_freq", (0,))

What is the expected behavior?

Both get_parameter_value calls succeed. Instead the second one produces:

CalibrationError: 'No parameter for drive_freq and schedule None and qubits (0,). No default value exists.'

Suggested solutions

The first get_parameter_value call succeeds because the schedules were also saved and reloaded and reloading them populates their parameter objects in the Calibrations._parameter_map dictionary. Perhaps the load function should loop through the parameters and add any parameters with schedule of None to the parameter map so that they can be properly loaded.

This issue was first noticed in #1351 when trying to convert the save/load tests from csv to json to reduce deprecation warnings in the tests.

@wshanks wshanks added the bug Something isn't working label Jan 12, 2024
github-merge-queue bot pushed a commit that referenced this issue Jan 31, 2024
…es (#1357)

5b6fa06 added support for saving and
loading `Calibrations` objects with a JSON format that preserved
calibrated gate schedules. However, it did not capture and restore the
`Parameter` objects for calibration parameters (like `drive_freq`) which
were not associated with a schedule. This commit adds support for these
parameters by adding an entry to the serialization model that holds a
placeholder `QuantumCircuit` with the parameters attached to placeholder
instructions. `ExperimentEncoder` can serialize `QuantumCircuit` to qpy
and so supports this format. Using a placeholder circuit like this is
the only supported way to serialize `Parameter` objects. An alternative
approach would be to store and retrieve the hidden attributes of the
`Parameter` objects directly.

Closes #1355
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants