A slightly more specific alternative: Fix Pauli ordering return type and Y-branch handling#34
A slightly more specific alternative: Fix Pauli ordering return type and Y-branch handling#34AlbertLee125 wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to stabilize Pauli-term ordering for Trotterized time evolution by making reorder_paulis return a consistent mapping type (including for ordering_method=None and empty input) and fixing the Y-branch selection logic in group_evolve_xyz.
Changes:
- Added a docstring and an empty-input fast path to
reorder_paulisto avoidIndexErrorand ensure callers can always use.items(). - Changed the
ordering_method=Nonepath to return a dict (preserving insertion order). - Fixed a typo in
group_evolve_xyzso the Y-branch checkspauli_typerather thanpauli_types.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Added ordering.py testsI added a dedicated test file for The tests cover the small stabilization changes made to
I verified the new tests locally with: The results was given as |
|
|
||
| if ordering_method == None: | ||
| return pauli_string_list | ||
| if ordering_method is None: |
There was a problem hiding this comment.
Maybe I've just forgotten some of the details here, but this is specifically talking about ordering terms, but then the comments say that the return type should be a dictionary which is unordered? Or maybe dictionaries are ordered and I'm remembering outdated information or a different language?
There was a problem hiding this comment.
Good point. In older Python versions, dictionaries were commonly treated as unordered, but in Python 3.7+ insertion order is guaranteed. Since QHAT uses Python 3.11, returning dict(pauli_string_list) preserves the selected Pauli-term order while keeping the return type compatible with downstream code that calls .items().
| pauli_string = term[0] | ||
| pauli_types = set(pauli_string) #throw out duplicates to see which pauli types exist (I, X, Y, Z) | ||
| pauli_types.discard("I") #throw out the identity I if it exists in the string | ||
| pauli_types = set( |
There was a problem hiding this comment.
You have a lot of reformatting mixed in with actual changes. Generally you don't change formatting at the same time as you change functionality (unless it's a line you're editing anyway as part of changing the functionality). It's much better to push formatting changes to its own merge request, to make it easier to review merge requests.
There was a problem hiding this comment.
I have a question, I did Python Black Formatting. So, is there a formatting rule that I need to be aware of?
There was a problem hiding this comment.
On other projects I've pushed for automated formatting, but on this project I'm trying to keep process pretty minimal. You're welcome to run a formatting tool if you like (I don't have enough experience with Python to pick the "best" formatting tool or options), just run it as a separate merge request.
There was a problem hiding this comment.
I restored the original formatting.
|
I ran |
Summary
This PR stabilizes
analysis/ordering.pyby makingreorder_paulisbehave consistently across the default and empty-input paths, and by fixing a typo in thegroup_evolve_xyzordering method.The changes are intentionally small and focused. They repair the current ordering behavior without redesigning the broader Pauli-term representation.
What changed
Why
reorder_paulisis used before building the Trotterized unitary. The caller expects the returned object to support.items(), so the defaultNoneordering path should preserve the original Pauli-term order while still returning a dictionary.This PR fixes three small issues:
Noneordering path returned a list, while the other ordering methods returned dictionaries.pauli_string_list[0][0]and fail with an unclearIndexError.group_evolve_xyzY branch comparedpauli_types, a set, against the string"Y"instead of comparingpauli_type.Tests
Didn't add the test file yet but will add it later.
Scope
This PR does not fully resolve the broader TODO in
ordering.pyabout Pauli-term representation, generator/list design, or tuple-format support. It only stabilizes the current dictionary-based behavior so future Trotter-ordering methods can be added more safely.