Skip to content

feat: add canonical PauliStringSum container#1294

Open
jaimeajl wants to merge 1 commit into
amazon-braket:mainfrom
jaimeajl:unitaryhack/canonical-pauli-string-sum
Open

feat: add canonical PauliStringSum container#1294
jaimeajl wants to merge 1 commit into
amazon-braket:mainfrom
jaimeajl:unitaryhack/canonical-pauli-string-sum

Conversation

@jaimeajl

@jaimeajl jaimeajl commented Jun 9, 2026

Copy link
Copy Markdown

Issue #, if available:

Closes #1256

Description of changes:

This PR adds a canonical PauliStringSum container for weighted PauliString expressions.

The implementation focuses on predictable algebraic behavior and representation fidelity across conversions:

  • duplicate Pauli strings are merged deterministically;
  • zero-coefficient terms are removed from the canonical representation;
  • term ordering is stable;
  • coefficients are restricted to real numbers;
  • weighted tuple round-trips preserve algebraic meaning;
  • conversions to/from Observable.Sum avoid silent semantic changes;
  • unsupported operations fail explicitly.

The goal is to make weighted PauliString sums predictable across algebraic operations and representation boundaries.

Testing done:

  • ruff check src/braket/quantum_information/pauli_string.py src/braket/quantum_information/__init__.py test/unit_tests/braket/quantum_information/test_pauli_string_sum.py
  • ruff format --check src/braket/quantum_information/pauli_string.py src/braket/quantum_information/__init__.py test/unit_tests/braket/quantum_information/test_pauli_string_sum.py
  • targeted pytest: 68 passed, 31 xfailed
  • coverage for pauli_string.py: 100%
  • git diff --check

AI assistance disclosure: I used AI assistance for design review and wording, then implemented, reviewed, and validated the changes locally.

Merge Checklist

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@jaimeajl jaimeajl requested a review from a team as a code owner June 9, 2026 22:52
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.

Allow for Sums of PauliStrings

2 participants