Skip to content

Update and correct pow function for PauliSum #6019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2be8204
Update and correct pow function for PauliSum
TarunSinghania Feb 24, 2023
0760d37
Format and remainder initialisation correction
TarunSinghania Feb 27, 2023
58cb47a
Format and remainder initialisation correction
TarunSinghania Feb 27, 2023
f0cb67c
using local variable instead of self and reformatting
TarunSinghania Feb 27, 2023
66d913c
Merge branch 'master' of https://github.com/TarunSinghania/Cirq
TarunSinghania Feb 27, 2023
5839490
Merge branch 'master' into master
tanujkhattar Feb 28, 2023
5894fb0
Merge branch 'quantumlib:master' into master
TarunSinghania Mar 14, 2023
0bf2b86
reverting to regular linear multiplication and adding tests
TarunSinghania Mar 14, 2023
949e6e2
Merge branch 'master' of https://github.com/TarunSinghania/Cirq
TarunSinghania Mar 14, 2023
ffff9b7
removing unnecssary base variable
TarunSinghania Mar 14, 2023
416d81c
Merge branch 'master' of https://github.com/TarunSinghania/Cirq
TarunSinghania Mar 14, 2023
51ab71f
formatting changes
TarunSinghania Mar 14, 2023
96ba3a9
Merge branch 'master' of https://github.com/TarunSinghania/Cirq
TarunSinghania Mar 14, 2023
c9216fa
variable name changes and tests for e in range (1,9)
TarunSinghania Mar 14, 2023
39aedba
Merge branch 'master' of https://github.com/TarunSinghania/Cirq
TarunSinghania Mar 14, 2023
6d8d9b9
variable name changes and tests for e in range (1,9)
TarunSinghania Mar 14, 2023
19f7af8
Merge branch 'master' of https://github.com/TarunSinghania/Cirq
TarunSinghania Mar 14, 2023
162b788
Merge branch 'master' into master
TarunSinghania Mar 14, 2023
b12c60d
Adding test for range (1,9)
TarunSinghania Mar 19, 2023
fd4fa6b
trailing blank
TarunSinghania Mar 19, 2023
112d238
remove trailing blank test
TarunSinghania Mar 19, 2023
71d6c1e
Getting rid of extraneous variables
TarunSinghania Mar 21, 2023
57527d2
Merge branch 'master' into master
TarunSinghania Mar 21, 2023
016e9b6
Fix up final formatting issue
pavoljuhas Mar 21, 2023
37ecf85
Merge branch 'master' into master
pavoljuhas Mar 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cirq-core/cirq/ops/linear_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,10 @@ def __pow__(self, exponent: int):
if exponent == 0:
return PauliSum(value.LinearDict({frozenset(): 1 + 0j}))
if exponent > 0:
base = self.copy()
result = self.copy()
for _ in range(exponent - 1):
base *= base
return base
result *= self
return result
return NotImplemented

def __truediv__(self, a: value.Scalar):
Expand Down
16 changes: 16 additions & 0 deletions cirq-core/cirq/ops/linear_combinations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,22 @@ def test_pauli_sum_pow():
for psum in [psum1, psum2, psum3, psum4]:
assert cirq.approx_eq(psum**0, identity)

# tests for exponents greater than two for both even and odd
psum5 = cirq.Z(q0) * cirq.Z(q1) + cirq.Z(q2) + cirq.Z(q3)
correctresult = psum5.copy()
for e in range(1, 9):
assert correctresult == psum5**e
correctresult *= psum5

psum6 = cirq.X(q0) * cirq.Y(q1) + cirq.Z(q2) + cirq.X(q3)
assert psum6 * psum6 * psum6 * psum6 * psum6 * psum6 * psum6 * psum6 == psum6**8

# test to ensure pow doesn't make any change to the original value
psum7 = cirq.X(q0) * cirq.Y(q1) + cirq.Z(q2)
psum7copy = psum7.copy()
assert psum7**5 == psum7 * psum7 * psum7 * psum7 * psum7
assert psum7copy == psum7


# Using the entries of table 1 of https://arxiv.org/abs/1804.09130 as golden values.
@pytest.mark.parametrize(
Expand Down