Skip to content

ThreadSafe object doesn't work as expected #573

@nkanazawa1989

Description

@nkanazawa1989

Informations

  • Qiskit Experiments version: v0.1-0.2
  • Python version:
  • Operating system:

What is the current behavior?

Currently post experiment processing (e.g. analysis) is attached as callback to the experiment data. The composite experiment adds another callback to wait for child experiment to finish form _run_analysis callback. However, since the thread for ExperimentData.block_for_result and ExperimentData.add_analysis_callback are async, a callback queued from another callback sometimes not caught by the blocking mechanism.

batch_exp = BatchExperiment([exp1, exp2], backend=my_backend)
exp_data = batch_exp.run()
exp_data.block_for_result()
exp_data.status()

As a consequence, above example code sometimes returns "POST_PROCESSING" while blocking is set before the status check. This doesn't become serial problem for the most of use cases because the most time consuming part of experiment is circuit execution. Once jobs are returned, analysis callbacks will complete immediately, and you'll get the status "DONE" as expected.

One of temporarily fix would be #570 , however this is not limited to the composite experiment (you have chance to run into the bug with whatever experiment with multiple callbacks). So this is not proper approach. We need more safer lock mechanism.

There is another bug that such thread safe object doesn't work properly.

https://github.com/Qiskit/qiskit-experiments/blob/d5bba9bd81350a41b034213ccfe4797ebcc733d8/qiskit_experiments/database_service/db_experiment_data.py#L296-L308

The callback added to the experiment data is executed in this wrapper. When some error happens during execution, this will be suppressed and the thread returns the status with error flag with the warning level log with actual error message. However, with some reason, the experiment data status method returns "DONE" instead of "ERROR". This is reported in #533 .

Steps to reproduce the problem

What is the expected behavior?

Suggested solutions

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions