Skip to content

Support representations directly in PEA (closes #2936)#3041

Open
zkasuran wants to merge 3 commits into
unitaryfoundation:mainfrom
zkasuran:unitaryhack/pea-representations-2936
Open

Support representations directly in PEA (closes #2936)#3041
zkasuran wants to merge 3 commits into
unitaryfoundation:mainfrom
zkasuran:unitaryhack/pea-representations-2936

Conversation

@zkasuran

@zkasuran zkasuran commented Jun 7, 2026

Copy link
Copy Markdown

Description

PEA could only amplify noise through the "local_depolarizing" and "global_depolarizing" model strings, which makes it unusable on real hardware where the noise is neither. This adds a representations parameter (a list of OperationRepresentation) to pea.construct_circuits and pea.execute_with_pea, as requested in #2936. The representations can be learned from hardware characterization, making PEA hardware-agnostic.

The representations are amplified with the canonical noise scaling of Sec. VI D (Eqs. 38-44) of Mari, Shammah and Zeng, Phys. Rev. A 104, 052607 (2021) (arXiv:2108.02237), already in the Mitiq bibliography as Mari_2021_PRA. The exact rule applied to each representation depends on its sign structure:

  • All-positive representations (a genuine probability distribution, e.g. an amplify_* decomposition or a noise model learned from hardware) are scaled by deviation from the identity: a0 -> 1 - s*(1 - a0), every other a_k -> s*a_k. This reproduces the legacy global-depolarizing rebuild exactly at every scale factor, so passing global-depolarizing representations yields the same sampled circuits, signs and norms as the noise_model path. That equivalence is the acceptance-criterion regression test, checked at scale factors [1, 3, 5] on a two-qubit circuit (not only at scale_factor=1).
  • Signed representations (containing negative coefficients, e.g. a PEC-style represent_operation_with_* decomposition) are scaled by the canonical sign-partition rule of Eq. (43). The positive volume gamma+ is scaled by (gamma+ - s*gamma-)/gamma+ and the negative volume gamma- by (1 - s), valid up to the canonical limit s <= gamma+/gamma-. In the amplification band the negative volume vanishes and the representation becomes a genuine probability distribution, so amplifying it adds real noise. Scaling a signed representation by deviation from the identity instead amplifies the error cancellation, the opposite of what PEA needs. The deviation rule above is the gamma- = 0 special case of this same construction.

This second branch fixes the case nez0b raised on #3058: a representation with mixed-sign coefficients was being amplified the wrong way. The fix commit credits nez0b as co-author.

representations and noise_model are mutually exclusive: passing both, or neither, raises a clear ValueError. epsilon only applies to the legacy noise_model path, so passing it together with representations is also rejected. noise_model keeps working unchanged for backward compatibility and now emits a DeprecationWarning pointing at the new interface. An empty representations list, a representation whose identity term has zero weight, and a signed representation scaled beyond its canonical limit are all rejected with clear messages.

Limitation, documented in the _scale_positive_representation docstring: the two-qubit local_depolarizing model has a product (quadratic) dependence on the noise level that flat deviation scaling cannot reproduce exactly. The coefficients still stay normalized; single-qubit local and all global depolarizing are exact, so the equivalence test is scoped to global depolarizing.

New tests cover the scale-factor != 1 equivalence, the signed-rep canonical scaling (closed-form match, negative volume dropping to zero for s >= 1, the canonical-limit error), the both/neither/missing-epsilon/empty-list/epsilon-with-representations errors, the deprecation warning and the missing/zero identity-term guard. The PEA user guide documents representations as the recommended interface, marks noise_model legacy, and now describes the sign-dispatch.

Verified locally: pytest mitiq/experimental/pea (56 passed), ruff check, ruff format --check, and mypy mitiq (whole package, 109 files) all clean.

References

  • Canonical noise scaling (the math used here): A. Mari, N. Shammah, W. J. Zeng, "Extending quantum probabilistic error cancellation by noise scaling", Phys. Rev. A 104, 052607 (2021). doi:10.1103/PhysRevA.104.052607 (arXiv:2108.02237). Sec. VI D, Eqs. (38)-(44) split a quasi-probability representation into positive and negative volumes and rescale them; Eq. (43) is the signed rule used here, valid up to s <= gamma+/gamma-, with the deviation-from-identity rule as the all-positive special case. Already in the Mitiq bibliography as Mari_2021_PRA.
  • PEA technique: Y. Kim et al., "Evidence for the utility of quantum computing before fault tolerance", Nature 618, 500-505 (2023). doi:10.1038/s41586-023-06096-3. Cited in Mitiq as Kim_2023_Nature; motivates learning the noise representation from hardware, which is what this PR lets PEA consume.
  • Quasi-probability foundation (PEC): K. Temme, S. Bravyi, J. M. Gambetta, "Error Mitigation for Short-Depth Quantum Circuits", Phys. Rev. Lett. 119, 180509 (2017). doi:10.1103/PhysRevLett.119.180509. Cited in Mitiq as Temme_2017_PRL; the OperationRepresentation structure this PR scales.

AI use

This change was implemented with help from Claude (Anthropic), which drafted the code, the tests and this description. I directed the design and reviewed every line. Before implementing the sign-dispatch I read Sec. VI D of the Mari, Shammah and Zeng paper and verified the signed-scaling rule against Eq. (43) (the s = lambda identification, the s <= gamma+/gamma- limit, and the sign-free amplification band), and I checked the all-positive branch still reproduces the depolarizing rebuild at several scale factors. The signed-rep handling resolves a case nez0b flagged on #3058 and credits him as commit co-author. I ran the test, lint and type-check suites locally. I understand the change and can answer questions about it during review.


License

  • I license this contribution under the terms of the GNU GPL, version 3 and grant Unitary Foundation the right to provide additional permissions as described in section 7 of the GNU GPL, version 3.

  • I added unit tests for new code.

  • I used type hints in function signatures.

  • I used Google-style docstrings for functions.

  • I updated the documentation where relevant.

PEA could only amplify noise through the "local_depolarizing" and
"global_depolarizing" model strings, which makes it unusable on real
hardware where the noise is neither. This lets construct_circuits and
execute_with_pea take a list of OperationRepresentation objects instead,
which can be learned from hardware characterization.

The representations are amplified with the canonical noise scaling of
Section D of Mari, Shammah and Zeng, Phys. Rev. A 104, 052607 (2021)
(Mari_2021_PRA): the deviation of each representation from the identity
is scaled by the scale factor (a0 -> 1 - s*(1-a0), every other coeff
a_k -> s*a_k). That paper shows any quasi-probability representation
induces a canonical noise channel that is linear in a single noise
parameter, so the scaling is well defined for arbitrary noise. It keeps
the coefficients summing to one and reproduces the legacy global-
depolarizing rebuild exactly at every scale factor, so a global-
depolarizing representation gives the same sampled circuits, signs and
norms as the noise_model path.

representations and noise_model are mutually exclusive: passing both, or
neither, raises a clear ValueError. An empty list and a representation
whose identity term has zero weight are also rejected. The noise_model
path is kept for backward compatibility and now emits a
DeprecationWarning.

Two-qubit local_depolarizing has a product (quadratic) structure that
flat deviation scaling cannot reproduce exactly. That limitation is
documented; the coefficients still stay normalized.

Tests cover the scale-factor != 1 equivalence on a two-qubit circuit, the
mutual-exclusion and empty/zero-identity errors, the deprecation warning
and the missing-identity guard. The PEA user guide documents
representations as the recommended interface and marks noise_model legacy.
@zkasuran zkasuran force-pushed the unitaryhack/pea-representations-2936 branch from e79fb1b to 53e46a1 Compare June 7, 2026 10:23
@zkasuran

Copy link
Copy Markdown
Author

Hi @natestemen, this one is ready for review. A short map to make it quicker.

construct_circuits and execute_with_pea accept a representations parameter, mutually exclusive with noise_model. The amplification lives in a small dedicated module, scale_amplifications.py, and follows the canonical noise scaling of Section D of Mari, Shammah and Zeng (2021), already in the bibliography as Mari_2021_PRA: the identity coefficient goes to 1 - s*(1 - a0) and every other coefficient is multiplied by s. That scaling is defined for any quasi-probability representation, so PEA works with representations learned from hardware characterization, not only the two depolarizing strings.

The regression test pins the acceptance criterion from #2936: global-depolarizing representations reproduce the legacy noise_model path exactly, same sampled circuits, signs and norms, at scale factors 1, 3 and 5. The PEA test file goes from 23 to 42 collected cases and CI is green on the full matrix (ubuntu, macos and windows on 3.11 and 3.12). The user guide is updated in three places (intro, options and low-level) so the new path is documented.

Happy to adjust the API surface if you would rather have a different entry point.

@natestemen natestemen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good. Just one blocking issue for now.

ValueError: If both ``representations`` and ``noise_model`` are given,
or if neither is given.
"""
if representations is not None and noise_model is not None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should throw in an epsilon check here too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added in 4970f86. _resolve_amplifications now rejects epsilon when it is passed together with representations, mirroring the noise_model mutual-exclusion check (epsilon only applies to the legacy noise_model path). I read your note as wanting that guard. If you meant a value check on epsilon for the noise_model path instead, I can switch it.

Comment on lines +57 to +60
def scale_representations(
representations: Sequence[OperationRepresentation],
scale_factor: float,
) -> list[OperationRepresentation]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good, but I think there is a flawed which was called out in #3058. In particular when the signs of the representation are not all positive then this increases error cancellation instead of increasing the noise (which is what we want in PEA). I think there needs to be some branching based on signs in order to properly compute scaling factors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BTW, please add @nez0b as commit author to the commit fixing this issue. You can likely pull code from his PR for this fix.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 4970f86. scale_representations now branches on sign structure. Signed (PEC-style) representations go through the canonical sign-partition scaling of Sec. VI D, Eq. (43): the positive volume is scaled by (gamma+ - s*gamma-)/gamma+ and the negative volume by (1 - s), valid up to s <= gamma+/gamma-. In the amplification band the negative volume goes to zero, so the representation becomes a real probability distribution and amplifying it adds noise instead of increasing the cancellation. All-positive amplify_* reps keep the deviation rule unchanged (it is the gamma- = 0 special case). New tests check the closed-form match, the negative volume dropping to zero for s >= 1 and the canonical-limit error.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. Commit 4970f86 credits nez0b as co-author and the signed-rep handling follows the approach from #3058.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks @nez0b. The signed-representation fix in 4970f86 follows your sign-partition approach from #3058, and you are credited as co-author on that commit.

@natestemen

Copy link
Copy Markdown
Member

@nez0b I'd encourage you to review this PR for anything you feel like is a must have from your PR that way we don't miss anything. I think the signed reps was the most important, but feel free to add comments to point out other items.

zkasuran and others added 2 commits June 21, 2026 05:05
scale_representations sent every representation through deviation-from-
identity scaling, which multiplies negative coefficients by the scale
factor. For a signed (PEC-style) representation that amplifies the error
cancellation instead of the noise, the opposite of what PEA needs.

Branch on sign structure instead. All-positive representations keep the
deviation rule. Signed representations now use the canonical noise scaling
of Mari, Shammah & Zeng (Phys. Rev. A 104, 052607, Sec. VI D, Eq. 43): the
positive volume is scaled by (gamma+ - s gamma-)/gamma+ and the negative
volume by (1 - s), valid up to the canonical limit s <= gamma+/gamma-. In
the amplification band the negative volume vanishes and the representation
becomes a genuine probability distribution.

Also reject epsilon when passed together with representations, since it
only applies to the legacy noise_model path.

Co-authored-by: nez0b <62788145+nez0b@users.noreply.github.com>
The representations guide described only deviation-from-identity scaling.
Note that signed representations take the canonical sign-partition branch
(Sec. VI D, Eq. 43), and correct the section reference.

Co-authored-by: nez0b <62788145+nez0b@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants