{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Leakage characterization using GST\n", "This tutorial demonstrates how to perform GST on a \"leaky-qubit\" described by a 3-level (instead of the desired 2-level) system. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pygsti\n", "import pygsti.modelpacks.legacy.std1Q_XYI as std1Q\n", "import numpy as np\n", "import scipy.linalg as sla\n", "#import pickle" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def to_3level_unitary(U_2level):\n", " U_3level = np.zeros((3,3),complex)\n", " U_3level[0:2,0:2] = U_2level\n", " U_3level[2,2] = 1.0\n", " return U_3level\n", "\n", "def unitary_to_gmgate(U):\n", " return pygsti.tools.change_basis( \n", " pygsti.tools.unitary_to_std_process_mx(U), 'std','gm')\n", "\n", "def state_to_gmvec(state):\n", " pygsti.tools.stdmx_to_gmvec\n", "\n", "Us = pygsti.tools.internalgates.standard_gatename_unitaries()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "mdl_2level_ideal = std1Q.target_model()\n", "mdl_2level_ideal.sim = \"matrix\" # so we can create reports later on" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "rho0 = np.array( [[1,0,0],\n", " [0,0,0],\n", " [0,0,0]], complex)\n", "E0 = rho0\n", "E1 = np.array( [[0,0,0],\n", " [0,1,0],\n", " [0,0,1]], complex)\n", "\n", "sslbls = pygsti.baseobjs.ExplicitStateSpace(['Qubit+Leakage'],[3])\n", "mdl_3level_ideal = pygsti.models.ExplicitOpModel(sslbls, 'gm')\n", "mdl_3level_ideal['rho0'] = pygsti.tools.stdmx_to_gmvec(rho0)\n", "mdl_3level_ideal['Mdefault'] = pygsti.modelmembers.povms.TPPOVM([('0',pygsti.tools.stdmx_to_gmvec(E0)),\n", " ('1',pygsti.tools.stdmx_to_gmvec(E1))],\n", " evotype='default')\n", "\n", "mdl_3level_ideal['Gi'] = unitary_to_gmgate( to_3level_unitary(Us['Gi']))\n", "mdl_3level_ideal['Gx'] = unitary_to_gmgate( to_3level_unitary(Us['Gxpi2']))\n", "mdl_3level_ideal['Gy'] = unitary_to_gmgate( to_3level_unitary(Us['Gypi2']))\n", "mdl_3level_ideal.sim = \"matrix\" # so we can create reports later on" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "sigmaX = np.array([[0,1],[1,0]],complex)\n", "rot = sla.expm(1j * 0.1 * sigmaX)\n", "Uleakage = np.identity(3,complex)\n", "Uleakage[1:3,1:3] = rot\n", "leakageOp = unitary_to_gmgate(Uleakage)\n", "#print(Uleakage)\n", "\n", "#Guess of a model w/just unitary leakage\n", "mdl_3level_guess = mdl_3level_ideal.copy()\n", "mdl_3level_guess['Gi'] = np.dot(leakageOp, mdl_3level_guess['Gi'])\n", "#mdl_3level_guess['Gx'] = np.dot(leakageOp, mdl_3level_guess['Gx'])\n", "#mdl_3level_guess['Gy'] = np.dot(leakageOp, mdl_3level_guess['Gy'])\n", "\n", "#Actual model used for data generation (some depolarization too)\n", "mdl_3level_noisy = mdl_3level_ideal.depolarize(op_noise=0.005, spam_noise=0.01)\n", "mdl_3level_noisy['Gi'] = np.dot(leakageOp, mdl_3level_noisy['Gi'])\n", "#mdl_3level_noisy['Gx'] = np.dot(leakageOp, mdl_3level_noisy['Gx'])\n", "#mdl_3level_noisy['Gy'] = np.dot(leakageOp, mdl_3level_noisy['Gy'])" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#print(mdl_3level_guess)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Initial Length Available Fiducial List: 121\n", " Creating cache of fiducial process matrices.\n", " Completed cache of fiducial process matrices.\n", "Length Available Fiducial List Dropped Identities and Duplicates: 111\n", "Using GRASP algorithm.\n", "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", "Starting fiducial list optimization. Lower score is better.\n", "Starting iteration 1 of 5.\n", "Initial construction:\n", "['{}', 'GxGxGx', 'GiGiGiGy', 'GxGyGy', 'GxGiGiGi', 'GxGxGyGi', 'GiGyGxGi', 'GyGiGyGx', 'GyGiGyGi', 'GxGiGyGx']\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ciostro\\Documents\\pyGSTi_leakage_models\\pygsti\\algorithms\\fiducialselection.py:156: UserWarning: max_fid_length is now deprecated and will be replaced by the kwarg candidate_fid_counts. See documentation for how to achieve the old behavior with the new kwarg.\n", " warn('max_fid_length is now deprecated and will be replaced by the kwarg candidate_fid_counts. See documentation for how to achieve the old behavior with the new kwarg.')\n", "C:\\Users\\ciostro\\Documents\\pyGSTi_leakage_models\\pygsti\\algorithms\\fiducialselection.py:158: UserWarning: Specifying max_fid_length without setting candidate_fid_counts results the settings specified in candidate_fid_counts being overridden. candidate_fid_counts is set by defaults, so this might be expected, but if this is not the desired behavior then please verify your arguments.\n", " warn('Specifying max_fid_length without setting candidate_fid_counts results the settings specified in candidate_fid_counts being overridden.\\\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Local optimum:\n", "['{}', 'GxGi', 'GyGi', 'GyGy', 'GiGxGi', 'GxGxGi', 'GxGiGiGi', 'GxGiGyGy', 'GyGiGiGi', 'GyGiGxGx']\n", "Finished iteration 1 of 5.\n", "Starting iteration 2 of 5.\n", "Initial construction:\n", "['{}', 'GyGiGxGy', 'GiGyGyGx', 'GiGyGx', 'GxGxGxGi', 'GiGyGy', 'GxGiGiGy', 'GxGiGy', 'GxGxGi']\n", "Local optimum:\n", "['{}', 'GxGi', 'GxGx', 'GyGi', 'GxGxGi', 'GxGiGiGi', 'GxGiGyGy', 'GyGiGiGi', 'GyGiGxGx']\n", "Finished iteration 2 of 5.\n", "Starting iteration 3 of 5.\n", "Initial construction:\n", "['{}', 'GyGiGiGy', 'GiGiGyGy', 'GiGiGiGx', 'GyGiGyGy', 'GxGyGiGy', 'GyGiGyGi', 'GxGyGi', 'GxGiGyGi', 'GyGyGyGx']\n", "Local optimum:\n", "['{}', 'GxGi', 'GyGi', 'GyGy', 'GiGxGi', 'GxGxGi', 'GxGiGiGi', 'GxGiGyGy', 'GyGiGiGi', 'GyGiGxGx']\n", "Finished iteration 3 of 5.\n", "Starting iteration 4 of 5.\n", "Initial construction:\n", "['{}', 'GiGyGiGy', 'GxGyGyGy', 'GiGy', 'GyGiGiGy', 'GxGiGxGy', 'GiGiGxGx', 'GyGiGiGx', 'GiGxGiGy', 'GxGiGi']\n", "Local optimum:\n", "['{}', 'GxGi', 'GyGi', 'GyGy', 'GiGxGi', 'GxGxGi', 'GxGiGiGi', 'GxGiGyGy', 'GyGiGiGi', 'GyGiGxGx']\n", "Finished iteration 4 of 5.\n", "Starting iteration 5 of 5.\n", "Initial construction:\n", "['{}', 'GxGiGyGy', 'GiGiGxGx', 'GyGiGi', 'GyGxGxGx', 'GxGxGxGi', 'GyGxGi', 'GyGiGiGx', 'GxGyGiGi']\n", "Local optimum:\n", "['{}', 'GxGi', 'GxGx', 'GyGi', 'GxGxGi', 'GxGiGiGi', 'GxGiGyGy', 'GyGiGiGi', 'GyGiGxGx']\n", "Finished iteration 5 of 5.\n", "Preparation fiducials:\n", "['{}', 'GxGi', 'GyGi', 'GyGy', 'GiGxGi', 'GxGxGi', 'GxGiGiGi', 'GxGiGyGy', 'GyGiGiGi', 'GyGiGxGx']\n", "Score: 29172.54075249312\n", "Complete initial fiducial set succeeds.\n", "Now searching for best fiducial set.\n", "Starting fiducial list optimization. Lower score is better.\n", "Starting iteration 1 of 5.\n", "Initial construction:\n", "['{}', 'GxGxGiGi', 'GxGxGiGx', 'GxGiGxGx', 'GxGy', 'GyGiGiGx', 'GiGiGy', 'GxGiGiGx', 'GyGxGiGi', 'GiGxGiGy']\n", "Local optimum:\n", "['{}', 'GiGx', 'GiGy', 'GyGy', 'GiGyGx', 'GiGyGy', 'GiGiGiGx', 'GiGiGiGy', 'GxGxGiGy', 'GyGyGiGx']\n", "Finished iteration 1 of 5.\n", "Starting iteration 2 of 5.\n", "Initial construction:\n", "['{}', 'GyGiGiGy', 'GyGiGyGx', 'GxGyGxGi', 'GxGiGxGi', 'GiGyGi', 'GxGy', 'GyGxGi', 'GiGyGy', 'GiGyGiGx']\n", "Local optimum:\n", "['{}', 'GiGx', 'GiGy', 'GyGy', 'GiGyGx', 'GiGyGy', 'GiGiGiGx', 'GiGiGiGy', 'GxGxGiGy', 'GyGyGiGx']\n", "Finished iteration 2 of 5.\n", "Starting iteration 3 of 5.\n", "Initial construction:\n", "['{}', 'GyGyGy', 'GxGiGiGy', 'GxGxGxGi', 'GxGx', 'GxGiGx', 'GiGiGyGy', 'GiGyGi', 'GiGxGxGi', 'GxGyGiGy']\n", "Local optimum:\n", "['{}', 'GiGx', 'GiGy', 'GyGy', 'GiGyGx', 'GiGyGy', 'GiGiGiGx', 'GiGiGiGy', 'GxGxGiGy', 'GyGyGiGx']\n", "Finished iteration 3 of 5.\n", "Starting iteration 4 of 5.\n", "Initial construction:\n", "['{}', 'GxGxGxGy', 'GiGx', 'GxGxGiGy', 'GyGyGiGy', 'GxGiGyGy', 'GiGxGiGy', 'GiGxGiGx', 'GyGxGiGx', 'Gx', 'GiGiGiGx']\n", "Local optimum:\n", "['{}', 'GiGx', 'GiGy', 'GyGy', 'GiGxGy', 'GiGyGx', 'GiGiGiGx', 'GiGiGiGy', 'GxGiGiGx', 'GxGxGiGy', 'GyGyGiGx']\n", "Finished iteration 4 of 5.\n", "Starting iteration 5 of 5.\n", "Initial construction:\n", "['{}', 'GxGyGyGy', 'GxGxGx', 'GxGyGi', 'GxGyGiGx', 'GxGiGyGy', 'GyGiGx', 'GxGiGiGy', 'GiGiGxGx', 'GiGx']\n", "Local optimum:\n", "['{}', 'GiGx', 'GiGy', 'GyGy', 'GiGyGx', 'GiGyGy', 'GiGiGiGx', 'GiGiGiGy', 'GxGxGiGy', 'GyGyGiGx']\n", "Finished iteration 5 of 5.\n", "Measurement fiducials:\n", "['{}', 'GiGx', 'GiGy', 'GyGy', 'GiGxGy', 'GiGyGx', 'GiGiGiGx', 'GiGiGiGy', 'GxGiGiGx', 'GxGxGiGy', 'GyGyGiGx']\n", "Score: 26690.426232238056\n" ] } ], "source": [ "# get sequences using expected model\n", "find_fiducials = True\n", "\n", "if find_fiducials:\n", " prepfids, measfids = pygsti.algorithms.find_fiducials(\n", " mdl_3level_guess, omit_identity=False, max_fid_length=4, verbosity=4)\n", " pygsti.io.write_circuit_list(\"example_files/leakage_prepfids.txt\", prepfids)\n", " pygsti.io.write_circuit_list(\"example_files/leakage_measfids.txt\", measfids)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# If files missing, run previous cell at least once with find_fiducials = True\n", "prepfids = pygsti.io.read_circuit_list(\"example_files/leakage_prepfids.txt\")\n", "measfids = pygsti.io.read_circuit_list(\"example_files/leakage_measfids.txt\")\n", "germs = std1Q.germs\n", "maxLengths = [1,]\n", "expList = pygsti.circuits.create_lsgst_circuits(mdl_3level_noisy, prepfids, measfids, germs, maxLengths)\n", "ds = pygsti.data.simulate_data(mdl_3level_noisy, expList, 1000, 'binomial', seed=1234)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- Circuit Creation ---\n", " 405 circuits created\n", " Dataset has 405 entries: 405 utilized, 0 requested circuits were missing\n", "-- Std Practice: Iter 1 of 1 (CPTP) --: \n", " --- Iterative GST: Iter 1 of 1 405 circuits ---: \n", " MatrixLayout: 1 processors divided into 1 x 1 (= 1) grid along circuit and parameter directions.\n", " 1 atoms, parameter block size limits (None,)\n", " *** Distributing 1 atoms to 1 atom-processing groups (1 cores) ***\n", " More atom-processors than hosts: each host gets ~1 atom-processors\n", " Atom-processors already occupy a single node, dividing atom-processor into 1 param-processors.\n", " *** Divided 1-host atom-processor (~1 procs) into 1 param-processing groups ***\n", " --- chi2 GST ---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ciostro\\Documents\\pyGSTi_leakage_models\\pygsti\\modelmembers\\operations\\lindbladerrorgen.py:1691: UserWarning: Using 'CPTP' as a Lindblad type is deprecated, and you should now use 'CPTPLND'\n", " _warnings.warn(\"Using 'CPTP' as a Lindblad type is deprecated, and you should now use 'CPTPLND'\")\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " Sum of Chi^2 = 1008.76 (405 data params - 60 (approx) model params = expected mean of 345; p-value = 0)\n", " Completed in 2.2s\n", " Iteration 1 took 2.3s\n", " \n", " Last iteration:\n", " --- dlogl GST ---\n", " 2*Delta(log(L)) = 1005.93 (405 data params - 60 (approx) model params = expected mean of 345; p-value = 0)\n", " Completed in 0.8s\n", " Final optimization took 0.8s\n", " \n", " Iterative GST Total Time: 3.1s\n" ] } ], "source": [ "results_2level = pygsti.run_stdpractice_gst(ds, mdl_2level_ideal, prepfids, measfids,\n", " germs, maxLengths, modes=\"CPTP\", verbosity=3)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- Circuit Creation ---\n", " 405 circuits created\n", " Dataset has 405 entries: 405 utilized, 0 requested circuits were missing\n", "-- Std Practice: Iter 1 of 2 (CPTP) --: \n", " --- Iterative GST: Iter 1 of 1 405 circuits ---: \n", " MatrixLayout: 1 processors divided into 1 x 1 (= 1) grid along circuit and parameter directions.\n", " 1 atoms, parameter block size limits (None,)\n", " *** Distributing 1 atoms to 1 atom-processing groups (1 cores) ***\n", " More atom-processors than hosts: each host gets ~1 atom-processors\n", " Atom-processors already occupy a single node, dividing atom-processor into 1 param-processors.\n", " *** Divided 1-host atom-processor (~1 procs) into 1 param-processing groups ***\n", " --- chi2 GST ---\n", " --- Outer Iter 0: norm_f = 2.24844e+06, mu=1, |x|=0, |J|=2669.67\n", " --- Outer Iter 1: norm_f = 50510.8, mu=558.747, |x|=0.0836338, |J|=14210.9\n", " --- Outer Iter 2: norm_f = 6531.22, mu=269.742, |x|=0.380777, |J|=2579.83\n", " --- Outer Iter 3: norm_f = 2507.43, mu=260.908, |x|=0.337193, |J|=2713.33\n", " --- Outer Iter 4: norm_f = 651.681, mu=160.258, |x|=0.295065, |J|=2785.57\n", " --- Outer Iter 5: norm_f = 469.941, mu=158.928, |x|=0.317773, |J|=2807.07\n", " --- Outer Iter 6: norm_f = 426.669, mu=325.082, |x|=0.330061, |J|=2835.49\n", " --- Outer Iter 7: norm_f = 380.449, mu=322.234, |x|=0.345577, |J|=2849.75\n", " --- Outer Iter 8: norm_f = 365.348, mu=644.469, |x|=0.35402, |J|=2859.56\n", " --- Outer Iter 9: norm_f = 354.285, mu=563.744, |x|=0.362779, |J|=2867.96\n", " Least squares message = Both actual and predicted relative reductions in the sum of squares are at most 0.01\n", " Sum of Chi^2 = 354.285 (405 data params - 360 (approx) model params = expected mean of 45; p-value = 0)\n", " Completed in 7.8s\n", " Iteration 1 took 7.9s\n", " \n", " Last iteration:\n", " --- dlogl GST ---\n", " --- Outer Iter 0: norm_f = 181.529, mu=1, |x|=0.362779, |J|=2030.72\n", " --- Outer Iter 1: norm_f = 178.198, mu=295.821, |x|=0.367274, |J|=2034.86\n", " Least squares message = Both actual and predicted relative reductions in the sum of squares are at most 0.01\n", " 2*Delta(log(L)) = 356.396 (405 data params - 360 (approx) model params = expected mean of 45; p-value = 0)\n", " Completed in 2.6s\n", " Final optimization took 2.6s\n", " \n", " Iterative GST Total Time: 10.5s\n", " -- Performing 'stdgaugeopt' gauge optimization on CPTP estimate --\n", "-- Std Practice: Iter 2 of 2 (True) --: \n", " MatrixLayout: 1 processors divided into 1 (= 1) grid along circuit and parameter directions.\n", " 1 atoms, parameter block size limits ()\n", " *** Distributing 1 atoms to 1 atom-processing groups (1 cores) ***\n", " More atom-processors than hosts: each host gets ~1 atom-processors\n", " -- Performing 'stdgaugeopt' gauge optimization on True estimate --\n" ] } ], "source": [ "results_3level = pygsti.run_stdpractice_gst(ds, mdl_3level_ideal, prepfids, measfids,\n", " germs, maxLengths, modes=\"CPTP,True\",\n", " models_to_test={'True': mdl_3level_noisy}, \n", " verbosity=4, advanced_options={'all': {'tolerance': 1e-2}})" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running idle tomography\n", "Computing switchable properties\n", "Found standard clifford compilation from std1Q_XYI\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n" ] } ], "source": [ "pygsti.report.construct_standard_report(\n", " {'two-level': results_2level, 'three-level': results_3level},\n", " \"Leakage Example Report\"\n", ").write_html('example_files/leakage_report')" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "#try a different basis:\n", "gm_basis = pygsti.baseobjs.Basis.cast('gm',9)\n", " \n", "leakage_basis_mxs = [ np.sqrt(2)/3*(np.sqrt(3)*gm_basis[0] + 0.5*np.sqrt(6)*gm_basis[8]),\n", " gm_basis[1], gm_basis[4], gm_basis[7],\n", " gm_basis[2], gm_basis[3], gm_basis[5], gm_basis[6],\n", " 1/3*(np.sqrt(3)*gm_basis[0] - np.sqrt(6)*gm_basis[8]) ]\n", "#for mx in leakage_basis_mxs:\n", "# pygsti.tools.print_mx(mx)\n", "\n", "check = np.zeros( (9,9), complex)\n", "for i,m1 in enumerate(leakage_basis_mxs):\n", " for j,m2 in enumerate(leakage_basis_mxs):\n", " check[i,j] = np.trace(np.dot(m1,m2))\n", "assert(np.allclose(check, np.identity(9,complex)))\n", "\n", "leakage_basis = pygsti.baseobjs.ExplicitBasis(leakage_basis_mxs, name=\"LeakageBasis\", \n", " longname=\"2+1 level leakage basis\", real=True,\n", " labels=['I','X','Y','Z','LX0','LX1','LY0','LY1','L'])\n", "\n", "def changebasis_3level_model(mdl):\n", " new_mdl = mdl.copy()\n", " new_mdl.preps['rho0'] = pygsti.modelmembers.states.FullState(\n", " pygsti.tools.change_basis(mdl.preps['rho0'].to_dense(), gm_basis, leakage_basis))\n", " new_mdl.povms['Mdefault'] = pygsti.modelmembers.povms.UnconstrainedPOVM(\n", " [('0', pygsti.tools.change_basis(mdl.povms['Mdefault']['0'].to_dense(), gm_basis, leakage_basis)),\n", " ('1', pygsti.tools.change_basis(mdl.povms['Mdefault']['1'].to_dense(), gm_basis, leakage_basis))],\n", " evotype='default')\n", " \n", " for lbl,op in mdl.operations.items():\n", " new_mdl.operations[lbl] = pygsti.modelmembers.operations.FullArbitraryOp(\n", " pygsti.tools.change_basis(op.to_dense(), gm_basis, leakage_basis))\n", " new_mdl.basis = leakage_basis\n", " return new_mdl\n", "\n", "def changebasis_3level_results(results):\n", " new_results = results.copy()\n", " for estlbl,est in results.estimates.items():\n", " for mlbl,mdl in est.models.items():\n", " if isinstance(mdl,(list,tuple)): #assume a list/tuple of models\n", " new_results.estimates[estlbl].models[mlbl] = \\\n", " [ changebasis_3level_model(m) for m in mdl ]\n", " else:\n", " new_results.estimates[estlbl].models[mlbl] = changebasis_3level_model(mdl)\n", " return new_results\n", " " ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "results_3level_leakage_basis = changebasis_3level_results( results_3level ) " ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running idle tomography\n", "Computing switchable properties\n", "Found standard clifford compilation from std1Q_XYI\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ciostro\\Documents\\pyGSTi_leakage_models\\pygsti\\report\\factory.py:1277: UserWarning:\n", "\n", "Idle tomography failed:\n", "operands could not be broadcast together with shapes (9,) (16,) \n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n" ] } ], "source": [ "pygsti.report.construct_standard_report(\n", " {'two-level': results_2level, 'three-level': results_3level_leakage_basis},\n", " \"Leakage Example Report\"\n", ").write_html('example_files/leakage_report')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Open the report [here](example_files/leakage_report/main.html)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "# use \"kite\" density-matrix structure\n", "def to_2plus1_superop(superop_2level):\n", " ret = np.zeros((5,5),'d')\n", " ret[0:4,0:4] = superop_2level.to_dense()\n", " ret[4,4] = 1.0 #leave leakage population where it is\n", " return ret\n", "\n", "#Tack on a single extra \"0\" for the 5-th dimension corresponding\n", "# to the classical leakage level population.\n", "eps = 0.01 # ideally zero, a smallish number to seed the GST optimiation away from 0-leakage so it doesn't get stuck there.\n", "rho0 = np.concatenate( (mdl_2level_ideal.preps['rho0'].to_dense(),[eps]), axis=0)\n", "E0 = np.concatenate( (mdl_2level_ideal.povms['Mdefault']['0'].to_dense(),[eps]), axis=0)\n", "E1 = np.concatenate( (mdl_2level_ideal.povms['Mdefault']['1'].to_dense(),[eps]), axis=0)\n", "\n", "\n", "statespace = pygsti.baseobjs.ExplicitStateSpace([('Qubit',),('Leakage',)],[(2,),(1,)])\n", "mdl_2plus1_ideal = pygsti.models.ExplicitOpModel(statespace, 'gm')\n", "mdl_2plus1_ideal['rho0'] = rho0\n", "mdl_2plus1_ideal['Mdefault'] = pygsti.modelmembers.povms.UnconstrainedPOVM([('0',E0),('1',E1)],\n", " evotype='default', state_space=statespace)\n", "\n", "mdl_2plus1_ideal['Gi'] = to_2plus1_superop(mdl_2level_ideal['Gi'])\n", "mdl_2plus1_ideal['Gx'] = to_2plus1_superop(mdl_2level_ideal['Gx'])\n", "mdl_2plus1_ideal['Gy'] = to_2plus1_superop(mdl_2level_ideal['Gy'])" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--- Circuit Creation ---\n", " 405 circuits created\n", " Dataset has 405 entries: 405 utilized, 0 requested circuits were missing\n", "--- Iterative GST: Iter 1 of 1 405 circuits ---: \n", " MatrixLayout: 1 processors divided into 1 x 1 (= 1) grid along circuit and parameter directions.\n", " 1 atoms, parameter block size limits (None,)\n", " *** Distributing 1 atoms to 1 atom-processing groups (1 cores) ***\n", " More atom-processors than hosts: each host gets ~1 atom-processors\n", " Atom-processors already occupy a single node, dividing atom-processor into 1 param-processors.\n", " *** Divided 1-host atom-processor (~1 procs) into 1 param-processing groups ***\n", " --- chi2 GST ---\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ciostro\\Documents\\pyGSTi_leakage_models\\pygsti\\protocols\\gst.py:288: UserWarning:\n", "\n", "Given model failed to create a processor spec for StdGST experiment design!\n", "\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " Sum of Chi^2 = 432.105 (405 data params - 90 (approx) model params = expected mean of 315; p-value = 1.2584e-05)\n", " Completed in 2.9s\n", " Iteration 1 took 3.0s\n", " \n", " Last iteration:\n", " --- dlogl GST ---\n", " 2*Delta(log(L)) = 439.682 (405 data params - 90 (approx) model params = expected mean of 315; p-value = 4.15511e-06)\n", " Completed in 0.7s\n", " Final optimization took 0.7s\n", " \n", "Iterative GST Total Time: 3.7s\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\ciostro\\Documents\\pyGSTi_leakage_models\\pygsti\\algorithms\\gaugeopt.py:275: UserWarning:\n", "\n", "No gauge group specified, so no gauge optimization performed.\n", "\n" ] } ], "source": [ "mdl_2plus1_ideal.sim = \"matrix\" # so we can construct report below\n", "results_2plus1 = pygsti.run_long_sequence_gst(ds, mdl_2plus1_ideal, prepfids, measfids,\n", " germs, maxLengths, verbosity=2,\n", " advanced_options={\"starting_point\": \"target\",\n", " \"tolerance\": 1e-8, # (lowering tolerance from 1e-6 gave a better fit)\n", " \"estimate_label\": \"kite\"})" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "tags": [ "nbval-skip" ] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running idle tomography\n", "Computing switchable properties\n", "Found standard clifford compilation from std1Q_XYI\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n", "Statistical hypothesis tests did NOT find inconsistency between the data at 5.00% significance.\n" ] } ], "source": [ "pygsti.report.construct_standard_report(\n", " {'two-level': results_2level, 'three-level': results_3level_leakage_basis,\n", " 'two+one level': results_2plus1},\n", " \"Leakage Example Report\"\n", ").write_html('example_files/leakage_report', autosize='none')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Open the report [here](example_files/leakage_report/main.html)" ] } ], "metadata": { "kernelspec": { "display_name": "leakage_models", "language": "python", "name": "leakage_models" }, "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.9.13" } }, "nbformat": 4, "nbformat_minor": 4 }