def _single_qubit_matrices_with_sqrt_iswap(
    kak: cirq.KakDecomposition, required_sqrt_iswap_count: int | None = None, atol: float = 1e-8
) -> tuple[Sequence[tuple[np.ndarray, np.ndarray]], complex]:
    """Computes the sequence of interleaved single-qubit unitary matrices in the
    sqrt-iSWAP decomposition."""
    decomposers = [
        (_in_0_region, _decomp_0_matrices),
        (_in_1sqrt_iswap_region, _decomp_1sqrt_iswap_matrices),
        (_in_2sqrt_iswap_region, _decomp_2sqrt_iswap_matrices),
        (_in_3sqrt_iswap_region, _decomp_3sqrt_iswap_matrices),
    ]
    if required_sqrt_iswap_count is not None:
        if not 0 <= required_sqrt_iswap_count <= 3:
            raise ValueError('the argument `required_sqrt_iswap_count` must be 0, 1, 2, or 3.')
        can_decompose, decomposer = decomposers[required_sqrt_iswap_count]
        if not can_decompose(kak.interaction_coefficients, weyl_tol=atol / 10):
            raise ValueError(
                f'the given gate cannot be decomposed into exactly '
                f'{required_sqrt_iswap_count} sqrt-iSWAP gates.'
            )
        return decomposer(kak, atol=atol)
    for can_decompose, decomposer in decomposers:
        if can_decompose(kak.interaction_coefficients, weyl_tol=atol / 10):
            return decomposer(kak, atol)
    assert False, 'The final can_decompose should always returns True'  # pragma: no cover
Computes the sequence of interleaved single-qubit unitary matrices in the
    sqrt-iSWAP decomposition.
cirq-core/cirq/transformers/analytical_decompositions/two_qubit_to_sqrt_iswap.py