Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Feature propagatable error gens #435

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
190 changes: 190 additions & 0 deletions jupyter_notebooks/Examples/Propagatable error gens tutorial.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from pygsti.extras.errorgenpropagation.propagatableerrorgen import *\n",
"from pygsti.extras.errorgenpropagation.errorpropagator import *\n",
"from pygsti.circuits import Circuit\n",
"import numpy as np\n",
"import pygsti.processors\n",
"import pygsti\n",
"import pygsti.tools.lindbladtools as _lt\n",
"import scipy\n",
"import matplotlib.pyplot as plt"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction to the Propagatable Error Generators Code"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining a circuit and error generators"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Currently Error Propgagation works for any model that meets three criteria\n",
"\n",
" 1. The circuit is clifford\n",
" 2. The errors on each gate can be defined at a time t of interest in the small markovian errors basis\n",
" 3. The error error model is defined such that a gate G has some linear combination of error generators following it\n",
"\n",
"We can therefore, start a code by defining a circuit and an error model by simply following the common pyGSTi notation"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"errorModel={\n",
" 'Gxpi2' : {('H','Y'):.01}\n",
"\n",
"}\n",
"c=Circuit(10*[('Gxpi2',0)])"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we can take the above definitions and plug them into the errorpropagator function, to get out a list of post-circuit error generators out."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"errors=ErrorPropagator(c,errorModel,BCHOrder=1,BCHLayerwise=False,NonMarkovian=False)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Here BCH order determines the to what order the BCH order will be taken to (if applicable). BCHLayerwise will if false, propagatate all errors to the end before taking the BCH expansion, otherwise it will push the errorgens through a layer and combine with the the error generators for that layer by the rules given by the BCHOrder. Non-markovian prevents any simplification or BCH expansions being taken, instead allowing the output to be a list a lists, where the each sublist denotes the errorgenerators that were occuring at time t in the circuit."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Additionally, if you want to describe a gate with multiple associated error definitions you can define it as follows."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('H', ('X',), (0.09999999999999999+0j))]"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"MultiGateDict={'Gxpi22' : 'Gxpi2'}\n",
"errorModel={\n",
" 'Gxpi2' : {('H','Y'):.01},\n",
" 'Gxpi22' : {('H','X'):.01}\n",
"\n",
"}\n",
"c=Circuit(10*[('Gxpi2',0),('Gxpi22',0)])\n",
"\n",
"ErrorPropagator(c,errorModel,MultiGateDict=MultiGateDict, MultiGate=True)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Once the errors are propagated to the process matrix given by the end of circuit error generators is given by"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"expMat=np.zeros([4**len(c.line_labels),4**len(c.line_labels)],dtype=np.complex128)\n",
"for error in errors:\n",
" expMat +=error.toWeightedErrorBasisMatrix()\n",
"processMatrix = scipy.linalg.expm(expMat)"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Non-Markovianity"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"If you want to use the non markovianity function you need to define an n x n correlation where n is the number of layers."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "PyGSTi_EOC",
"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.11.4"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
53 changes: 53 additions & 0 deletions pygsti/circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3644,6 +3644,59 @@ def _write_q_circuit_tex(self, filename): # TODO
f.write("\\end{document}")
f.close()


def convert_to_stim_tableau_layers(self,gate_name_conversions=None):
"""
Converts this circuit to a list of stim tableau layers

Parameters
----------
gate_name_conversions : Dict
A map from pygsti gatenames to standard stim tableaus. If set to None a standard set of gate names is used

Returns
-------
A layer by layer list of stim tabluaes
"""
try:
import stim
except ImportError:
raise ImportError("Stim is required for this operation, and it does not appear to be installed.")
if gate_name_conversions is None:
gate_name_conversions = _itgs.standard_gatenames_stim_conversions()

qubits=len(self.line_labels)
stim_layers=[]
for j in range(self.depth):
layer = self.layer(j)
stim_layer=stim.Tableau(qubits)
for sub_lbl in layer:
temp = gate_name_conversions[sub_lbl.name]
stim_layer.append(temp,sub_lbl.qubits)
stim_layers.append(stim_layer)
return stim_layers

def convert_to_stim_tableau(self,gate_name_conversions=None):
"""
Converts this circuit to a stim tableu

Parameters
----------
gate_name_conversions : Dict
A map from pygsti gatenames to standard stim tableaus. If set to None a standard set of gate names is used

Returns
-------
A single stim tableu representing the entire circuit
"""
layers=self.convert_to_stim_tableau_layers(gate_name_conversions)
tableu=layers.pop(0)
for layer in layers:
tableu=tableu*layer
return tableu



def convert_to_cirq(self,
qubit_conversion,
wait_duration=None,
Expand Down
Loading
Loading