ProjectQ interoperability

Translating quantum circuits

myQLM provides binders to translate ProjectQ circuits into myQLM circuits through classes AqasmPrinter and AqasmEngine

from projectq.ops import X, H, CNOT
from projectq.cengines import MainEngine
from qat.interop.projectq import AqasmPrinter, AqasmEngine

# Define AQASM engine
aq = AqasmPrinter(MainEngine)
eng = AqasmEngine(aq, engine_list=[aq])

# Create a ProjectQ circuit
q = eng.allocate_qureg(2)
X | q[0]
H | q[0]
CNOT | (q[0], q[1])

# Then recover your generated qlm circuit with
circ = eng.projectq_to_qlm()
print("The circuit is composed of the gates:",
      list(circ.iterate_simple()))
The circuit is composed of the gates: [('X', [], [0]), ('H', [], [0]), ('CNOT', [], [0, 1])]

Source code documentation

class qat.interop.projectq.AqasmPrinter(engine=<class 'projectq.cengines._main.MainEngine'>, **kwargs)

A compiler engine which can retrieve all data sent to the stream then send it over to the AqasmEngine

receive(command_list)

Forward the list of commands to the first engine.

Parameters

command_list (list<Command>) – List of commands to receive (and then send on)

class qat.interop.projectq.AqasmEngine(aq, engine_list=[], verbose=False)

A compiler engine which can print and export commands in AQASM format.

projectq_to_qlm(sep_measure=False, **kwargs)

Generates the QLM circuit corresponding to all projectq commands we sent to the engine

Parameters
  • sep_measures

    Separates measures from the circuit:

    • if set to True measures won’t be included in the resulting circuits, qubits to be measured will be put in a list, the resulting measureless circuit and this list will be returned in a tuple : (resulting_circuit, list_qubits)

    • if set to False, measures will be converted normally (Default set to False)

  • kwargs – these are the options that you would use on a regular to_circ function, these are added for more flexibility, for advanced users

Returns

If sep_measures is set to:

  • True: the result is a tuple composed of a Circuit and a list of qubits that should be measured

  • False: the result is a Circuit

Return type

tuple or Circuit