def test_decompose_single_qubit_matrix_gate():
    q = cirq.LineQubit(0)
    for _ in range(100):
        gate = cirq.MatrixGate(cirq.testing.random_unitary(2))
        circuit = cirq.Circuit(gate(q))
        decomposed_circuit = cirq.Circuit(*ionq.decompose_to_device(gate(q)))
        cirq.testing.assert_circuits_with_terminal_measurements_are_equivalent(
            circuit, decomposed_circuit, atol=1e-8)
        assert VALID_DECOMPOSED_GATES.validate(decomposed_circuit)
def test_decompose_unsupported_gate():
    q0, q1, q2 = cirq.LineQubit.range(3)
    op = cirq.CCZ(q0, q1, q2)
    with pytest.raises(ValueError, match='not supported'):
        _ = ionq.decompose_to_device(op)
def test_decompose_leaves_supported_alone(gate):
    qubits = cirq.LineQubit.range(gate.num_qubits())
    operation = gate(*qubits)
    assert ionq.decompose_to_device(operation) == operation