def test_gate_conversion():
    """Check that the gates all convert with matching unitaries."""
    for quil_gate, cirq_gate in SUPPORTED_GATES.items():
        if quil_gate in PARAMETRIC_TRANSFORMERS:
            pyquil_def = getattr(matrices, quil_gate)
            sig = signature(pyquil_def)
            num_params = len(sig.parameters)
            sample_params = list(np.random.random(num_params) * np.pi)

            pyquil_unitary = pyquil_def(*sample_params)
            cirq_unitary = unitary(cirq_gate(**PARAMETRIC_TRANSFORMERS[quil_gate](*sample_params)))
            assert np.allclose(pyquil_unitary, cirq_unitary)

        else:
            assert np.allclose(getattr(matrices, quil_gate), unitary(cirq_gate))
Check that the gates all convert with matching unitaries.
cirq-rigetti/cirq_rigetti/quil_input_test.py