{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Projectq Tutorials\n", "\n", "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.\n", "\n", "\n", "## Projectq to QLM conversion\n", "\n", "Here is an example that shows how one can convert projectq circuits into QLM circuits." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2022-11-05T19:49:38.320789Z", "iopub.status.busy": "2022-11-05T19:49:38.320475Z", "iopub.status.idle": "2022-11-05T19:49:38.870965Z", "shell.execute_reply": "2022-11-05T19:49:38.870414Z" } }, "outputs": [], "source": [ "from projectq.cengines import MainEngine\n", "from projectq.ops import H, CX, All, Measure\n", "\n", "from qat.interop.projectq.converters import AqasmPrinter, AqasmEngine\n", "\n", "# this first engine is only used as a workaround for some issues\n", "# only engine you should be interacting with is the AqasmEngine\n", "aq = AqasmPrinter(MainEngine)\n", "eng = AqasmEngine(aq, engine_list=[aq])\n", "\n", "qreg = eng.allocate_qureg(2)\n", "\n", "H | qreg[0]\n", "CX | (qreg[0], qreg[1])\n", "\n", "All(Measure) | qreg\n", "\n", "# Generate the QLM circuit with the to_qlm_circ method\n", "qlm_circuit = eng.projectq_to_qlm()\n", "\n", "from qat.core.util import extract_syntax\n", "\n", "for entry in qlm_circuit.ops:\n", " # no need to print measures\n", " if entry.gate is None:\n", " continue\n", " print(\"Gate {} with params {} on qbits {}\"\n", " .format(*extract_syntax(qlm_circuit.gateDic[entry.gate],\n", " qlm_circuit.gateDic), entry.qbits))" ] } ], "metadata": { "authors": [ "Simon Martiel", "Arnaud Gazda" ], "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" } }, "nbformat": 4, "nbformat_minor": 2 }