Skip to content

Commit

Permalink
Increase atol for sub_state_vector() (quantumlib#4877)
Browse files Browse the repository at this point in the history
Attempts to fix quantumlib#4786
  • Loading branch information
tonybruguier authored and rht committed May 1, 2023
1 parent efc9ac5 commit 8708b9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cirq-core/cirq/linalg/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def sub_state_vector(
keep_indices: List[int],
*,
default: np.ndarray = RaiseValueErrorIfNotProvided,
atol: Union[int, float] = 1e-8,
atol: Union[int, float] = 1e-6,
) -> np.ndarray:
r"""Attempts to factor a state vector into two parts and return one of them.
Expand Down
19 changes: 19 additions & 0 deletions cirq-core/cirq/linalg/transformations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,22 @@ def test_to_special():
su = cirq.to_special(u)
assert not cirq.is_special_unitary(u)
assert cirq.is_special_unitary(su)


def test_default_tolerance():
a, b = cirq.LineQubit.range(2)
final_state_vector = (
cirq.Simulator()
.simulate(
cirq.Circuit(
cirq.H(a),
cirq.H(b),
cirq.CZ(a, b),
cirq.measure(a),
)
)
.final_state_vector.reshape((2, 2))
)
# Here, we do NOT specify the default tolerance. It is merely to check that the default value
# is reasonable.
cirq.sub_state_vector(final_state_vector, [0])

0 comments on commit 8708b9a

Please sign in to comment.