Skip to content

Add unit tests for PauliStringLCU block encoding - #94

Merged
cferenba merged 6 commits into
mainfrom
cferenba/pauli-string-unit-tests
Aug 25, 2026
Merged

cferenba merged 6 commits into
mainfrom
cferenba/pauli-string-unit-tests

Conversation

@cferenba

@cferenba cferenba commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

This adds two unit tests for the (Qualtran-based) PauliStringLCU block encoding, which verify that the upper corner of the generated block encoding is equal to the original Hamiltonian, up to a scale factor. It also does some cleanup of the PauliStringLCU logic and fixes a minor bug.

EDIT: I've also added the same two tests for the PyLIQTR version of the encoding.

@cferenba

Copy link
Copy Markdown
Member Author

I found that my contraction of the select bits shouldn't have been necessary - it was only needed to work around a bug in Qualtran 0.4.0. I've backported a fix from 0.5.0 and that allows me to simplify the tests nicely.

@BrendanKKrueger BrendanKKrueger left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I saw that John sent you some feedback. Since he understands this topic better than I do, I'll just assume that he's handling the review for this merge request unless informed otherwise.

@cferenba

Copy link
Copy Markdown
Member Author

[Review notes from @johngolden's email]

I looked at your code for the recent PR and found some issues. The main one is that you pass sqrt(coeffs) to StatePreparationAliasSampling when that wants abs(coeffs). You can see in pyLIQTR's own PauliStringLCU that they keep those as two separate variables (the sqrt one is only for the prepare_type=None branch). And then your tests all use equal coefficients, which makes the issue invisible, since sqrt of equal values is still equal. If you make them unequal you'll also need to drop probability_eps to 0.1, otherwise the correct code fails too because the aliasing is too coarse. I've attached a .py (masquerading as a .txt) which shows this. Should be a quick change to the code and the tests to get up and running.

A few other things I noticed:

  • test_pauli_string_lcu_pyliqtr1 constructs PauliStringLCU instead of PyLIQTRPauliStringLCU, so it duplicates test_pauli_string_lcu1 and nothing covers the 1-qubit pyLIQTR path.
  • The negative coefficient warning is wrong. SelectPauliLCU normalizes each DensePauliString coefficient to its sign, so the signs are already handled and abs(coeffs) is the right input. pyLIQTR also gets this wrong. This will throw an error on any actual chemistry Hamiltonian.
  • PauliStringInstance doesn't implement get_alpha, so PyLIQTRPauliStringLCU.alpha raises AttributeError on it.
  • The identity term is still in the LCU — normally we remove that (it can significantly increase \lambda but contains no nontrivial physics).

@cferenba
cferenba force-pushed the cferenba/pauli-string-unit-tests branch from 8490fec to 3b40617 Compare August 25, 2026 19:39
@cferenba
cferenba merged commit 33fb2e0 into main Aug 25, 2026
14 checks passed
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