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

Timing bug (RuntimeError) in running analysis with block_for_results() #1185

Closed
itoko opened this issue May 22, 2023 · 3 comments · Fixed by #1339
Closed

Timing bug (RuntimeError) in running analysis with block_for_results() #1185

itoko opened this issue May 22, 2023 · 3 comments · Fixed by #1339
Labels
bug Something isn't working
Milestone

Comments

@itoko
Copy link
Contributor

itoko commented May 22, 2023

Informations

  • Qiskit Experiments version: 6a732f4
  • Python version: 3.10.10
  • Operating system: Mac OS

What is the current behavior?

Running an analysis (e.g. Parallel T1) with block_for_results() occasionally fails with a RuntimeError: cannot schedule new futures after interpreter shutdown. It may suggest block_for_results() does not actually wait for the completion of results.

Steps to reproduce the problem

Running the code below via command line.

import numpy as np
from qiskit_experiments.framework import ExperimentData, ParallelExperiment
from qiskit_experiments.library import T1
from qiskit_ibm_provider import IBMProvider

# run and save parallel experiments in advance
provider = IBMProvider()
backend = provider.get_backend("ibm_wellington")
exps = [
    T1(
        physical_qubits=[q],
        delays=np.arange(1e-6, 6e-4, 5e-5),
    )
    for q in range(backend.configuration().num_qubits)
]
exp = ParallelExperiment(exps)
exp_data = exp.run(backend, shots=1000)
exp_data.auto_save = True
exp_data.block_for_results()

# load and rerun analysis
new_exp_data = ExperimentData.load(exp_data.experiment_id, provider=provider)
new_exp = ParallelExperiment(exps)
new_exp.analysis.run(new_exp_data)
new_exp_data.block_for_results()

Try rerun the "load and rerun analysis" part with your experiment_id if no error happens in your env.

What is the expected behavior?

block_for_results should wait for the completion of analysis.

@itoko itoko added the bug Something isn't working label May 22, 2023
@itoko itoko changed the title Timing bug (RuntimeError) in running analysis Timing bug (RuntimeError) in running analysis with block_for_results() May 22, 2023
@coruscating coruscating added this to the Release 0.6 milestone Jun 13, 2023
@gadial
Copy link
Contributor

gadial commented Jun 21, 2023

The reason for this behavior (which is not a bug) is that the line new_exp.analysis.run(new_exp_data) creates a copy of new_exp_data (since run was called with replace_results=False. The solution is to do new_exp_data = new_exp.analysis.run(new_exp_data) instead.

This raises the question of whether we should use the default replace_results=False or change the default to True to avoid similar confusions.

@itoko
Copy link
Contributor Author

itoko commented Dec 5, 2023

@gadial Thank you for letting me know the spec. I should have read the API doc carefully.
I now understand this is an issue on this code in how-to guide, which I referred when writing the above code. It should be

expdata = experiment.analysis.run(expdata)

or

experiment.analysis.run(expdata, replace_results=True)

@coruscating
Copy link
Collaborator

Thanks @itoko and @gadial, I've updated the how-to here: #1339

github-merge-queue bot pushed a commit that referenced this issue Dec 7, 2023
The rerun analysis how-to has been updated with the correct syntax for
running the analysis so that the current experiment data object is
overwritten instead of creating a new one. Closes #1185.

---------

Co-authored-by: Toshinari Itoko <[email protected]>
mergify bot pushed a commit that referenced this issue Dec 7, 2023
The rerun analysis how-to has been updated with the correct syntax for
running the analysis so that the current experiment data object is
overwritten instead of creating a new one. Closes #1185.

---------

Co-authored-by: Toshinari Itoko <[email protected]>
(cherry picked from commit 8cc20df)
nkanazawa1989 pushed a commit to nkanazawa1989/qiskit-experiments that referenced this issue Jan 17, 2024
The rerun analysis how-to has been updated with the correct syntax for
running the analysis so that the current experiment data object is
overwritten instead of creating a new one. Closes qiskit-community#1185.

---------

Co-authored-by: Toshinari Itoko <[email protected]>
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.

3 participants