{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Compression 1-qubit gates\n", "\n", "`qat.pbo` comes with a plugin, called `KAKCompression` that can compress sequences of single qubit gates into some universal pattern of gates\n", "(typically three Pauli rotations).\n", "\n", "This plugin comes with a preset of possible (named) patterns you can pick from:\n", "- $RZ-RX-RZ$ (key: **ZXZ**)\n", "- $RX-RZ-RX$ (key: **XZX**)\n", "- $RZ-RY-RZ$ (key: **ZYZ**)\n", "- $U_3$ (which is universal by itself) (key: **u3** or **ibm**)\n", "- $RZ-RX(\\pi/2)-RZ-RX(\\pi/2)-RZ$ (key: **rx+** or **ions**)\n", "\n", "Instances of the plugin can be constructed via the `.from_pattern` static method.\n", "\n", "Let us try to use this plugin on some examples !" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "from qat.lang.AQASM import *\n", "from qat.core import Batch\n", "\n", "prog = Program()\n", "qbits = prog.qalloc(2)\n", "\n", "H(qbits[0])\n", "RX(0.232)(qbits[0])\n", "CNOT(qbits)\n", "RZ(1.89)(qbits[1])\n", "H(qbits[1])\n", "circuit = prog.to_circ()\n", "circuit.display()\n", "\n", "input = Batch(jobs=[circuit.to_job()])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from qat.plugins import KAKCompression\n", "from qat.pbo.kak import list_decompositions\n", "\n", "for decomposition in list_decompositions():\n", " plugin = KAKCompression(decomposition=decomposition)\n", " new_circuit = plugin.compile(input, None).jobs[0].circuit\n", " print(f\"Using decomposition: {decomposition}\")\n", " new_circuit.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "documentation-tags": { "icon": ":material-outlined:`compress;3em`" }, "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" }, "vscode": { "interpreter": { "hash": "f9f85f796d01129d0dd105a088854619f454435301f6ffec2fea96ecbd9be4ac" } } }, "nbformat": 4, "nbformat_minor": 2 }