Skip to content

Commit 64e2eac

Browse files
authored
Increase atol for sub_state_vector() (#4877)
Attempts to fix #4786
1 parent aa9d184 commit 64e2eac

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

cirq-core/cirq/linalg/transformations.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def sub_state_vector(
396396
keep_indices: List[int],
397397
*,
398398
default: np.ndarray = RaiseValueErrorIfNotProvided,
399-
atol: Union[int, float] = 1e-8,
399+
atol: Union[int, float] = 1e-6,
400400
) -> np.ndarray:
401401
r"""Attempts to factor a state vector into two parts and return one of them.
402402

cirq-core/cirq/linalg/transformations_test.py

+19
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,22 @@ def test_to_special():
609609
su = cirq.to_special(u)
610610
assert not cirq.is_special_unitary(u)
611611
assert cirq.is_special_unitary(su)
612+
613+
614+
def test_default_tolerance():
615+
a, b = cirq.LineQubit.range(2)
616+
final_state_vector = (
617+
cirq.Simulator()
618+
.simulate(
619+
cirq.Circuit(
620+
cirq.H(a),
621+
cirq.H(b),
622+
cirq.CZ(a, b),
623+
cirq.measure(a),
624+
)
625+
)
626+
.final_state_vector.reshape((2, 2))
627+
)
628+
# Here, we do NOT specify the default tolerance. It is merely to check that the default value
629+
# is reasonable.
630+
cirq.sub_state_vector(final_state_vector, [0])

0 commit comments

Comments
 (0)