Skip to content

Commit

Permalink
Fix Y-eigenstate convention in SparsePauliOp.as_paulis
Browse files Browse the repository at this point in the history
`|r>` is the positive eigenstate of Y, not the negative one.  The tests
also asserted this backwards.
  • Loading branch information
jakelishman committed Feb 14, 2025
1 parent e6e4798 commit 4e69702
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions crates/accelerate/src/sparse_observable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ fn bit_term_as_pauli(bit: &BitTerm) -> &'static [(bool, Option<BitTerm>)] {
BitTerm::Z => &[(true, Some(BitTerm::Z))],
BitTerm::Plus => &[(true, None), (true, Some(BitTerm::X))],
BitTerm::Minus => &[(true, None), (false, Some(BitTerm::X))],
BitTerm::Left => &[(true, None), (true, Some(BitTerm::Y))],
BitTerm::Right => &[(true, None), (false, Some(BitTerm::Y))],
BitTerm::Right => &[(true, None), (true, Some(BitTerm::Y))],
BitTerm::Left => &[(true, None), (false, Some(BitTerm::Y))],
BitTerm::Zero => &[(true, None), (true, Some(BitTerm::Z))],
BitTerm::One => &[(true, None), (false, Some(BitTerm::Z))],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def test_from_sparse_observable(self):
with self.subTest("XrZ"):
obs = SparseObservable("XrZ")
spo = SparsePauliOp.from_sparse_observable(obs)
expected = SparsePauliOp(["XIZ", "XYZ"], coeffs=[0.5, -0.5])
expected = SparsePauliOp(["XIZ", "XYZ"], coeffs=[0.5, 0.5])

# we don't guarantee the order of Paulis, so check equality by comparing
# the matrix representation and that all Pauli strings are present
Expand Down
10 changes: 5 additions & 5 deletions test/python/quantum_info/test_sparse_observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2126,21 +2126,21 @@ def test_as_paulis(self):
expected = SparseObservable.from_sparse_list(
[
("", [], 1 / 8),
("Y", [2], -1 / 8),
("Y", [2], 1 / 8),
("YY", [3, 2], -1 / 8),
("Z", [0], 1 / 8),
("YZ", [2, 0], -1 / 8),
("YZ", [2, 0], 1 / 8),
("YYZ", [3, 2, 0], -1 / 8),
("Y", [3], 1 / 8),
("YZ", [3, 0], 1 / 8),
("Y", [3], -1 / 8),
("YZ", [3, 0], -1 / 8),
],
4,
)
self.assertEqual(expected.simplify(), obs_paulis.simplify())

# test multiple terms
with self.subTest(msg="+X + lY - ZI"):
obs = SparseObservable.from_list([("+X", 1), ("rY", 1), ("ZI", -1)])
obs = SparseObservable.from_list([("+X", 1), ("lY", 1), ("ZI", -1)])
obs_paulis = obs.as_paulis()

expected = SparseObservable.from_list(
Expand Down

0 comments on commit 4e69702

Please sign in to comment.