Skip to content

Commit 2511de8

Browse files
committed
linting quantumlib#5
1 parent ffec7c5 commit 2511de8

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

cirq/linalg/transformations.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ def wavefunction_partial_trace_as_mixture(wavefunction: np.ndarray,
367367
(2, 2) * int(np.log2(wavefunction.size)))
368368
keep_rho = partial_trace(rho, keep_indices).reshape((keep_dims,) * 2)
369369
eigvals, eigvecs = np.linalg.eigh(keep_rho)
370-
mixture = tuple(
371-
zip(eigvals, [vec.reshape(ret_shape) for vec in eigvecs.T]))
370+
mixture = tuple(zip(eigvals, [vec.reshape(ret_shape) for vec in eigvecs.T]))
372371
return tuple([
373372
(float(p[0]), p[1]) for p in mixture if not approx_eq(p[0], 0.0)
374373
])
@@ -457,8 +456,8 @@ def subwavefunction(wavefunction: np.ndarray,
457456
[abs(np.dot(left, c.reshape((keep_dims,))))**2 for c in candidates])
458457

459458
if approx_eq(coherence_measure, 1, atol=atol):
460-
return np.exp(2j * np.pi *
461-
np.random.random()) * best_candidate.reshape(ret_shape)
459+
return np.exp(
460+
2j * np.pi * np.random.random()) * best_candidate.reshape(ret_shape)
462461

463462
# Method did not yield a pure state. Fall back to `default` argument.
464463
if default is not RaiseValueErrorIfNotProvided:

cirq/linalg/transformations_test.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,6 @@ def test_wavefunction_partial_trace_as_mixture_invalid_input():
534534

535535

536536
def mixtures_equal(m1, m2, atol=1e-7):
537-
if len(m1) != len(m2):
538-
return False
539537
for (p1, v1), (p2, v2) in zip(m1, m2):
540538
if not (cirq.approx_eq(p1, p2, atol=atol) and
541539
cirq.equal_up_to_global_phase(v1, v2, atol=atol)):
@@ -582,25 +580,25 @@ def test_wavefunction_partial_trace_as_mixture_pure_result():
582580
((1.0, b),))
583581
assert mixtures_equal(
584582
cirq.wavefunction_partial_trace_as_mixture(state, [5, 6, 7, 8],
585-
atol=1e-8),
586-
((1.0, c),))
583+
atol=1e-8), ((1.0, c),))
587584

588585
# Return mixture will defer to numpy.linalg.eigh's builtin tolerance.
589586
state = np.array([1, 0, 0, 1]) / np.sqrt(2)
587+
truth = ((0.5, np.array([1, 0])), (0.5, np.array([0, 1])))
590588
assert mixtures_equal(
591589
cirq.wavefunction_partial_trace_as_mixture(state, [1], atol=1e-20),
592-
((0.5, np.array([1, 0])), (0.5, np.array([0, 1]))), atol=1e-15)
590+
truth, atol=1e-15)
593591
assert not mixtures_equal(
594592
cirq.wavefunction_partial_trace_as_mixture(state, [1], atol=1e-20),
595-
((0.5, np.array([1, 0])), (0.5, np.array([0, 1]))), atol=1e-16)
593+
truth, atol=1e-16)
596594

597595

598596
def test_wavefunction_partial_trace_as_mixture_mixed_result():
599597
state = np.array([1, 0, 0, 1]) / np.sqrt(2)
600598
truth = ((0.5, np.array([1, 0])), (0.5, np.array([0, 1])))
601599
for q1 in [0, 1]:
602-
mixture = cirq.wavefunction_partial_trace_as_mixture(
603-
state.reshape(2, 2), [q1], atol=1e-8)
600+
mixture = cirq.wavefunction_partial_trace_as_mixture(state, [q1],
601+
atol=1e-8)
604602
assert mixtures_equal(mixture, truth)
605603

606604
state = np.array([0, 1, 1, 0, 1, 0, 0, 0]).reshape(2, 2, 2) / np.sqrt(3)

0 commit comments

Comments
 (0)