Skip to content

Commit 9315cc3

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e7bea6f commit 9315cc3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

projectq/tests/PhaseAgnosticStateComparator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import numpy as np
2+
23
from projectq import MainEngine
3-
from projectq.ops import H, CNOT
4+
from projectq.ops import CNOT, H
45
from projectq.tests.helpers import PhaseAgnosticStateComparator
56

7+
68
def test_hadamard_twice():
79
eng = MainEngine()
810
q = eng.allocate_qureg(1)
@@ -14,13 +16,14 @@ def test_hadamard_twice():
1416
comparator = PhaseAgnosticStateComparator()
1517
comparator.compare(actual, expected)
1618

19+
1720
def test_bell_state():
1821
eng = MainEngine()
1922
q = eng.allocate_qureg(2)
2023
H | q[0]
2124
CNOT | (q[0], q[1])
2225
eng.flush()
2326
_, actual = eng.backend.cheat()
24-
expected = np.array([1/np.sqrt(2), 0, 0, 1/np.sqrt(2)], dtype=complex)
27+
expected = np.array([1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)], dtype=complex)
2528
comparator = PhaseAgnosticStateComparator()
26-
comparator.compare(actual, expected)
29+
comparator.compare(actual, expected)

projectq/tests/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import numpy as np
22

3+
34
class PhaseAgnosticStateComparator:
45
def __init__(self, tol=1e-8):
56
self.tol = tol
@@ -47,6 +48,4 @@ def compare(self, actual, expected):
4748
else:
4849
for i in range(actual.shape[0]):
4950
if not np.allclose(aligned[i], expected[i], atol=self.tol):
50-
raise AssertionError(
51-
f"State {i} differs:\nAligned: {aligned[i]}\nExpected: {expected[i]}"
52-
)
51+
raise AssertionError(f"State {i} differs:\nAligned: {aligned[i]}\nExpected: {expected[i]}")

0 commit comments

Comments
 (0)