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

Many calibration experiments' data can not be saved to the results database #413

Closed
wshanks opened this issue Sep 30, 2021 · 2 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@wshanks
Copy link
Collaborator

wshanks commented Sep 30, 2021

Informations

  • Qiskit Experiments version: current main (f859b2d)
  • Python version: 3.9
  • Operating system: Linux

What is the current behavior?

When you try to save the experiment data from a calibration experiment, it fails to save because most calibration experiments set a pulse schedule as an experiment option and that can not be serialized for storing in the database. Here is the output I see (see steps to reproduce for the code to generate this output):

Unable to save the experiment data: Traceback (most recent call last):
  File "/home/wshanks/Documents/Coding/qiskit-experiments/qiskit_experiments/database_service/utils.py", line 152, in save_data
    return True, new_func(**kwargs)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/qiskit/providers/ibmq/experiment/ibm_experiment_service.py", line 173, in create_experiment
    response_data = self._api_client.experiment_upload(data)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/qiskit/providers/ibmq/api/clients/experiment.py", line 117, in experiment_upload
    return self.base_api.experiment_upload(data)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/qiskit/providers/ibmq/api/rest/root.py", line 244, in experiment_upload
    raw_data = self.session.post(url, json=experiment).json()
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/requests/sessions.py", line 590, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/qiskit/providers/ibmq/api/session.py", line 277, in request
    response = super().request(method, final_url, headers=headers, **kwargs)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/requests/sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/requests/sessions.py", line 456, in prepare_request
    p.prepare(
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/requests/models.py", line 319, in prepare
    self.prepare_body(data, files, json)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/requests/models.py", line 471, in prepare_body
    body = complexjson.dumps(json, allow_nan=False)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/json/__init__.py", line 234, in dumps
    return cls(
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ScheduleBlock is not JSON serializable

Unable to save the experiment data: Traceback (most recent call last):
  File "/home/wshanks/Documents/Coding/qiskit-experiments/qiskit_experiments/database_service/utils.py", line 152, in save_data
    return True, new_func(**kwargs)
TypeError: create_analysis_result() missing 1 required positional argument: 'data'

Unable to save the experiment data: Traceback (most recent call last):
  File "/home/wshanks/Documents/Coding/qiskit-experiments/qiskit_experiments/database_service/utils.py", line 152, in save_data
    return True, new_func(**kwargs)
TypeError: create_analysis_result() missing 1 required positional argument: 'data'

Unable to save the experiment data: Traceback (most recent call last):
  File "/home/wshanks/Documents/Coding/qiskit-experiments/qiskit_experiments/database_service/utils.py", line 152, in save_data
    return True, new_func(**kwargs)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/qiskit/providers/ibmq/experiment/ibm_experiment_service.py", line 1065, in create_figure
    response = self._api_client.experiment_plot_upload(experiment_id, figure, figure_name)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/contextlib.py", line 135, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/wshanks/conda/envs/qiskit/lib/python3.9/site-packages/qiskit/providers/ibmq/experiment/utils.py", line 32, in map_api_error
    raise IBMExperimentEntryNotFound(error_msg + f" {api_err}") from None
qiskit.providers.ibmq.experiment.exceptions.IBMExperimentEntryNotFound: 'Figure figure_7fa922a9_2021-09-30T16:34:05.546362_0.svg already exists. \'404 Client Error: Not Found for url: https://api.quantum-computing.ibm.com/resultsdb/experiments/7fa922a9-c499-4e65-b349-fd9509d62693/plots. {"errors":["Experiment 7fa922a9-c499-4e65-b349-fd9509d62693 does not exist"]}\''

The code does keep going without raising an exception which is good. However, it does print the following to stdout which is not true (the experiment is not accessible):

You can view the experiment online at https://quantum-computing.ibm.com/experiments/7fa922a9-c499-4e65-b349-fd9509d62693

Steps to reproduce the problem

With whichever backend you prefer, run:

qubit = 0
x_pulse = backend.defaults().instruction_schedule_map.get('x', (qubit,)).instructions[0][1].pulse
with pulse.build(backend=backend, name="xp") as xp_over:
    pulse.play(
        pulse.Drag(
            duration=x_pulse.duration, amp=x_pulse.amp * 1.1, sigma=x_pulse.sigma, beta=x_pulse.beta
        ), 
        pulse.drive_channel(qubit)
    )
amp_cal = FineXAmplitude(qubit)
amp_cal.set_experiment_options(schedule=xp_over)
data = amp_cal.run(backend)
data.block_for_results()
data.figure(0)
data.save()

What is the expected behavior?

The ideal solution would be if pulse schedules could be serialized so they could be stored in the database like other experiment options. That might not be a quick solution but is already planned (Qiskit/qiskit#6923).

More generally, should the experiment save as much data as possible to the results database and just drop fields that can't be serialized? Or should we insist on full serialization (which might be needed for future plans)? Outside of calibrations, this issue could come up again in the future for other options that users might attach that can't be serialized.

Suggested solutions

See discussion in expected behavior

@wshanks wshanks added the bug Something isn't working label Sep 30, 2021
@eggerdj
Copy link
Contributor

eggerdj commented Oct 4, 2021

Perhaps a temporary option, which I think we also mentioned, is saving the schedule as a string? Also, this issues means that any transpiler/run/experiment option should be serializable (unless we drop options). Another option that comes to mind and will cause issues is the instruction schedule map since, as with this issue, schedules cannot yet be serialized. PassManagers also potential transpiler options may need to be serialized too (not sure if this is possible yet?).

@wshanks
Copy link
Collaborator Author

wshanks commented Nov 4, 2021

Results are saving successfully for me now (with some kind of string substituted in for the things that gave serialization errors before).

@wshanks wshanks closed this as completed Nov 4, 2021
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

No branches or pull requests

2 participants