CITE THIS NOTEBOOK: Stabilizer formalism for quantum operations by Mads Bahrami. Wolfram Community DEC 14 2022.
In this short computational essay, I explore the stabilizer formalism, which is a powerful method to explore quantum operations, in particular the quantum error correction. I showed how some simple replacement rules and string functionalities in the Wolfram Language, make the calculations simple, without that much need for matric multiplication etc.
Install quantum framework
Install quantum framework
In[]:=
PacletInstall["https://wolfr.am/DevWQCF",ForceVersionInstall->True]<<Wolfram`QuantumFramework`
Out[]=
PacletObject
Pauli operators or Pauli strings
Pauli operators or Pauli strings
“Pauli operators” or “Pauli strings”: tensor products of Pauli matrices. For example:
One can generate them using Wolfram quantum framework, either directly or as quantum tensor product:
In[]:=
QuantumOperator["IZXY"]==QuantumTensorProduct[QuantumOperator/@Characters["IZXY"]]
Out[]=
True
Note the final matric representation of that operator is the same as Kronecker product of corresponding Pauli matrices:
In[]:=
QuantumOperator["IZXY"]["Matrix"]==KroneckerProduct@@PauliMatrix/@(Characters["IZXY"]/.{"I"->0,"X"->1,"Y"->2,"Z"->3})
Out[]=
True
Note we can have with a multiplicative factor of ±1 or ±i (for example, -XIYZ).
Stabilizer formalism
Stabilizer formalism
Stabilizer formalism is a powerful technique for model a wide range of quantum operations , in particular the quantum error-correction. There are many good references on this topic. In this essay, I used the followings:
https://www.scottaaronson.com/qclec/28.pdf
https://ochicken.top/Library/Physics/Topological_Insulators/Topological_Codes_and_Quantum_Computation/Part1.pdf
https://arxiv.org/pdf/quant-ph/0406196.pdf
https://arxiv.org/pdf/quant-ph/9807006.pdf
https://www.scottaaronson.com/qclec/28.pdf
https://ochicken.top/Library/Physics/Topological_Insulators/Topological_Codes_and_Quantum_Computation/Part1.pdf
https://arxiv.org/pdf/quant-ph/0406196.pdf
https://arxiv.org/pdf/quant-ph/9807006.pdf
Stabilizers are defined for a given state such that ψ=+ψ. In other words, the state ψ is stabilized by the operator .
Given ψ, the stabilizer group has the size Times@@QuantumState[...]["Dimensions"]. This means for only qubits, n-qubit state has a stabilizer group of the size
S
Given ψ, the stabilizer group has the size Times@@QuantumState[...]["Dimensions"]. This means for only qubits, n-qubit state has a stabilizer group of the size
n
2
Define a function that returns stabilizers of a given state:
In[]:=
[ψ_]:=KeyValueMap[If[#2==1,#1,StringDelete[ToString[Conjugate@#2],"1"]<>#1]&]@Select[With[{st=StringJoin@@@Tuples[{"I","X","Y","Z"},ψ["Qudits"]]},AssociationThread[st,ψ["Dagger"][#]["Number"]&/@Through[(QuantumOperator/@st)[ψ]]]],Abs[#]^2==1&]
Stabilizer group of :
|0〉
In[]:=
[QuantumState["0"]]
Out[]=
{I,Z}
Stabilizer group of :
(|0〉+|1〉)
2
In[]:=
[QuantumState["Plus"]]
Out[]=
{I,X}
Stabilizer group of :
(|00〉+|11〉)
2
In[]:=
[QuantumState["PhiPlus"]]
Out[]=
{II,XX,-YY,ZZ}
Stabilizer group of :
(|00〉-|11〉)
2
In[]:=
[QuantumState["PhiMinus"]]
Out[]=
{II,-XX,YY,ZZ}
Stabilizer group of :
(|000〉+|111〉)
2
In[]:=
[QuantumState["GHZ"]]
Out[]=
{III,IZZ,XXX,-XYY,-YXY,-YYX,ZIZ,ZZI}
The stabilizer formalism relies on the group theory. To define a group of operators, first we need to find their multiplication. The multiplication of Pauli operators/strings can be obtained without multiplying matrices and working with only strings and some replacement rules obtained from single-qubit Pauli operators.
Define a function that takes two Pauli operators/strings, and return their multiplication:
In[]:=
pauliStringMultiplier[s1_String,s2_String]/;Length[StringCases[s1,"X"|"Y"|"Z"|"I"]]==Length[StringCases[s2,"X"|"Y"|"Z"|"I"]]:=Module[{factor,multi},factor=StringCases[s1<>s2,""|"-"];multi=StringJoin[StringJoin@@@Transpose[{StringCases[s1,"X"|"Y"|"Z"|"I"],StringCases[s2,"X"|"Y"|"Z"|"I"]}]/.{x_String/;StringCount[x,"I"]==1:>StringDelete[x,"I"],"II"|"XX"|"YY"|"ZZ":>"I","XZ":>"-Y","ZX":>"Y","XY":>"Z","YX":>"-Z","YZ":>"X","ZY":>"-X"}];factor=StringDelete["1"]@StringReplace[{"-1":>"-","I":>""}]@ToString[Times@@KeyValueMap[#1^#2&]@Counts[Join[factor,StringCases[multi,""|"-"]]/.{"-":>-1,""->}]];factor<>StringDelete[multi,{"-",""}]]
For example:
In[]:=
pauliStringMultiplier["-XYZZ","IXYZ"]
Out[]=
XZXI
A list of Pauli strings forms a group under the operation of multiplication.
Test if a list of Pauli strings form a group or not
In[]:=
groupQ[group_]:=Sort[DeleteDuplicates[pauliStringMultiplier@@@Tuples[group,2]]]==Sort[group]
For example, let’s find all subgroups of operators stabilizing GHZ state:
In[]:=
Select[Subsets[[QuantumState["GHZ"]],{3,∞}],groupQ]
Out[]=
{{III,IZZ,XXX,-XYY},{III,IZZ,-YXY,-YYX},{III,IZZ,ZIZ,ZZI},{III,XXX,-YXY,ZIZ},{III,XXX,-YYX,ZZI},{III,-XYY,-YXY,ZZI},{III,-XYY,-YYX,ZIZ},{III,IZZ,XXX,-XYY,-YXY,-YYX,ZIZ,ZZI}}
The group of principal interest is the Pauli group.
Define Pauli group of n qubits:
In[]:=
[n_]:=Catenate@Outer[#1<>#2&,{"","-","","-"},StringJoin@@@Tuples[{"I","X","Y","Z"},n]]
For example, Pauli group of 3-qubits:
In[]:=
[3]
Out[]=
{III,IIX,IIY,IIZ,IXI,IXX,IXY,IXZ,IYI,IYX,IYY,IYZ,IZI,IZX,IZY,IZZ,XII,XIX,XIY,XIZ,XXI,XXX,XXY,XXZ,XYI,XYX,XYY,XYZ,XZI,XZX,XZY,XZZ,YII,YIX,YIY,YIZ,YXI,YXX,YXY,YXZ,YYI,YYX,YYY,YYZ,YZI,YZX,YZY,YZZ,ZII,ZIX,ZIY,ZIZ,ZXI,ZXX,ZXY,ZXZ,ZYI,ZYX,ZYY,ZYZ,ZZI,ZZX,ZZY,ZZZ,-III,-IIX,-IIY,-IIZ,-IXI,-IXX,-IXY,-IXZ,-IYI,-IYX,-IYY,-IYZ,-IZI,-IZX,-IZY,-IZZ,-XII,-XIX,-XIY,-XIZ,-XXI,-XXX,-XXY,-XXZ,-XYI,-XYX,-XYY,-XYZ,-XZI,-XZX,-XZY,-XZZ,-YII,-YIX,-YIY,-YIZ,-YXI,-YXX,-YXY,-YXZ,-YYI,-YYX,-YYY,-YYZ,-YZI,-YZX,-YZY,-YZZ,-ZII,-ZIX,-ZIY,-ZIZ,-ZXI,-ZXX,-ZXY,-ZXZ,-ZYI,-ZYX,-ZYY,-ZYZ,-ZZI,-ZZX,-ZZY,-ZZZ,III,IIX,IIY,IIZ,IXI,IXX,IXY,IXZ,IYI,IYX,IYY,IYZ,IZI,IZX,IZY,IZZ,XII,XIX,XIY,XIZ,XXI,XXX,XXY,XXZ,XYI,XYX,XYY,XYZ,XZI,XZX,XZY,XZZ,YII,YIX,YIY,YIZ,YXI,YXX,YXY,YXZ,YYI,YYX,YYY,YYZ,YZI,YZX,YZY,YZZ,ZII,ZIX,ZIY,ZIZ,ZXI,ZXX,ZXY,ZXZ,ZYI,ZYX,ZYY,ZYZ,ZZI,ZZX,ZZY,ZZZ,-III,-IIX,-IIY,-IIZ,-IXI,-IXX,-IXY,-IXZ,-IYI,-IYX,-IYY,-IYZ,-IZI,-IZX,-IZY,-IZZ,-XII,-XIX,-XIY,-XIZ,-XXI,-XXX,-XXY,-XXZ,-XYI,-XYX,-XYY,-XYZ,-XZI,-XZX,-XZY,-XZZ,-YII,-YIX,-YIY,-YIZ,-YXI,-YXX,-YXY,-YXZ,-YYI,-YYX,-YYY,-YYZ,-YZI,-YZX,-YZY,-YZZ,-ZII,-ZIX,-ZIY,-ZIZ,-ZXI,-ZXX,-ZXY,-ZXZ,-ZYI,-ZYX,-ZYY,-ZYZ,-ZZI,-ZZX,-ZZY,-ZZZ}
Note the total number of Pauli operators in is .
n
4×
n
4
Any two Pauli operators either commute or anti-commute. Additionally, a Pauli string/operator containing ± does not have +1 eigenvalue, so we focus on the subset with ± coefficients only. Additionally, we can use the following replacement rules on any Pauli string, to find the set of commuting operators or anti-commuting
I -> {I,X,Z}
X -> {I,X,-Z}
Y -> {I,-X,Y,-Z}
Z -> {I,-X,Z}
I -> {I,X,Z}
X -> {I,X,-Z}
Y -> {I,-X,Y,-Z}
Z -> {I,-X,Z}
The commuting set of a given Pauli string/operator will be the one with even number of -, while anti-commuting with odd number of -
For example, find set of all Pauli strings that commute with IXXZY (note, we do not show - signs, so all of below operators with - sign also commute with IXXZY)
In[]:=
StringDelete[Select[StringJoin@@@Tuples[Characters["IXXZY"]/.{"I"->{"I","X","Z"},"X"->{"I","X","-Z"},"Y"->{"I","-X","Y","-Z"},"Z"->{"I","-X","Z"}}],EvenQ[StringCount[#,"-"]]&],"-"]
Out[]=
{IIIII,IIIIY,IIIXX,IIIXZ,IIIZI,IIIZY,IIXII,IIXIY,IIXXX,IIXXZ,IIXZI,IIXZY,IIZIX,IIZIZ,IIZXI,IIZXY,IIZZX,IIZZZ,IXIII,IXIIY,IXIXX,IXIXZ,IXIZI,IXIZY,IXXII,IXXIY,IXXXX,IXXXZ,IXXZI,IXXZY,IXZIX,IXZIZ,IXZXI,IXZXY,IXZZX,IXZZZ,IZIIX,IZIIZ,IZIXI,IZIXY,IZIZX,IZIZZ,IZXIX,IZXIZ,IZXXI,IZXXY,IZXZX,IZXZZ,IZZII,IZZIY,IZZXX,IZZXZ,IZZZI,IZZZY,XIIII,XIIIY,XIIXX,XIIXZ,XIIZI,XIIZY,XIXII,XIXIY,XIXXX,XIXXZ,XIXZI,XIXZY,XIZIX,XIZIZ,XIZXI,XIZXY,XIZZX,XIZZZ,XXIII,XXIIY,XXIXX,XXIXZ,XXIZI,XXIZY,XXXII,XXXIY,XXXXX,XXXXZ,XXXZI,XXXZY,XXZIX,XXZIZ,XXZXI,XXZXY,XXZZX,XXZZZ,XZIIX,XZIIZ,XZIXI,XZIXY,XZIZX,XZIZZ,XZXIX,XZXIZ,XZXXI,XZXXY,XZXZX,XZXZZ,XZZII,XZZIY,XZZXX,XZZXZ,XZZZI,XZZZY,ZIIII,ZIIIY,ZIIXX,ZIIXZ,Z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IXY,XXIZX,XXIZZ,XXXIX,XXXIZ,XXXXI,XXXXY,XXXZX,XXXZZ,XXZII,XXZIY,XXZXX,XXZXZ,XXZZI,XXZZY,XZIII,XZIIY,XZIXX,XZIXZ,XZIZI,XZIZY,XZXII,XZXIY,XZXXX,XZXXZ,XZXZI,XZXZY,XZZIX,XZZIZ,XZZXI,XZZXY,XZZZX,XZZZZ,ZIIIX,ZIIIZ,ZIIXI,ZIIXY,ZIIZX,ZIIZZ,ZIXIX,ZIXIZ,ZIXXI,ZIXXY,ZIXZX,ZIXZZ,ZIZII,ZIZIY,ZIZXX,ZIZXZ,ZIZZI,ZIZZY,ZXIIX,ZXIIZ,ZXIXI,ZXIXY,ZXIZX,ZXIZZ,ZXXIX,ZXXIZ,ZXXXI,ZXXXY,ZXXZX,ZXXZZ,ZXZII,ZXZIY,ZXZXX,ZXZXZ,ZXZZI,ZXZZY,ZZIII,ZZIIY,ZZIXX,ZZIXZ,ZZIZI,ZZIZY,ZZXII,ZZXIY,ZZXXX,ZZXXZ,ZZXZI,ZZXZY,ZZZIX,ZZZIZ,ZZZXI,ZZZXY,ZZZZX,ZZZZZ}
Let us focus only on Pauli strings with + sign. Let us create a graph with vertices the Pauli strings and edges only if vertices commute
For example, commuting graph of 2-qubits:
Find all Abelian subgroups of 2-qubits with the min order of 4:
A function that returns the states defining the subspace spanned by positive eigenstate of an operator (a Pauli string)
Find the basis defined by the subspace that is spanned by the positive eigenstates of ZZI
Confirm that any linear combination of above states, c1 |000〉+c2 |001〉+c3 |110〉+c4 |111〉, is also a positive eigenstate of ZZI:
Find the states spanning the subspace defined by the stabilizers {III, ZZI, ZIZ, IZZ}
Given a Pauli string, one can rewrite it as a vector that can be created by joining two vectors, with the first vector generated by replacement rules as {“I”->0,”X”->1,”Y”->1,”Z”->0} and the 2nd one by {“I”->0,”X”->0,”Y”->1,”Z”->1}. So a Pauli string of n-letter will be a vector of 2n elements (where those elements can be 0,±1,±).
A function generating a vector as the check row of a given Pauli string:
Show that the rows are mutually independent, meaning all generators commute:
Another way of checking for commutation is using a 2n×2n matrix Λ as follows:
For example, for 7-qubit system, one gets:
If two operators commute, then Mod[row1.Λ.row2,2]) should be zero. Therefore, one can define the following function to test the commutation using the check rows:
For example:
Another way of testing the commutation: