{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Metrics in pyGSTi\n", "PyGSTi contains implementation of common ways to compare quantum processes and models. You may just want to `import pygsti` just for this functionality, as many of the functions below act on standard NumPy arrays. Here are some of the most common functions (this tutorial is under construction, and we plan to expand it in future releases. We apologize for it's current brevity.\n", "\n", "Let's begin by getting some gate (process) matrices for several simple 1-qubit operations. Note that `Gx`, `Gy` and `Gi` below are superoperator matrices in the Pauli basis - they're $4 \\times 4$ *real* matrices. We do this for a standard model (see the [standard module tutorial](../objects/advanced/StandardModules.ipynb)) and a version of this model with slightly rotated gates." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " 1.0000 0 0 0\n", " 0 1.0000 0 0\n", " 0 0 -0.0998 -0.9950\n", " 0 0 0.9950 -0.0998\n", "\n" ] } ], "source": [ "import pygsti.tools as tls\n", "import pygsti.report.reportables as rptbls\n", "from pygsti.construction import std1Q_XYI as std\n", "import numpy as np\n", "\n", "mdl = std.target_model()\n", "Gx = mdl['Gx'].todense()\n", "Gy = mdl['Gy'].todense()\n", "Gi = mdl['Gi'].todense()\n", "\n", "mdl_overrot = mdl.rotate( (0.1,0,0) )\n", "Gx_overrot = mdl_overrot['Gx'].todense()\n", "Gy_overrot = mdl_overrot['Gy'].todense()\n", "Gi_overrot = mdl_overrot['Gi'].todense()\n", "\n", "tls.print_mx(Gx_overrot)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Process matrix comparisons\n", "### Fidelities" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0024979173609871452" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.entanglement_infidelity(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0016652782406580968" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.avg_gate_infidelity(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0024979173609871452" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.eigenvalue_entanglement_infidelity(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0016652782406580968" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.eigenvalue_avg_gate_infidelity(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Diamond distance" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.04997916855345197" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.half_diamond_norm(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.07496875390601751" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.eigenvalue_diamondnorm(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Unitarity" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1.0000000000000002" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tls.unitarity(Gx_overrot)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Jamiolkowski trace distance" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.04997916927067833" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rptbls.jt_diff(Gx, Gx_overrot, 'pp')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## State comparisons\n", "\n", "### State fidelity" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.9" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rhoA = tls.ppvec_to_stdmx(mdl['rho0'].todense())\n", "rhoB = np.array( [ [0.9, 0],\n", " [ 0, 0.1]], complex)\n", "tls.fidelity(rhoA, rhoB)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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": 2 }