{ "cells": [ { "cell_type": "markdown", "metadata": { "qat-category": "1-Circuit generation in Python", "qat-summary": "1-Creation of an EPR pair using two qubits" }, "source": [ "# Creation of an EPR pair using two qubits\n", "\n", "\n", " \n", "Let us start with a simple circuit: the creation of an EPR pair using two qubits.\n", " \n", " \n", "First, we need to import relevant objects from the python AQASM module:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from qat.lang.AQASM import Program, H, CNOT " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creation of the quantum program\n", "\n", "Then, we can declare a new object ``Program``. Let us give it an explicit name:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "epr_prog = Program() " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To create our EPR pair, we need to manipulate two qbits. \n", "Qbits are manipulated through qbit registers only (to keep things structured).\n", "Registers are allocated as follows:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qbits = epr_prog.qalloc(2) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, we can access our qbits using the register \"qbits\".\n", "\n", "Registers behave like python list/arrays.\n", "\n", "Here our qbits will be refered to using qbits[0] and qbits[1].\n", "\n", "To create our EPR pair, we simply implement the appropriate 2-qbit rotation using a Hadamard gate (H) on the first qbit, followed by a controlled NOT gate (CNOT) on both qbits:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "epr_prog.apply(H, qbits[0]) \n", "epr_prog.apply(CNOT, qbits)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that since the CNOT is applied on both qbits (it is a 2-qbit gate), we can pass the whole register as argument to the ``.apply`` method." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The corresponding circuit object can be extracted directly from the Program object as follows:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "circuit = epr_prog.to_circ()\n", "%qatdisplay circuit" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Simulation of the execution of the circuit\n", "Now that we have a proper circuit, we can try and simulate it:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Let us import some qpu connected to a classical linear algebra simulator\n", "from qat.qpus import PyLinalg\n", "qpu = PyLinalg()\n", "\n", "job = circuit.to_job()\n", "\n", "result = qpu.submit(job)\n", "for sample in result:\n", " print(\"State\", sample.state, \"with amplitude\", sample.amplitude)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Export to Atos Quantum Assembly Language (AQASM) format\n", "We can also export our circuit in the AQASM format:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "epr_prog.export(\"helloworld.aqasm\") " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The generated file *helloworld.aqasm* should look like this:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!cat helloworld.aqasm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and can be compiled to circ format as follows:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "!aqasm2circ helloworld.aqasm" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "authors": [ "Simon Martiel" ], "kernelspec": { "display_name": "Python 3", "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.6.8" } }, "nbformat": 4, "nbformat_minor": 1 }