{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Cirq Tutorials\n", "\n", "With cirq we only have the function to convert a cirq circuit to a QLM circuit, and no providers nor algorithms, because cirq\n", "doesn't offer the interface for that.\n", "\n", "Cirq has a special feature allowing users to put arbitrary real powers of gates into circuits.\n", "\n", "Not all gate support all powers in this conversion:\n", "\n", "\n", "Gates supporting arbitrary real powers (all of these gates daggers and controls are also supported in power mode):\n", "- X, Y, Z\n", "- RX, RY, RZ\n", "- XX, YY, ZZ\n", "- RXX, RYY, RZZ\n", "- PH\n", "- S, T\n", "\n", "Gates supporting integer powers (all of these gates daggers and controls are also supported in power mode):\n", "- H\n", "- SWAP (also supports square roots +/- 0.5)\n", "- iSWAP\n", "\n", "\n", "## Cirq to qlm conversion\n", "\n", "Below we use an example showing the usage of arbitrary powers \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import cirq\n", "\n", "from numpy import sqrt, pi\n", "\n", "from qat.interop.cirq.converters import cirq_to_qlm\n", "from qat.core.util import get_syntax\n", "\n", "gcirq = cirq.Circuit()\n", "qreg = [cirq.LineQubit(i) for i in range(5)]\n", "\n", "gcirq.append(cirq.X(qreg[0]) ** -3.67)\n", "gcirq.append(cirq.Y(qreg[0]) ** 7.9)\n", "gcirq.append(cirq.Z(qreg[0]) ** (sqrt(5)))\n", "gcirq.append(cirq.S(qreg[0]) ** -pi)\n", "gcirq.append(cirq.T(qreg[0]) ** (sqrt(7)-pi))\n", "gcirq.append(cirq.SWAP(qreg[0], qreg[1]) ** -0.5)\n", "gcirq.append(cirq.ISWAP(qreg[0], qreg[1]) ** 16.0)\n", "for qbit in qreg:\n", " gcirq.append(cirq.measure(qbit))\n", " \n", "# get result with included measures\n", "qlm_circuit = cirq_to_qlm(gcirq)\n", "\n", "for index, op in enumerate(qlm_circuit.ops):\n", " print(\"Gate {} with params {} on qubits {} and cbits {}\".format(*get_syntax(qlm_circuit, index), op.cbits))\n", "\n", "# get result with separated measures\n", "print(\"---------------------------------------------------------\")\n", "qlm_circuit, to_measure = cirq_to_qlm(gcirq, sep_measures=True)\n", "\n", "for index, op in enumerate(qlm_circuit.ops):\n", " print(\"Gate {} with params {} on qubits {}\".format(*get_syntax(qlm_circuit, index)))\n", "print(\"qubits to measure {}\".format(to_measure))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "## QLM to Cirq conversion\n", "\n", "The following is an example on how to convert a QLM circuit to a Cirq circuit" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from qat.interop.cirq.converters import qlm_to_cirq\n", "from qat.lang.AQASM import Program\n", "from qat.lang.AQASM.gates import *\n", "\n", "nbqubits = 2\n", "\n", "prog = Program()\n", "\n", "qreg = prog.qalloc(nbqubits)\n", "creg = prog.calloc(nbqubits)\n", "\n", "prog.apply(H, qreg[0])\n", "prog.apply(CNOT, qreg[0], qreg[1])\n", "\n", "prog.measure(qreg, creg)\n", "qlm_circuit = prog.to_circ()\n", "\n", "# Conversion\n", "cirq_circuit = qlm_to_cirq(qlm_circuit)\n", "\n", "print(cirq_circuit)" ] } ], "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.12.11" } }, "nbformat": 4, "nbformat_minor": 2 }