#!/usr/bin/env python # coding: utf-8 # # Projectq Tutorials # # Due to the very different nature of how projectq works, we only implemented a wrapper around their `MainEngine`. But instead of simulating the circuit on the fly, it only creates a QLM circuit progressively, it can then output the QLM circuit using the `projectq_to_qlm` method. # # # ## Projectq to QLM conversion # # Here is an example that shows how one can convert projectq circuits into QLM circuits. # In[ ]: from projectq.cengines import MainEngine from projectq.ops import H, CX, All, Measure from qat.interop.projectq.converters import AqasmPrinter, AqasmEngine # this first engine is only used as a workaround for some issues # only engine you should be interacting with is the AqasmEngine aq = AqasmPrinter(MainEngine) eng = AqasmEngine(aq, engine_list=[aq]) qreg = eng.allocate_qureg(2) H | qreg[0] CX | (qreg[0], qreg[1]) All(Measure) | qreg # Generate the QLM circuit with the to_qlm_circ method qlm_circuit = eng.projectq_to_qlm() from qat.core.util import extract_syntax for entry in qlm_circuit.ops: # no need to print measures if entry.gate is None: continue print("Gate {} with params {} on qbits {}" .format(*extract_syntax(qlm_circuit.gateDic[entry.gate], qlm_circuit.gateDic), entry.qbits))