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

pauli twirling callibration of expectation_estimation_shadow needs continue #2115

Closed
bdg221 opened this issue Dec 8, 2023 · 1 comment · Fixed by #2116
Closed

pauli twirling callibration of expectation_estimation_shadow needs continue #2115

bdg221 opened this issue Dec 8, 2023 · 1 comment · Fixed by #2116
Assignees
Labels
bug Something isn't working shadows classical shadows module
Milestone

Comments

@bdg221
Copy link
Collaborator

bdg221 commented Dec 8, 2023

In shadows/classical_postprocessing.py the expectation_estimation_shadow code includes a section that uses pauli_twirling_calibration. If the f_val returned however is None, then the value, 0.0, is added to the means List. However, the code will continue to execute and a second (invalid) value, np.sum(product) / len(idxes), is added to the means List. Only a single mean should be added to the means List object per split (each loop of the for loop.)

for idxes in group_idxes:
if len(
np.nonzero(np.all(u_lists_shadow[idxes] == target_obs, axis=1))[0]
):
product = (-1) ** np.sum(
b_lists_shadow[
np.nonzero(
np.all(u_lists_shadow[idxes] == target_obs, axis=1)
)
].astype(int),
axis=1,
)

        if pauli_twirling_calibration:
            if f_est is None:
                raise ValueError(
                    "estimation of Pauli fidelity must be provided for"
                    "Pauli twirling calibration."
                )

            b = create_string(num_qubits, target_locs)
            f_val = f_est.get(b, None)
            if f_val is None:
                means.append(0.0)
            else:
                # product becomes an array of snapshots expectation values
                # witch satisfy condition (1) and (2)
                product = (1.0 / f_val) * product
        else:
            product = 3 ** (len(target_locs)) * product

        # append the mean of the product in each split
        means.append(np.sum(product) / len(idxes))
    else:
        means.append(0.0)

The solution would be to add "continue" after "means.append(0.0) to have the code properly move on to the next split.

@bdg221 bdg221 added the bug Something isn't working label Dec 8, 2023
@bdg221
Copy link
Collaborator Author

bdg221 commented Dec 8, 2023

@natestemen please assign to me and I will get this included for Milestone 0.32.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working shadows classical shadows module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants