Skip to content

Bugfixes: Simultaneous measurement of mutually commuting terms - #196

Merged
chmwzc merged 38 commits into
mainfrom
fix-gc
Sep 2, 2026
Merged

Bugfixes: Simultaneous measurement of mutually commuting terms#196
chmwzc merged 38 commits into
mainfrom
fix-gc

Conversation

@chmwzc

@chmwzc chmwzc commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

The mapping of mutually generally commuting terms occasionally messes up the qubits to be measured if the given term group doesn't span the entire possible space, e.g.

from qibo.symbols import X, Y, Z
from qibo.hamiltonians import SymbolicHamiltonian

from qibochem.measurement.optimization import _gc_measurement_mapping

ham = SymbolicHamiltonian(X(2)*X(3) + Y(2)*Y(3) + Z(2)*Z(3), nqubits=4)
term_mapping, gates_to_add = _gc_measurement_mapping(ham.form, ham.nqubits, "chong")
print(f"{term_mapping = }")
# Output: term_mapping = {'X2 X3': Z1, 'Y2 Y3': -Z1*Z3, 'Z2 Z3': Z3} 
# Want: Qubits to be measured to remain as {2, 3}

This PR solves this by adding a dict to get back and use the original set of qubits after mapping the Pauli terms.


Edit: Using this PR to fix some other bugs that JF found as well


Edit 2: Reverting the addition of SWAP gates after circuit synthesis; it's simpler to just re-label instead. This PR is now just bug-fixing.

@chmwzc
chmwzc requested a review from a team July 6, 2026 07:43
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (89d00e1) to head (15e384b).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #196   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           13        13           
  Lines          990       996    +6     
=========================================
+ Hits           990       996    +6     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chmwzc chmwzc self-assigned this Jul 6, 2026
@chmwzc chmwzc added the bug Something isn't working label Jul 6, 2026
@chmwzc
chmwzc requested a review from damarkian July 6, 2026 07:44
@chmwzc
chmwzc marked this pull request as draft July 30, 2026 03:08
@chmwzc chmwzc changed the title Minor bugfix: Simultaneous measurement of mutually commuting terms Bugfixes: Simultaneous measurement of mutually commuting terms Aug 3, 2026
@chmwzc
chmwzc marked this pull request as ready for review September 2, 2026 03:00
@chmwzc
chmwzc merged commit b175dc9 into main Sep 2, 2026
15 checks passed
@chmwzc
chmwzc deleted the fix-gc branch September 2, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants