Skip to content

Set default unitary precision np.complex64 #5426

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 37 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
55360c4
initial fix
dabacon May 31, 2022
088e61f
Merge branch 'master' into precision
dabacon May 31, 2022
4e952d2
more updated precisions
dabacon May 31, 2022
ff6b21c
less precision
dabacon May 31, 2022
39ba502
Update precision
dabacon May 31, 2022
018b72d
One broken test left
dabacon Jun 1, 2022
52643fa
fix more tests
dabacon Jun 1, 2022
440765a
Merge branch 'master' into precision
dabacon Jun 1, 2022
527eb23
64
dabacon Jun 1, 2022
02f9193
fixes
dabacon Jun 1, 2022
77ee2b2
more fixes
dabacon Jun 1, 2022
098ef9d
Make tests reslient to running multiple times
dabacon Jun 1, 2022
830ec63
fix more flaky tests
dabacon Jun 1, 2022
fbc4a9c
more fix for flakes
dabacon Jun 2, 2022
c68311a
Merge branch 'master' into precision
dabacon Jun 2, 2022
1b46b28
Merge branch 'master' into precision
dabacon Jun 6, 2022
167c84d
Merge branch 'master' into precision
dabacon Jun 7, 2022
a027b11
Merge branch 'master' into precision
dabacon Jun 7, 2022
98cdc1b
Merge branch 'master' into precision
dabacon Jun 7, 2022
0a6e666
try to debug
dabacon Jun 7, 2022
aba2005
Merge branch 'master' into precision
dabacon Jun 9, 2022
314b5a0
fix too many unitaries
dabacon Jun 9, 2022
ce4a385
Attempt precision change
dabacon Jun 9, 2022
19da0a6
less precise
dabacon Jun 9, 2022
7b2f63f
less precise
dabacon Jun 9, 2022
bfa4d80
Merge branch 'precision' of github.com:dabacon/Cirq into precision
dabacon Jun 9, 2022
a43b26d
fix bad merge
dabacon Jun 9, 2022
847b45e
Add comments
dabacon Jun 10, 2022
40788e7
oops?
dabacon Jun 10, 2022
c39354f
Merge branch 'master' into precision
dabacon Jun 14, 2022
2c3377e
Merge branch 'master' into precision
dabacon Jun 15, 2022
2650803
Review comments
dabacon Jun 15, 2022
565f485
Fix new test
dabacon Jun 15, 2022
58c4ee3
Merge branch 'master' into precision
dabacon Jun 15, 2022
24702c4
fix tests
dabacon Jun 15, 2022
b5b4d46
notebook precision
dabacon Jun 15, 2022
78455fc
Merge branch 'master' into precision
dabacon Jun 15, 2022
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
11 changes: 5 additions & 6 deletions cirq-core/cirq/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ def unitary(
qubit_order: 'cirq.QubitOrderOrList' = ops.QubitOrder.DEFAULT,
qubits_that_should_be_present: Iterable['cirq.Qid'] = (),
ignore_terminal_measurements: bool = True,
dtype: Type[np.number] = np.complex128,
dtype: Type[np.number] = np.complex64,
) -> np.ndarray:
"""Converts the circuit into a unitary matrix, if possible.

Expand All @@ -1013,11 +1013,10 @@ def unitary(
ignore_terminal_measurements: When set, measurements at the end of
the circuit are ignored instead of causing the method to
fail.
dtype: The numpy dtype for the returned unitary. Defaults to
np.complex128. Specifying np.complex64 will run faster at the
cost of precision. `dtype` must be a complex np.dtype, unless
all operations in the circuit have unitary matrices with
exclusively real coefficients (e.g. an H + TOFFOLI circuit).
dtype: The numpy dtype for the returned unitary. `dtype` must be
a complex np.dtype, unless all operations in the circuit have
unitary matrices with exclusively real coefficients
(e.g. an H + TOFFOLI circuit).

Returns:
A (possibly gigantic) 2d numpy array corresponding to a matrix
Expand Down
4 changes: 3 additions & 1 deletion cirq-core/cirq/contrib/acquaintance/executor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def test_executor_random(
circuit.append(cca.LinearPermutationGate(num_qubits, permutation)(*qubits))
actual_unitary = circuit.unitary()

np.testing.assert_allclose(actual=actual_unitary, desired=expected_unitary, verbose=True)
np.testing.assert_allclose(
actual=actual_unitary, desired=expected_unitary, verbose=True, atol=1e-6
)


def test_acquaintance_operation():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ def test_optimize_large_circuit():

c_opt = clifford_optimized_circuit(c_orig)

cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-7)
cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-6)
3 changes: 1 addition & 2 deletions cirq-core/cirq/contrib/paulistring/convert_gate_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def converted_gate_set(
circuit: circuits.Circuit, no_clifford_gates: bool = False, atol: float = 1e-8
) -> circuits.Circuit:
"""Returns a new, equivalent circuit using the gate set
{SingleQubitCliffordGate,
CZ/PauliInteractionGate, PauliStringPhasor}.
{SingleQubitCliffordGate, CZ/PauliInteractionGate, PauliStringPhasor}.
"""
conv_circuit = transformers.optimize_for_target_gateset(
circuit, gateset=transformers.CZTargetGateset()
Expand Down
6 changes: 3 additions & 3 deletions cirq-core/cirq/contrib/paulistring/optimize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_optimize():

c_opt = optimized_circuit(c_orig)

cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-7)
cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-6)

cirq.testing.assert_has_diagram(
c_opt,
Expand All @@ -68,7 +68,7 @@ def test_optimize_large_circuit():

c_opt = optimized_circuit(c_orig)

cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-7)
cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-6)

assert (
sum(
Expand All @@ -86,7 +86,7 @@ def test_repeat_limit():

c_opt = optimized_circuit(c_orig, repeat=1)

cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-7)
cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-6)

assert (
sum(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def test_pauli_string_dag_from_circuit():
c_left_reordered = c_left_dag.to_circuit()

cirq.testing.assert_allclose_up_to_global_phase(
c_left.unitary(), c_left_reordered.unitary(), atol=1e-7
c_left.unitary(), c_left_reordered.unitary(), atol=1e-6
)
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_optimize():

c_opt = pauli_string_optimized_circuit(c_orig)

cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-7)

assert c_opt == c_expected
cirq.testing.assert_allclose_up_to_global_phase(
c_orig.unitary(), c_expected.unitary(), atol=1e-6
)

cirq.testing.assert_has_diagram(
c_opt,
Expand Down Expand Up @@ -81,4 +81,4 @@ def test_optimize_large_circuit():

c_opt = pauli_string_optimized_circuit(c_orig)

cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-7)
cirq.testing.assert_allclose_up_to_global_phase(c_orig.unitary(), c_opt.unitary(), atol=1e-6)
2 changes: 1 addition & 1 deletion cirq-core/cirq/contrib/paulistring/separate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_toffoli_separate():
c_left, c_right = convert_and_separate_circuit(circuit)

cirq.testing.assert_allclose_up_to_global_phase(
circuit.unitary(), (c_left + c_right).unitary(), atol=1e-7
circuit.unitary(), (c_left + c_right).unitary(), atol=1e-6
)

assert all(isinstance(op, cirq.PauliStringPhasor) for op in c_left.all_operations())
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/contrib/qasm_import/qasm_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ def test_consistency_with_qasm_output_and_qiskit():
circuit2 = circuit_from_qasm(qasm)

cirq_unitary = cirq.unitary(circuit2)
ct.assert_allclose_up_to_global_phase(cirq_unitary, cirq.unitary(circuit1), atol=1e-8)
ct.assert_allclose_up_to_global_phase(cirq_unitary, cirq.unitary(circuit1), atol=1e-6)

cq.assert_qiskit_parsed_qasm_consistent_with_unitary(qasm, cirq_unitary)
2 changes: 1 addition & 1 deletion cirq-core/cirq/ion/convert_to_ion_gates_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_convert_to_ion_gates():
atol=1e-4,
)
assert cirq.allclose_up_to_global_phase(
cirq.unitary(cirq.Circuit(rcnot)), cirq.unitary(OtherCNOT().on(q0, q1))
cirq.unitary(cirq.Circuit(rcnot)), cirq.unitary(OtherCNOT().on(q0, q1)), atol=1e-6
)


Expand Down
19 changes: 13 additions & 6 deletions cirq-core/cirq/linalg/decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,8 @@ def scatter_plot_normalized_kak_interaction_coefficients(
*,
include_frame: bool = True,
ax: Optional[plt.Axes] = None,
rtol: float = 1e-5,
atol: float = 1e-6,
**kwargs,
):
r"""Plots the interaction coefficients of many two-qubit operations.
Expand Down Expand Up @@ -590,6 +592,13 @@ def scatter_plot_normalized_kak_interaction_coefficients(
wireframe. Defaults to `True`.
ax: A matplotlib 3d axes object to plot into. If not specified, a new
figure is created, plotted, and shown.
rtol: Per-matrix-entry relative tolerance on equality used if the
kak decomposition is calculated from the `interactions`.
atol: Per-matrix-entry absolute tolerance on equality used if the
kak decomposition is calculated from the `interaction`s. T
This determines how close $k_x$ must be to π/4 to guarantee
$k_z$ ≥ 0. Must be non-negative.

**kwargs: Arguments forwarded into the call to `scatter` that plots the
points. Working arguments include color `c='blue'`, scale `s=2`,
labelling `label="theta=pi/4"`, etc. For reference see the
Expand Down Expand Up @@ -662,7 +671,7 @@ def coord_transform(
else:
interactions_extracted = [interactions]

points = kak_vector(interactions_extracted) * 4 / np.pi
points = kak_vector(interactions_extracted, rtol=rtol, atol=atol) * 4 / np.pi

ax.scatter(*coord_transform(points), **kwargs)
ax.set_xlim(0, +1)
Expand Down Expand Up @@ -810,7 +819,7 @@ def kak_decomposition(
],
*,
rtol: float = 1e-5,
atol: float = 1e-8,
atol: float = 1e-6,
check_preconditions: bool = True,
) -> KakDecomposition:
"""Decomposes a 2-qubit unitary into 1-qubit ops and XX/YY/ZZ interactions.
Expand Down Expand Up @@ -848,9 +857,7 @@ def kak_decomposition(
if check_preconditions and (
mat.shape != (4, 4) or not predicates.is_unitary(mat, rtol=rtol, atol=atol)
):
raise ValueError(
'Input must correspond to a 4x4 unitary matrix. Received matrix:\n' + str(mat)
)
raise ValueError(f'Input must correspond to a 4x4 unitary matrix. Received matrix:\n{mat}')

# Diagonalize in magic basis.
left, d, right = diagonalize.bidiagonalize_unitary_with_special_orthogonals(
Expand Down Expand Up @@ -948,7 +955,7 @@ def kak_vector(

if check_preconditions:
actual = np.einsum('...ba,...bc', unitary.conj(), unitary) - np.eye(4)
if not np.allclose(actual, np.zeros_like(actual), rtol, atol):
if not np.allclose(np.zeros_like(actual), actual, rtol=rtol, atol=atol):
raise ValueError(
'Input must correspond to a 4x4 unitary matrix or tensor of '
f'unitary matrices. Received input:\n{unitary}'
Expand Down
16 changes: 9 additions & 7 deletions cirq-core/cirq/linalg/decompositions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,15 +738,17 @@ def test_kak_vector_input_not_unitary():
def test_kak_decompose(unitary: np.ndarray):
kak = cirq.kak_decomposition(unitary)
circuit = cirq.Circuit(kak._decompose_(cirq.LineQubit.range(2)))
np.testing.assert_allclose(cirq.unitary(circuit), unitary, atol=1e-8)
np.testing.assert_allclose(cirq.unitary(circuit), unitary, atol=1e-6)
assert len(circuit) == 5
assert len(list(circuit.all_operations())) == 8


def test_num_two_qubit_gates_required():
for i in range(4):
assert (
cirq.num_cnots_required(cirq.testing.random_two_qubit_circuit_with_czs(i).unitary())
cirq.num_cnots_required(
cirq.testing.random_two_qubit_circuit_with_czs(i).unitary(), atol=1e-6
)
== i
)

Expand All @@ -759,7 +761,7 @@ def test_num_two_qubit_gates_required_invalid():


@pytest.mark.parametrize(
"U",
"u",
[
cirq.testing.random_two_qubit_circuit_with_czs(3).unitary(),
# an example where gamma(special(u))=I, so the denominator becomes 0
Expand All @@ -776,8 +778,8 @@ def test_num_two_qubit_gates_required_invalid():
),
],
)
def test_extract_right_diag(U):
assert cirq.num_cnots_required(U) == 3
diag = cirq.linalg.extract_right_diag(U)
def test_extract_right_diag(u):
assert cirq.num_cnots_required(u) == 3
diag = cirq.linalg.extract_right_diag(u)
assert cirq.is_diagonal(diag)
assert cirq.num_cnots_required(U @ diag) == 2
assert cirq.num_cnots_required(u @ diag, atol=1e-6) == 2
10 changes: 6 additions & 4 deletions cirq-core/cirq/ops/diagonal_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def test_decomposition_unitary(n):
expected_f = [np.exp(1j * angle) for angle in diagonal_angles]
decomposed_f = cirq.unitary(decomposed_circ).diagonal()

np.testing.assert_allclose(decomposed_f, expected_f)
# For large qubit counts, the decomposed circuit is rather large, so we lose a lot of
# precision.
np.testing.assert_allclose(decomposed_f, expected_f, atol=5e-6)


@pytest.mark.parametrize('n', [1, 2, 3, 4])
Expand All @@ -63,7 +65,7 @@ def test_diagonal_exponent(n):
sqrt_diagonal_gate = diagonal_gate**0.5

expected_angles = [prime / 2 for prime in diagonal_angles]
np.testing.assert_allclose(expected_angles, sqrt_diagonal_gate._diag_angles_radians, atol=1e-8)
np.testing.assert_allclose(expected_angles, sqrt_diagonal_gate._diag_angles_radians, atol=1e-6)

assert cirq.pow(cirq.DiagonalGate(diagonal_angles), "test", None) is None

Expand All @@ -78,7 +80,7 @@ def test_decomposition_diagonal_exponent(n):
expected_f = [np.exp(1j * angle / 2) for angle in diagonal_angles]
decomposed_f = cirq.unitary(decomposed_circ).diagonal()

np.testing.assert_allclose(decomposed_f, expected_f)
np.testing.assert_allclose(decomposed_f, expected_f, atol=1e-6)


@pytest.mark.parametrize('n', [1, 2, 3, 4])
Expand All @@ -97,7 +99,7 @@ def test_decomposition_with_parameterization(n):
resolved_op = cirq.resolve_parameters(parameterized_op, resolver)
resolved_circuit = cirq.resolve_parameters(decomposed_circuit, resolver)
np.testing.assert_allclose(
cirq.unitary(resolved_op), cirq.unitary(resolved_circuit), atol=1e-8
cirq.unitary(resolved_op), cirq.unitary(resolved_circuit), atol=1e-6
)


Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/fsim_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def test_phased_fsim_from_fsim_rz(theta, phi, rz_angles_before, rz_angles_after)
cirq.rz(rz_angles_after[0]).on(q0),
cirq.rz(rz_angles_after[1]).on(q1),
)
cirq.testing.assert_allclose_up_to_global_phase(cirq.unitary(f), cirq.unitary(c), atol=1e-8)
cirq.testing.assert_allclose_up_to_global_phase(cirq.unitary(f), cirq.unitary(c), atol=1e-6)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/matrix_gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(
name: str = None,
qid_shape: Optional[Iterable[int]] = None,
unitary_check_rtol: float = 1e-5,
unitary_check_atol: float = 1e-8,
unitary_check_atol: float = 1e-6,
) -> None:
"""Initializes a matrix gate.

Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/parallel_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_unitary(gate, num_copies, qubits):
step = gate.num_qubits()
qubit_lists = [qubits[i * step : (i + 1) * step] for i in range(num_copies)]
np.testing.assert_allclose(
cirq.unitary(g), cirq.unitary(cirq.Circuit(gate.on_each(qubit_lists))), atol=1e-8
cirq.unitary(g), cirq.unitary(cirq.Circuit(gate.on_each(qubit_lists))), atol=1e-6
)


Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/phased_x_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_parameterize(resolve_fn, global_shift):
np.testing.assert_allclose(
cirq.unitary(resolved_gate(q)),
cirq.unitary(resolve_fn(parameterized_decomposed_circuit, resolver)),
atol=1e-8,
atol=1e-6,
)

unparameterized_gate = cirq.PhasedXPowGate(
Expand Down
1 change: 1 addition & 0 deletions cirq-core/cirq/ops/two_qubit_diagonal_gate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_parameterized_decompose():
np.testing.assert_allclose(
cirq.unitary(cirq.resolve_parameters(parameterized_op, resolver)),
cirq.unitary(cirq.resolve_parameters(decomposed_circuit, resolver)),
atol=1e-6,
)


Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/optimizers/merge_interactions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def assert_optimization_not_broken(circuit):
cirq.MergeInteractions().optimize_circuit(circuit)
u_after = circuit.unitary()

cirq.testing.assert_allclose_up_to_global_phase(u_before, u_after, atol=1e-8)
cirq.testing.assert_allclose_up_to_global_phase(u_before, u_after, atol=1e-6)


def test_clears_paired_cnot():
Expand Down Expand Up @@ -254,4 +254,4 @@ def clean_up(operations):

u_before = c_orig.unitary()
u_after = circuit[1:-1].unitary()
cirq.testing.assert_allclose_up_to_global_phase(u_before, u_after, atol=1e-8)
cirq.testing.assert_allclose_up_to_global_phase(u_before, u_after, atol=1e-6)
3 changes: 2 additions & 1 deletion cirq-core/cirq/testing/circuit_compare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ def test_measuring_qubits():
'circuit', [cirq.testing.random_circuit(cirq.LineQubit.range(2), 4, 0.5) for _ in range(5)]
)
def test_random_same_matrix(circuit):
circuit_copy = circuit.copy()
a, b = cirq.LineQubit.range(2)
same = cirq.Circuit(
cirq.MatrixGate(circuit.unitary(qubits_that_should_be_present=[a, b])).on(a, b)
)

cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(circuit, same)
cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(circuit_copy, same)

mutable_circuit = circuit.copy()
mutable_circuit.append(cirq.measure(a))
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/testing/consistent_decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ def assert_decompose_is_consistent_with_unitary(val: Any, ignoring_global_phase:
actual = circuits.Circuit(dec).unitary(qubit_order=qubits)

if ignoring_global_phase:
lin_alg_utils.assert_allclose_up_to_global_phase(actual, expected, atol=1e-8)
lin_alg_utils.assert_allclose_up_to_global_phase(actual, expected, atol=1e-6)
else:
# coverage: ignore
np.testing.assert_allclose(actual, expected, atol=1e-8)
np.testing.assert_allclose(actual, expected, atol=1e-6)


def _known_gate_with_no_decomposition(val: Any):
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/testing/consistent_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def assert_qiskit_parsed_qasm_consistent_with_unitary(qasm, unitary):
qiskit_unitary = result.result().get_unitary()
qiskit_unitary = _reorder_indices_of_matrix(qiskit_unitary, list(reversed(range(num_qubits))))

lin_alg_utils.assert_allclose_up_to_global_phase(unitary, qiskit_unitary, rtol=1e-8, atol=1e-8)
lin_alg_utils.assert_allclose_up_to_global_phase(unitary, qiskit_unitary, rtol=1e-6, atol=1e-6)


def _indent(*content: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_decompose_x():
*qubits[0 : controls_count + 1]
)
expected_matrix = circuit2.unitary()
assert np.allclose(expected_matrix, result_matrix)
assert np.allclose(expected_matrix, result_matrix, atol=1e-6)


def _random_unitary():
Expand Down Expand Up @@ -88,7 +88,9 @@ def _test_decompose(matrix, controls_count):
[cirq.MatrixGate(matrix).on(qubits[-1]).controlled_by(*qubits[:-1])]
).unitary()

assert np.allclose(expected_matrix, result_matrix)
# Decompose can build rather large circuits for large controls_count,
# so we lose a lot of precision.
np.testing.assert_allclose(expected_matrix, result_matrix, atol=1e-5)


def test_decompose_specific_matrices():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def assert_decomposition_valid(cphase_gate, fsim_gate):
u_expected = cirq.unitary(cphase_gate)
ops = cirq.decompose_cphase_into_two_fsim(cphase_gate, fsim_gate=fsim_gate)
u_actual = cirq.unitary(cirq.Circuit(ops))
assert np.allclose(u_actual, u_expected)
assert np.allclose(u_actual, u_expected, atol=1e-6)


@pytest.mark.parametrize(
Expand Down
Loading