def convert():
    data = request.json
    option = data["option"]
    option_output = data["optionOutput"]
    circuit = data["circuit"]
    try:
        if option.lower() == "quil":
            wrapper = CircuitWrapper(quil_str=circuit)
        elif option.lower() == "pyquil":
            wrapper = CircuitWrapper(pyquil_instructions=circuit)
        elif option.lower() == "openqasm":
            wrapper = CircuitWrapper(qasm=circuit)
        elif option.lower() == "qiskit":
            wrapper = CircuitWrapper(qiskit_instructions=circuit)
        else:
            return "Bad Request!", 400

        if option_output.lower() == "quil":
            output = wrapper.export_quil()
        elif option_output.lower() == "pyquil":
            output = wrapper.export_pyquil_commands()
        elif option_output.lower() == "openqasm":
            output = wrapper.export_qasm()
        elif option_output.lower() == "qiskit":
            output = wrapper.export_qiskit_commands(include_imports=True)
        else:
            return "Bad Request!", 400
    except Exception as e:
        print(str(e))
        return str(e), 500

    return output
def unroll():
    data = request.json
    option = data["option"]
    circuit = data["circuit"]
    isExpert = data["isExpert"]
    format = data["format"]

    try:
        wrapper = CircuitWrapper(qiskit_instructions=circuit)
        if option == "Rigetti":
            wrapper.unroll_rigetti()
        elif option == "IBMQ":
            wrapper.unroll_ibm()
        else:
            return "Bad Request!", 400

        if isExpert:
            if format == "OpenQASM":
                output = wrapper.export_qasm()
            elif format == "Quil":
                output = wrapper.export_quil()
            elif format == "Qiskit":
                output = wrapper.export_qiskit_commands(include_imports=True)
            elif format == "Pyquil":
                output = wrapper.export_pyquil_commands()
            else:
                return "Bad Request!", 400
        else:
            if option == "Rigetti":
                output = wrapper.export_quil()
            elif option == "IBMQ":
                output = wrapper.export_qasm()
            else:
                return "Bad Request!", 400

    except Exception as e:
        print(str(e))
        return str(e), 500
    return output
def export_circuit():
    data = request.json
    option = data["option"]
    circuit = data["circuit"]
    try:
        wrapper = CircuitWrapper(qiskit_instructions=circuit)
        if option.lower() == "quil":
            output = wrapper.export_quil()
        elif option.lower() == "pyquil":
            output = wrapper.export_pyquil()
        elif option.lower() == "openqasm":
            output = wrapper.export_qasm()
        elif option.lower() == "qiskit":
            output = wrapper.export_qiskit_commands()
        else:
            return "Bad Request!", 400
    except Exception as e:
        print(str(e))
        return str(e), 500
    return output
 def test_qasm_export(self):
     wrapper = CircuitWrapper(qiskit_circuit=qiskit_custom_unroll())
     qasm = wrapper.export_qasm()
     print(qasm)