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

Composite analysis can not handle single shot memory data #605

Closed
eggerdj opened this issue Jan 13, 2022 · 7 comments
Closed

Composite analysis can not handle single shot memory data #605

eggerdj opened this issue Jan 13, 2022 · 7 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@eggerdj
Copy link
Contributor

eggerdj commented Jan 13, 2022

Informations

  • Qiskit Experiments version: 660766a
  • Python version: 3.8.5
  • Operating system: Linux

What is the current behavior?

The following fails:

specs = []
for qubit in [0, 1, 2]:
    freq01 = backend.defaults().qubit_freq_est[qubit]
    specs.append(QubitSpectroscopy(qubit, frequencies=np.linspace(freq01-20e6, freq01+20e6, 51), backend=backend))

multi_spec = ParallelExperiment(specs, backend=backend)
multi_spec.set_run_options(meas_level=MeasLevel.KERNELED, meas_return="single")

mexp_data = multi_spec.run()

With error

ValueError: x and y must be the same size

when the analysis attempts to create a scatter plot of the data.

Steps to reproduce the problem

Execute the code above.

What is the expected behavior?

The code above should run and produce meaningful results.

Suggested solutions

I suspect that the cause of this is the data processing. Nothing is telling the data processing chain for each individual experiment how to extract the data from the "memory" in the experiment_data object. This points to a missing node in the data processing chain.

@eggerdj eggerdj added the bug Something isn't working label Jan 13, 2022
@yaelbh
Copy link
Contributor

yaelbh commented Jan 13, 2022

  1. If the spectroscopy experiment has default transpile or run options, they don't propagate to the composite experiment itself, therefore you have to manually set them in the composite experiment.
  2. It is possible that an explicit call to block_for_results is still required for composite experiments.

P.S. I see that you took care of the run options. Didn't check if there are particular transpile options.

I don't know about the data processor, but as far as I remember the code was changed to support measurement level 1, including the case of parallel experiments. Parallel readout angle (with measurement level 1 like here, but meas_return=avg) works well.

@eggerdj
Copy link
Contributor Author

eggerdj commented Jan 13, 2022

@yaelbh have you tried with meas_return=single ?

@yaelbh
Copy link
Contributor

yaelbh commented Jan 13, 2022

No, and if I remember correctly the readout angle experiment is written in a way that assume avg.

@wshanks
Copy link
Collaborator

wshanks commented Jan 13, 2022

The problem is that _marginalize_data in composite_analysis.py does not handle single shot data for memory. Here is where it marginalizes memory data: https://github.com/Qiskit/qiskit-experiments/blob/db3962c57f115b5d2065d5526d5459e5700d6c28/qiskit_experiments/framework/composite/composite_analysis.py#L152-L158

If you measure 3 qubits like in the example above and measure 1024 shots, composite_clbits is [[0], [1], [2]] and datum['memory'].shape is (1024, 3, 2), so instead of picking out the appropriate qubit the function picks out the first shot leaving something with shape (1, 3, 2) instead of (1024, 1, 2). When this is passed to the curve fitting function, you get the shape mismatch error.

@wshanks wshanks changed the title Spectroscopy fails in a parallel experiment Composite analysis can not handle single shot memory data Jan 13, 2022
@chriseclectic
Copy link
Collaborator

chriseclectic commented Jan 14, 2022

Composite analysis currently only supports level 2 measurement data. The handling of memory was intended for single-shot level-counts which returned a list like "memory": ["000", "000", "111", ...] when running using the run option memory=True (using memory key for both level 1 and 2 is confusing here).

Adding support for marginalizing level 1 data is a feature that needs to be added to this class.

@wshanks
Copy link
Collaborator

wshanks commented Jan 14, 2022

Ah, okay. It seems that the support single-shot level 2 also incidentally enabled support for average level 1 data.

@coruscating coruscating self-assigned this Jan 19, 2022
@chriseclectic chriseclectic added this to the Release 0.3 milestone Mar 30, 2022
@chriseclectic chriseclectic removed this from the Release 0.3 milestone Apr 20, 2022
@coruscating coruscating added this to the Release 0.4 milestone Apr 27, 2022
@coruscating
Copy link
Collaborator

Fixed by #801.

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

5 participants