Convert a  pyQuil program to a QuantumFlow Program

def pyquil_to_program(program: pyquil.Program) -> Program:
    """Convert a  pyQuil program to a QuantumFlow Program"""
    def _reg(mem: Any) -> Any:
        if isinstance(mem, pyquil.MemoryReference):
            return Register(mem.name)[mem.offset]
        return mem

    prog = Program()
    for inst in program:
        if isinstance(inst, pyquil.Gate):
            qubits = [q.index for q in inst.qubits]
            if inst.name in STDGATES:
                defgate = STDGATES[inst.name]
                gate = defgate(*inst.params)
                gate = gate.relabel(qubits)
                prog += gate
            else:
                prog += Call(inst.name, inst.params, qubits)

        elif isinstance(inst, pyquil.ClassicalEqual):
            prog += EQ(_reg(inst.target), _reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalLessThan):
            prog += LT(_reg(inst.target), _reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalLessEqual):
            prog += LE(_reg(inst.target), _reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalGreaterThan):
            prog += GT(_reg(inst.target), _reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalGreaterEqual):
            prog += GE(_reg(inst.target), _reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalAdd):
            prog += Add(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalMul):
            prog += Mul(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalDiv):
            prog += Div(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalSub):
            prog += Sub(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalAnd):
            prog += And(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalExchange):
            prog += Exchange(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalInclusiveOr):
            prog += Ior(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalMove):
            # Also handles deprecated ClassicalTrue and ClassicalFalse
            prog += Move(_reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalNeg):
            prog += Neg(_reg(inst.target))

        elif isinstance(inst, pyquil.ClassicalNot):
            prog += Not(_reg(inst.target))

        elif isinstance(inst, pyquil.ClassicalExclusiveOr):
            target = _reg(inst.left)
            source = _reg(inst.right)
            prog += Xor(target, source)

        elif isinstance(inst, pyquil.Declare):
            prog += Declare(inst.name,
                            inst.memory_type,
                            inst.memory_size,
                            inst.shared_region)

        elif isinstance(inst, pyquil.Halt):
            prog += Halt()

        elif isinstance(inst, pyquil.Jump):
            prog += Jump(inst.target.name)

        elif isinstance(inst, pyquil.JumpTarget):
            prog += Label(inst.label.name)

        elif isinstance(inst, pyquil.JumpWhen):
            prog += JumpWhen(inst.target.name, _reg(inst.condition))

        elif isinstance(inst, pyquil.JumpUnless):
            prog += JumpUnless(inst.target.name, _reg(inst.condition))

        elif isinstance(inst, pyquil.Pragma):
            prog += Pragma(inst.command, inst.args, inst.freeform_string)

        elif isinstance(inst, pyquil.Measurement):
            if inst.classical_reg is None:
                prog += Measure(inst.qubit.index)
            else:
                prog += Measure(inst.qubit.index, _reg(inst.classical_reg))

        elif isinstance(inst, pyquil.Nop):
            prog += Nop()

        elif isinstance(inst, pyquil.Wait):
            prog += Wait()

        elif isinstance(inst, pyquil.Reset):
            prog += Reset()

        elif isinstance(inst, pyquil.ResetQubit):
            prog += Reset(inst.qubit)

        elif isinstance(inst, pyquil.ClassicalStore):
            prog += Store(inst.target, _reg(inst.left), _reg(inst.right))

        elif isinstance(inst, pyquil.ClassicalLoad):
            prog += Load(_reg(inst.target), inst.left, _reg(inst.right))

        # elif isinstance(inst, pyquil.ClassicalConvert):
        #     prog += Convert(inst.target, _reg(inst.left), _reg(inst.right))

        else:
            raise ValueError('Unknown pyQuil instruction: {}'
                             .format(str(inst)))   # pragma: no cover

    return prog