Implement ZNE postprocess function#2953
Conversation
TsafrirA
left a comment
There was a problem hiding this comment.
Some initial comments, mainly on the integration into the main post processor function.
|
The extrapolation I/O changes were moved to a separate PR which will need to be merged first - #3000 (the tests will fail until this PR will be merged, but they pass combined with this PR code) |
…hods (Qiskit#3000) ### Summary Change the extrapolation input and output to align with the flow of the EM methods. ### Details and comments Related to Qiskit#2948 and Qiskit#2953 ### AI/LLM disclosure - [ ] I didn't use LLM tooling, or only used it privately. - [ ] I used the following tool to help write this PR description: - [X] I used the following tool to generate or modify code: bob --------- Co-authored-by: TsafrirA <113579969+TsafrirA@users.noreply.github.com>
TsafrirA
left a comment
There was a problem hiding this comment.
Some nitpicks, and a couple of things that need a fix -
- Length validation will fail.
- 'auto' value will fail for
extrapolated_noise_factors.
| len(observables_lists), | ||
| len(param_basis_pairs_lists), | ||
| len(param_shapes_list), | ||
| } != {len(result)}: |
There was a problem hiding this comment.
This will fail for ZNE, as the number of items is not the same as the number of pubs.
Also highlights that we are missing a test for estimator_v2_post_processor_v0_1 with a ZNE result.
| Returns: | ||
| An :class:`~qiskit_ibm_runtime.results.EstimatorPubResult` with an empty metadata dict. | ||
| """ | ||
| # The last returned value is the selected extrapolators, that should be saved in the |
There was a problem hiding this comment.
| # The last returned value is the selected extrapolators, that should be saved in the | |
| # TODO: The last returned value is the selected extrapolators, that should be saved in the |
| extrapolator: list[ExtrapolatorType], | ||
| measure_noise_data: PauliLindbladMap | np.ndarray | None, | ||
| ) -> tuple[npt.NDArray[float], npt.NDArray[float], npt.NDArray[float], list[list[str]]]: | ||
| """Process expectation values for a single item result. |
There was a problem hiding this comment.
| """Process expectation values for a single item result. | |
| """Process expectation values for a single pub. |
| raise ValueError("Dedicated creg ``'_meas'`` is missing from one of the results.") | ||
|
|
||
| if data.ndim != 4: | ||
| # Shape: (num_randomizations, num_noise_scales, num_configs, shots, num_bits) |
There was a problem hiding this comment.
| # Shape: (num_randomizations, num_noise_scales, num_configs, shots, num_bits) | |
| # Shape: (num_randomizations, num_configs, shots, num_bits) |
|
|
||
| # Combine the data from each noise factor | ||
| noise_amplified_data = [] | ||
| for i, item_result in enumerate(item_results): |
There was a problem hiding this comment.
| for i, item_result in enumerate(item_results): | |
| for item_result in item_results: |
| ): | ||
| # In case each pub is associated with several items - create a list in which each element | ||
| # is a list containing all relevant items for that pub | ||
| combined_results = [] |
There was a problem hiding this comment.
The calculation of combined_results only applies to the ZNE branch, so I think we should move it into that branch.
| """Calculate expectation values and errors with ZNE, and return pub result. | ||
|
|
||
| Args: | ||
| item_results: The item result. |
There was a problem hiding this comment.
| item_results: The item result. | |
| item_results: The item results. |
| param_basis_pairs, | ||
| readout_noise_data, | ||
| noise_factors=zne_noise_factors, | ||
| extrapolated_noise_factors=extrapolated_noise_factors, |
There was a problem hiding this comment.
The options have an auto value for extrapolated_noise_factors. I don't see where it's resolved. It's passed as is during prepare, and I don't see it being resolved here.
There was a problem hiding this comment.
I think it should be resolved in finalize_options.
|
|
||
| # Apply measurement flips if present | ||
| if "measurement_flips._meas" in item_result: | ||
| data ^= item_result["measurement_flips._meas"] |
There was a problem hiding this comment.
We can pop the measurement flips here. Also makes sure you can't apply it twice somehow.
| pec_gamma=pec_gammas[pub_idx], | ||
| ) | ||
| elif mitigation == "zne": | ||
| pub_result = create_pub_result_zne( |
There was a problem hiding this comment.
Just like in the PEA PR, some of the values could be None, but are passed as here as actual values. Need to validate. (Again, I don't understand how this passes static checks).
Summary
Add a post-process function to calculate the extrapolated expectation values when using ZNE with gate folding EM method.
Details and comments
Fixes #2850
AI/LLM disclosure