Skip to content

changed Pauli summation to use finite state machine construction - #308

Merged
aaronleesander merged 7 commits into
mainfrom
pauli-upgrade
Jan 29, 2026
Merged

aaronleesander merged 7 commits into
mainfrom
pauli-upgrade

Conversation

@aaronleesander

Copy link
Copy Markdown
Member

Description

This pull request updates the construction of Hamiltonian MPOs from Pauli Strings to use a more standard finite state machine construction.

This leads to a significant speedup, especially for larger systems.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@coderabbitai

coderabbitai Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Reworked the internal Pauli-sum construction for improved efficiency and maintainability; public APIs remain backward compatible.
  • Tests
    • Removed a unit test that validated internal term-construction calls (no behavioral changes).
  • Documentation
    • Updated changelog with an entry describing the construction change and added the corresponding PR reference.

✏️ Tip: You can customize this high-level summary in your review settings.

Walkthrough

Replaces the internal MPO.from_pauli_sum implementation: direct-sum construction is replaced by a finite state machine (FSM) based assembly; internal helper methods were removed. Changelog and a test that asserted internal behavior were updated accordingly.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added Unreleased entry noting Pauli summation now uses FSM-based construction and linked PR #308.
Core Algorithm Refactor
src/mqt/yaqs/core/data_structures/networks.py
Rewrote MPO.from_pauli_sum to use an FSM-driven construction: term parsing/validation, per-term trajectory/state assignment, left-to-right tensor assembly using FSM branches; removed _create_term and _sum_terms helpers; preserved public API surface.
Tests
tests/core/data_structures/test_networks.py
Removed test test_from_pauli_sum_calls_create_term_for_each_term which asserted internal helper invocation; other tests left unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

feature

Poem

🐰 I hop along the FSM trail,
Tracing Pauli steps without fail,
States align and transitions sing,
Tensors grow from each small spring,
Public doors stay bright — hooray, curtail no tale!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: replacing Pauli summation with finite state machine construction.
Description check ✅ Passed The description provides a clear summary of the change, indicates performance benefits, and confirms all checklist items are completed as required by the template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Around line 14-15: The changelog entry "changed Pauli summation to use finite
state machine construction" is split across lines and not aligned with the
project template; update that entry so the title, PR link and author link are on
a single line using the template format: include the PR as
([`#308`](https://github.com/…/pull/308)) and the author as
([**aaronleesander**](https://github.com/aaronleesander)), removing any separate
issue references and combining the pieces into one line for the entry.

In `@src/mqt/yaqs/core/data_structures/networks.py`:
- Around line 1417-1431: The loop in the term-parsing block (iterating over
terms and calling self._parse_pauli_string) currently processes even
zero-coefficient terms; modify the loop in the method that fills parsed_terms so
it first checks the term coefficient (coeff) and skips appending or parsing when
coeff is exactly zero (or effectively zero using a small epsilon for
floats/complex), i.e., do not call self._parse_pauli_string or build op_list for
such terms; ensure the check happens before validating sites or using
self._VALID so parsed_terms only receives nonzero contributions.

Comment thread CHANGELOG.md Outdated
Comment thread src/mqt/yaqs/core/data_structures/networks.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Aaron Sander <61705296+aaronleesander@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Line 14: The changelog entry line "Changed Pauli summation to use finite state
machine construction ([`#308`]) ([**@aaronleesander**])" has a broken PR
reference; replace the backticked reference with the proper PR reference format
and follow the project template: change "([`#308`])" to "([`#308`])" (or use an
inline link like
"([`#308`](https://github.com/munich-quantum-toolkit/yaqs/pull/308))") and ensure
the author remains as
"([**@aaronleesander**](https://github.com/aaronleesander))" to match other
entries (update the PR link URL if you choose the inline form).

Comment thread CHANGELOG.md
@aaronleesander
aaronleesander merged commit 1c45cdd into main Jan 29, 2026
16 checks passed
@aaronleesander
aaronleesander deleted the pauli-upgrade branch January 29, 2026 15:17
@codecov

codecov Bot commented Jan 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.87234% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/mqt/yaqs/core/data_structures/networks.py 97.8% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

1 participant