{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Robust Phase Estimation (RPE) Tutorial\n", "This notebook demonstrates how to use Robust Phase Estimation (RPE) to estimate certain parameters of a standard single-qubit gate set. The RPE protocol is contained within the `extras` package of pyGSTi." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Fully specified RPE configuration.\n" ] } ], "source": [ "#Import relevant namespaces.\n", "from __future__ import print_function\n", "\n", "import pygsti\n", "import pygsti.construction.std1Q_XY as Std1Q_XY\n", "from pygsti.extras import rpe\n", "\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Declare the particular RPE instance we are interested in\n", "#(X and Y pi/2 rotations)\n", "rpeconfig_inst = rpe.rpeconfig_GxPi2_GyPi2_UpDn" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#Declare a variety of relevant parameters\n", "\n", "gs_target = Std1Q_XY.gs_target\n", "gs_target.set_all_parameterizations('TP')\n", "maxLengths_1024 = [0,1,2,4,8,16,32,64,128,256,512,1024]\n", "\n", "stringListsRPE = rpe.rpeconstruction.make_rpe_angle_string_list_dict(10,rpeconfig_inst)\n", "\n", "angleList = ['alpha','epsilon','theta']\n", "\n", "numStrsD = {}\n", "numStrsD['RPE'] = [6*i for i in np.arange(1,12)]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Create noisy gateset\n", "gs_real = gs_target.randomize_with_unitary(.01,seed=0)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Extract noisy gateset angles\n", "true_alpha = rpe.extract_alpha(gs_real,rpeconfig_inst)\n", "true_epsilon = rpe.extract_epsilon(gs_real,rpeconfig_inst)\n", "true_theta = rpe.extract_theta(gs_real,rpeconfig_inst)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Simulate dataset\n", "N=100\n", "DS = pygsti.construction.generate_fake_data(gs_real,stringListsRPE['totalStrList'],N,sampleError='binomial',seed=1)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#Analyze dataset\n", "resultsRPE = rpe.analyze_rpe_data(DS,gs_real,stringListsRPE,rpeconfig_inst)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "alpha_true - pi/2 = 0.0279649415513\n", "epsilon_true - pi/2 = 0.00671591123378\n", "theta_true = 0.0233041210479\n", "\n", "alpha_true - alpha_est_final = 1.83008894992e-05\n", "epsilon_true - epsilon_est_final = 6.16866596674e-05\n", "theta_true - theta_est_final = 0.0120789343601\n" ] } ], "source": [ "#Print results\n", "print('alpha_true - pi/2 =',true_alpha-np.pi/2)\n", "print('epsilon_true - pi/2 =',true_epsilon-np.pi/2)\n", "print('theta_true =',true_theta)\n", "print()\n", "print('alpha_true - alpha_est_final =',resultsRPE['alphaErrorList'][-1])\n", "print('epsilon_true - epsilon_est_final =',resultsRPE['epsilonErrorList'][-1])\n", "print('theta_true - theta_est_final =',resultsRPE['thetaErrorList'][-1])" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }