Support representations directly in PEA (closes #2936)#3041
Conversation
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.
e79fb1b to
53e46a1
Compare
|
Hi @natestemen, this one is ready for review. A short map to make it quicker.
The regression test pins the acceptance criterion from #2936: global-depolarizing representations reproduce the legacy Happy to adjust the API surface if you would rather have a different entry point. |
natestemen
left a comment
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
We should throw in an epsilon check here too.
There was a problem hiding this comment.
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.
| def scale_representations( | ||
| representations: Sequence[OperationRepresentation], | ||
| scale_factor: float, | ||
| ) -> list[OperationRepresentation]: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
BTW, please add @nez0b as commit author to the commit fixing this issue. You can likely pull code from his PR for this fix.
There was a problem hiding this comment.
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.
|
@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. |
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>
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 arepresentationsparameter (a list ofOperationRepresentation) topea.construct_circuitsandpea.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:amplify_*decomposition or a noise model learned from hardware) are scaled by deviation from the identity:a0 -> 1 - s*(1 - a0), every othera_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 thenoise_modelpath. That equivalence is the acceptance-criterion regression test, checked at scale factors[1, 3, 5]on a two-qubit circuit (not only atscale_factor=1).represent_operation_with_*decomposition) are scaled by the canonical sign-partition rule of Eq. (43). The positive volumegamma+is scaled by(gamma+ - s*gamma-)/gamma+and the negative volumegamma-by(1 - s), valid up to the canonical limits <= 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 thegamma- = 0special 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.
representationsandnoise_modelare mutually exclusive: passing both, or neither, raises a clearValueError.epsilononly applies to the legacynoise_modelpath, so passing it together withrepresentationsis also rejected.noise_modelkeeps working unchanged for backward compatibility and now emits aDeprecationWarningpointing at the new interface. An emptyrepresentationslist, 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_representationdocstring: the two-qubitlocal_depolarizingmodel 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 documentsrepresentationsas the recommended interface, marksnoise_modellegacy, and now describes the sign-dispatch.Verified locally:
pytest mitiq/experimental/pea(56 passed),ruff check,ruff format --check, andmypy mitiq(whole package, 109 files) all clean.References
s <= gamma+/gamma-, with the deviation-from-identity rule as the all-positive special case. Already in the Mitiq bibliography asMari_2021_PRA.Kim_2023_Nature; motivates learning the noise representation from hardware, which is what this PR lets PEA consume.Temme_2017_PRL; theOperationRepresentationstructure 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 = lambdaidentification, thes <= 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.