<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def circuit_to_pyquil(circuit: Circuit) -> pyquil.Program: """Convert a QuantumFlow circuit to a pyQuil program"""

    prog = pyquil.Program()

    for elem in circuit.elements:
        if isinstance(elem, Gate) and elem.name in QUIL_GATES:
            params = list(elem.params.values()) if elem.params else []
            prog.gate(elem.name, params, elem.qubits)
        elif isinstance(elem, Measure):
            prog.measure(elem.qubit, elem.cbit)
        else:
            # FIXME: more informative error message
            raise ValueError('Cannot convert operation to pyquil')

    return prog