{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example for qutrit GST\n", "This notebook demonstrates how to construct the operation sequences and perform the analysis for qutrit GST when the model consists of symmetric $\\pi/2$-rotations on each single qubit separately, X, Y and a 2-qubit Molmer-Sorenson gate which rotates around the XX axis by $\\pi/2$." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pygsti\n", "import pygsti.construction as pc\n", "from pygsti.construction import qutrit\n", "\n", "from numpy import pi, array\n", "import pickle\n", "\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, we construct the target model. This functionality is built into pyGSTi, so we just need to specify the single-qubit and M-S angles." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "target_model = qutrit.make_qutrit_model(errorScale=0, Xangle=pi/2, Yangle=pi/2, MSglobal=pi/2, MSlocal=0, basis=\"qt\")\n", "#print(target_model)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now construct the operation sequences needed by GST. These fiducials and germs have been computed ahead of time and the results are used to construct the operation sequence lists below. Then we construct an empty dataset containing all of the necessary experimental sequences which can serve as a template for the actual experimental results." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "fiducialPrep = pc.to_circuits(\n", " [(),('Gy',),('Gx',),('Gm',),\n", " ('Gx','Gx'), ('Gm','Gy'),('Gm','Gx'),\n", " ('Gy','Gy','Gy'),('Gx','Gx','Gx')])\n", "\n", "fiducialMeasure = pc.to_circuits(\n", " [(),('Gy',),('Gx',),('Gm',),\n", " ('Gy','Gm'),('Gx','Gm')])\n", "\n", "maxLengths = [1,2,4]\n", "\n", "germs = pygsti.construction.to_circuits(\n", "[('Gi',),\n", " ('Gy',),\n", " ('Gx',),\n", " ('Gm',),\n", " ('Gi', 'Gy'),\n", " ('Gi', 'Gx'),\n", " ('Gi', 'Gm'),\n", " ('Gy', 'Gx'),\n", " ('Gy', 'Gm'),\n", " ('Gx', 'Gm'),\n", " ('Gi', 'Gi', 'Gy'),\n", " ('Gi', 'Gi', 'Gx'),\n", " ('Gi', 'Gi', 'Gm'),\n", " ('Gi', 'Gy', 'Gy'),\n", " ('Gi', 'Gy', 'Gx'),\n", " ('Gi', 'Gy', 'Gm'),\n", " ('Gi', 'Gx', 'Gy'),\n", " ('Gi', 'Gx', 'Gx'),\n", " ('Gi', 'Gx', 'Gm'),\n", " ('Gi', 'Gm', 'Gy'),\n", " ('Gi', 'Gm', 'Gx'),\n", " ('Gi', 'Gm', 'Gm'),\n", " ('Gy', 'Gy', 'Gx'),\n", " ('Gy', 'Gy', 'Gm'),\n", " ('Gy', 'Gx', 'Gx'),\n", " ('Gy', 'Gx', 'Gm'),\n", " ('Gy', 'Gm', 'Gx'),\n", " ('Gy', 'Gm', 'Gm'),\n", " ('Gx', 'Gx', 'Gm'),\n", " ('Gx', 'Gm', 'Gm')])" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "#Note above construction is now a \"standard\" qutrit model\n", "from pygsti.modelpacks.legacy import stdQT_XYIMS\n", "target_model = stdQT_XYIMS.target_model()\n", "fiducialPrep = stdQT_XYIMS.prepStrs\n", "fiducialMeasure = stdQT_XYIMS.effectStrs\n", "germs = stdQT_XYIMS.germs_lite\n", "maxLengths = [1,2,4]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "9 prep fiducials\n", "7 meas fiducials\n", "31 germs\n" ] } ], "source": [ "print(\"%d prep fiducials\" % len(fiducialPrep))\n", "print(\"%d meas fiducials\" % len(fiducialMeasure))\n", "print(\"%d germs\" % len(germs))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#generate data template\n", "expList = pygsti.construction.create_lsgst_circuits(target_model.operations.keys(), fiducialPrep, fiducialMeasure, germs, maxLengths)\n", "pygsti.io.write_empty_dataset(\"example_files/dataTemplate_qutrit_maxL=4.txt\", expList, \"## Columns = 0bright count, 1bright count, 2bright count\")" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "At this point **STOP** and create/fill a dataset file using the template written in the above cell. Then proceed with the lines below to run GST on the data and create (hopefully useful) reports telling you about your gates." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "mdl_datagen = target_model.depolarize(op_noise=0.05)\n", "DS = pygsti.construction.simulate_data(mdl_datagen, expList, 500, sampleError='multinomial', seed=2018)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "#DS = pygsti.io.load_dataset('PATH_TO_YOUR_DATASET',cache=True) # (cache=True speeds up future loads)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- Circuit Creation ---\n", " 2017 sequences created\n", "-- Std Practice: Iter 1 of 2 (TP) --: \n", " --- Iterative MLGST: [##################################################] 100.0% 2017 operation sequences ---\n", " Iterative MLGST Total Time: 74.5s\n", "-- Std Practice: Iter 2 of 2 (CPTP) --: \n", " --- Iterative MLGST: [##################################################] 100.0% 2017 operation sequences ---\n", " Iterative MLGST Total Time: 986.8s\n" ] } ], "source": [ "#Run qutrit GST... which could take a while on a single CPU. Please adjust memLimit to machine specs \n", "# (now 3GB; usually set to slightly less than the total machine memory)\n", "result = pygsti.run_stdpractice_gst(DS,target_model,fiducialPrep,fiducialMeasure,germs,maxLengths,\n", " verbosity=2, comm=None, memLimit=3*(1024)**3, modes=\"TP,CPTP\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running idle tomography\n", "Computing switchable properties\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/Users/enielse/pyGSTi/pygsti/report/factory.py:1236: UserWarning:\n", "\n", "Idle tomography failed:\n", "operands could not be broadcast together with shapes (9,) (16,) \n", "\n" ] } ], "source": [ "#Create a report\n", "ws = pygsti.report.construct_standard_report(\n", " result, \"Example Qutrit Report\", verbosity=3\n", ").write_html('example_files/sampleQutritReport', auto_open=True, verbosity=3)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Qutrit basis (dim=9), 9 elements of shape (3, 3) :\n", "II, X+Y, X-Y, YZ, IX, IY, IZ, XY, XZ\n" ] } ], "source": [ "print(target_model.basis)" ] } ], "metadata": { "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.7.0" } }, "nbformat": 4, "nbformat_minor": 1 }