def test_pyquil_commands(self):
     wrapper = CircuitWrapper(
         qiskit_circuit=grover_general_logicalexpression_qiskit(
             "(A | B) & (A | ~B) & (~A | B)"))
     print(wrapper.circuit)
     commands = wrapper.export_pyquil_commands()
     print(commands)
 def test_qiskit_commands(self):
     wrapper = CircuitWrapper(qiskit_circuit=shor_general(3))
     # print(wrapper.circuit)
     commands = wrapper.export_qiskit_commands()
     print(commands)
     circuit = qiskit_commands_to_circuit(commands)
     print(circuit)
    def test_analysis(self):
        wrapper = CircuitWrapper(qiskit_circuit=shor_15())
        print(wrapper.circuit)
        wrapper.unroll_ibm()
        print(wrapper.circuit)

        # print(wrapper.circuit)
        # print(wrapper.depth())
        # print(wrapper.depth_gate_times())
        print(wrapper.depth_two_qubit_gates())
def simulate():
    data = request.json
    circuit = data["circuit"]
    try:
        wrapper = CircuitWrapper(qiskit_instructions=circuit)
        output = wrapper.simulate()
    except Exception as e:
        print(str(e))
        return str(e), 500
    return output
def circuit_to_internal():
    data = request.json
    option = data["option"]
    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
        output = wrapper.export_qiskit_commands()
    except Exception as e:
        print(str(e))
        return str(e), 500
    return output
 def test_compare_depth_topology(self):
     wrapper = CircuitWrapper(qiskit_circuit=grover_fix_SAT_qiskit())
     # print(ibmq_16_melbourne())
     wrapper.compare_depth_topology(aspen_4(),
                                    wrapper.depth_two_qubit_gates)
 def test_topology_mapping(self):
     wrapper = CircuitWrapper(qiskit_circuit=shor_15())
     wrapper.unroll_ibm()
     print(wrapper.circuit)
     wrapper.topology_mapping(aspen_4())
     print(wrapper.circuit)
 def test_unroll(self):
     wrapper = CircuitWrapper(qiskit_circuit=shor_general(3))
     wrapper.unroll_rigetti()
     print(wrapper.circuit)
 def test_decompose(self):
     print(qiskit_custom_unroll())
     wrapper = CircuitWrapper(qiskit_circuit=qiskit_custom_unroll())
     wrapper.decompose_to_standard_gates()
     print(wrapper.circuit)
 def test_qasm_export(self):
     wrapper = CircuitWrapper(qiskit_circuit=qiskit_custom_unroll())
     qasm = wrapper.export_qasm()
     print(qasm)
 def test_pyquil_export(self):
     wrapper = CircuitWrapper(qiskit_circuit=qiskit_custom())
     pyquil = wrapper.export_pyquil()
     print(pyquil)
 def test_pyquil_import(self):
     wrapper = CircuitWrapper(pyquil_program=pyquil_custom())
     show_figure(wrapper.circuit)
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 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 depth_comparison_qpu():
    data = request.json
    circuit = data["circuit"]
    depth = {}
    try:
        wrapper = CircuitWrapper(qiskit_instructions=circuit)
        circuit = wrapper.circuit
        qpu_map = qpus()
        for qpu_name in qpu_map:
            wrapper = CircuitWrapper(qiskit_circuit=circuit)
            is_ibm = False
            qpu = qpu_map[qpu_name]
            if qpu[1] == "q":
                is_ibm = True
            qpu_multiplier = qpu[1]
            qpu_coupling = qpu[2]
            if len(wrapper.dag.qubits) > len(qpu_coupling.physical_qubits):
                continue
            if is_ibm:
                wrapper.unroll_ibm()
                depth["q_depth"] = wrapper.depth() * qpu_multiplier
                depth["q_two_qubit"] = wrapper.depth_two_qubit_gates(
                ) * qpu_multiplier
                depth["q_gate_times"] = wrapper.depth_gate_times(
                ) * qpu_multiplier

            else:

                wrapper.unroll_rigetti()
                depth["r_depth"] = wrapper.depth()
                depth["r_two_qubit"] = wrapper.depth_two_qubit_gates()
                depth["r_gate_times"] = wrapper.depth_gate_times()
        output = depth
    except Exception as e:
        print(str(e))
        return str(e), 500
    return output
def depth():
    data = request.json
    circuit = data["circuit"]
    depth = {}
    try:
        wrapper = CircuitWrapper(qiskit_instructions=circuit)
        wrapper.unroll_ibm()
        depth["q_depth"] = wrapper.depth()
        depth["q_two_qubit"] = wrapper.depth_two_qubit_gates()
        depth["q_gate_times"] = wrapper.depth_gate_times()

        wrapper = CircuitWrapper(qiskit_instructions=circuit)
        wrapper.unroll_rigetti()
        depth["r_depth"] = wrapper.depth()
        depth["r_two_qubit"] = wrapper.depth_two_qubit_gates()
        depth["r_gate_times"] = wrapper.depth_gate_times()
        output = depth
    except Exception as e:
        print(str(e))
        return str(e), 500
    return output