Skip to content

Add a new transformer that performs random pauli insertion #7558

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

NoureldinYosri
Copy link
Collaborator

@NoureldinYosri NoureldinYosri commented Aug 5, 2025

implements the error mitigation technique described in appendix D of https://arxiv.org/abs/2503.20870

@NoureldinYosri NoureldinYosri requested review from vtomole and a team as code owners August 5, 2025 05:59
@github-actions github-actions bot added the size: M 50< lines changed <250 label Aug 5, 2025
@github-actions github-actions bot added size: L 250< lines changed <1000 and removed size: M 50< lines changed <250 labels Aug 5, 2025
Copy link
Collaborator

@eliottrosenberg eliottrosenberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Nour! This is great! A few comments:

  • Can we have a clear, deterministic way of saying which qubit is which in the probabilities array?
  • For applications, we might need finer-grained pair-by-pair control over the probabilities.
  • Also see the error_mitigation/noise_adding.py file in my user folder.

@zlatko-minev
Copy link
Collaborator

Eliott will chat with you at our chat

Copy link

codecov bot commented Aug 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.50%. Comparing base (0e87d09) to head (4eb0bdd).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #7558    +/-   ##
========================================
  Coverage   97.50%   97.50%            
========================================
  Files        1101     1103     +2     
  Lines       99411    99541   +130     
========================================
+ Hits        96928    97058   +130     
  Misses       2483     2483            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

probabilities of sampling 2Q paulis. The order of the paulis is IXYZ.
If at operation `op` a pair (i, j) is sampled then _PAULIS[i] is applied
to op.qubits[0] and _PAULIS[j] is applied to op.qubits[1].
If None, assume uniform distribution.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A uniform distribution would completely depolarize the state, which is probably not what we want. I think probabilities should be required.

Comment on lines +42 to +52
probabilities: np.ndarray | Mapping[tuple[ops.Qid, ops.Qid], np.ndarray] | None = None,
):
"""Makes a pauli insertion transformer that samples 2Q paulis with the given probabilities.

Args:
target: The target gate, gatefamily, gateset, or type (e.g. ZZPowGAte).
probabilities: Optional ndarray or mapping[qubit-pair, nndarray] representing the
probabilities of sampling 2Q paulis. The order of the paulis is IXYZ.
If at operation `op` a pair (i, j) is sampled then _PAULIS[i] is applied
to op.qubits[0] and _PAULIS[j] is applied to op.qubits[1].
If None, assume uniform distribution.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should require that probabilities be a mapping from qubit pairs to numpy arrays and use the order in the qubit pair (not in the op, which is less easily accessible to the user) to determine which qubit is which in probabilities.

Comment on lines +59 to +60
assert np.isclose(probs.sum(), 1)
assert probs.shape == (4, 4)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change these to ValueErrors and document them in a Raises section of the docstring? Also check that none of them are negative.


Args:
target: The target gate, gatefamily, gateset, or type (e.g. ZZPowGAte).
probabilities: Optional ndarray or mapping[qubit-pair, nndarray] representing the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should say more clearly that probabilities contains 4x4 arrays and the [i,j] element is the probability of applying _PAULIS[i] to qubit 0 and _PAULIS[j] to qubit 1, where the two qubits now (if you make the other change I suggest) are in the order specified in the key of the dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: L 250< lines changed <1000
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants