models.color: color stabilizer codes¶
qecsim.models.color
¶
This module contains implementations relevant to color stabilizer codes.
qecsim.models.color.Color666Code
¶
-
class
qecsim.models.color.
Color666Code
(size)¶ Bases:
qecsim.model.StabilizerCode
Implements a triangular color 6.6.6 code.
Indices:
Indices are in the format (row, column).
For example, a size 5 triangular lattice with site indices in (parentheses) and plaquette indices in [brackets]:
(0,0) | | (1,0) [1,1] \ \ [2,0] (2,1)---(2,2) | \ | \ (3,0)---(3,1) [3,2] (3,3) | \ | | \ | (4,0) [4,1] (4,2)---(4,3) [4,4] \ | \ \ | \ [5,0] (5,1)---(5,2) [5,3] (5,4)---(5,5) | \ | \ | \ | \ (6,0)---(6,1) [6,2] (6,3)---(6,4) [6,5] (6,6)
-
__init__
(size)¶ Initialise new triangular color 6.6.6 code.
- Parameters
size (int) – Size of side of triangular lattice in terms of number of qubits.
- Raises
ValueError – if size smaller than 3.
ValueError – if size is even.
TypeError – if any parameter is of an invalid type.
-
ascii_art
(syndrome=None, pauli=None)¶ Return ASCII art style lattice showing syndrome bits and Pauli operators as given.
- Parameters
syndrome (numpy.array (1d)) – Syndrome (optional) as binary vector.
pauli (Color666Pauli) – Color 6.6.6 Pauli (optional)
- Returns
ASCII art style lattice.
- Return type
str
-
property
bound
¶ Maximum value that an index coordinate can take.
- Return type
int
-
is_in_bounds
(index)¶ Return True if the index is within lattice bounds inclusive, irrespective of object type.
- Parameters
index (2-tuple of int) – Index in the format (row, column).
- Returns
If the index is within lattice bounds inclusive.
- Return type
bool
-
classmethod
is_plaquette
(index)¶ Return True if the index specifies a plaquette, irrespective of lattice bounds, i.e. column mod 3 == 2 - (row mod 3).
- Parameters
index (2-tuple of int) – Index in the format (row, column).
- Returns
If the index specifies a plaquette
- Return type
bool
-
classmethod
is_site
(index)¶ Return True if the index specifies a site, irrespective of lattice bounds, i.e. column mod 3 != 2 - (row mod 3).
- Parameters
index (2-tuple of int) – Index in the format (row, column).
- Returns
If the index specifies a site
- Return type
bool
-
property
label
¶
-
property
logical_xs
¶
-
property
logical_zs
¶
-
property
logicals
¶ Logical operators as binary symplectic matrix.
Notes:
Each row is a logical operator.
All logical X operators are stacked above all logical Z operators, in the order given by
logical_xs()
andlogical_zs()
.
- Return type
numpy.array (2d)
-
property
n_k_d
¶
-
new_pauli
(bsf=None)¶ Convenience constructor of color 6.6.6 Pauli for this code.
Notes:
For performance reasons, the new Pauli is a view of the given bsf. Modifying one will modify the other.
- Parameters
bsf (numpy.array (1d)) – Binary symplectic representation of Pauli. (Optional. Defaults to identity.)
- Returns
Color 6.6.6 Pauli
- Return type
-
property
size
¶ Size of any side of the triangular lattice in terms of number of qubits.
- Return type
int
-
property
stabilizers
¶
-
syndrome_to_plaquette_indices
(syndrome)¶ Returns the indices of the plaquettes associated with the non-commuting stabilizers identified by the syndrome.
- Parameters
syndrome (numpy.array (1d)) – Binary vector identifying commuting and non-commuting stabilizers by 0 and 1 respectively.
- Returns
Two sets of plaquette indices (first set for X stabilizers, second for Z stabilizers).
- Return type
set of 2-tuple of int, set of 2-tuple of int
-
validate
()¶ Perform various sanity checks.
Sanity checks:
\(stabilizers \odot stabilisers^T = 0\)
\(stabilizers \odot logicals^T = 0\)
\(logicals \odot logicals^T = \Lambda\)
See
qecsim.paulitools.bsp()
for definition of \(\odot\) and \(\Lambda\).- Raises
QecsimError – if the stabilizers or logicals fail the sanity checks.
-
virtual_plaquette_index
(index)¶ For the given index of a plaquette on the lattice, returns the index of the virtual plaquette just outside the boundary of the same color as the plaquette.
Notes:
Index is in the format (row, column).
Given a red plaquette, the nearest virtual plaquette will reside just outside on the red boundary (i.e. the boundary consisting of green and blue plaquettes).
The rules for other color plaquettes is found by permuting the colors in the above rule.
The above rules apply even if the given index is outside the boundary.
- Parameters
index (2-tuple of int) – Index identifying a plaquette in the format (row, column).
- Returns
Index of virtual plaquette.
- Return type
2-tuple of int
- Raises
IndexError – If index is not a plaquette index.
qecsim.models.color.Color666Pauli
¶
-
class
qecsim.models.color.
Color666Pauli
(code, bsf=None)¶ Defines a Pauli operator on a color 6.6.6 lattice.
Notes:
This is a utility class used by color 6.6.6 implementations of the core models.
It is typically instantiated using
qecsim.models.color.Color666Code.new_pauli()
Use cases:
Construct a planar Pauli operator by applying site, plaquette, path and logical operators:
site()
,plaquette()
,logical_x()
,logical_z()
.Get the single Pauli operator applied to a given site:
operator()
Convert to binary symplectic form:
to_bsf()
.Copy a planar Pauli operator:
copy()
.
-
__init__
(code, bsf=None)¶ Initialise new color 6.6.6 Pauli.
Notes:
For performance reasons, the new Pauli is a view of the given bsf. Modifying one will modify the other.
- Parameters
code (Color666Code) – The color 6.6.6 code.
bsf (numpy.array (1d)) – Binary symplectic representation of Pauli. (Optional. Defaults to identity.)
-
property
code
¶ The color 6.6.6 code.
- Return type
-
copy
()¶ Returns a copy of this Pauli that references the same code but is backed by a copy of the bsf.
- Returns
A copy of this Pauli.
- Return type
-
logical_x
()¶ Apply a logical X operator, i.e. column of X along leftmost sites.
Notes:
The column of X is applied to the leftmost column to allow optimisation of the MPS decoder.
- Returns
self (to allow chaining)
- Return type
-
logical_z
()¶ Apply a logical Z operator, i.e. column of Z along leftmost sites.
Notes:
The column of Z is applied to the leftmost column to allow optimisation of the MPS decoder.
- Returns
self (to allow chaining)
- Return type
-
operator
(index)¶ Returns the operator on the site identified by the index.
- Parameters
index (2-tuple of int) – Index identifying a site in the format (row, column).
- Returns
Pauli operator. One of ‘I’, ‘X’, ‘Y’, ‘Z’.
- Return type
str
- Raises
IndexError – If index is not an in-bounds site index.
-
plaquette
(operator, index)¶ Apply a plaquette operator at the given index.
Notes:
Index is in the format (row, column).
Parts of plaquettes that lie outside the lattice have no effect on the lattice.
- Parameters
operator (str) – Pauli operator. One of ‘I’, ‘X’, ‘Y’, ‘Z’.
index (2-tuple of int) – Index identifying the plaquette in the format (row, column).
- Returns
self (to allow chaining)
- Return type
- Raises
IndexError – If index is not a plaquette index.
-
site
(operator, *indices)¶ Apply the operator to site identified by the index.
Notes:
Index is in the format (row, column).
Operations on sites that lie outside the lattice have no effect on the lattice.
- Parameters
operator (str) – Pauli operator. One of ‘I’, ‘X’, ‘Y’, ‘Z’.
indices (Any number of 2-tuple of int) – Any number of indices identifying a site in the format (row, column).
- Returns
self (to allow chaining)
- Return type
- Raises
IndexError – If index is not a site index.
-
to_bsf
()¶ Binary symplectic representation of Pauli.
Notes:
For performance reasons, the returned bsf is a view of this Pauli. Modifying one will modify the other.
- Returns
Binary symplectic representation of Pauli.
- Return type
numpy.array (1d)
qecsim.models.color.Color666MPSDecoder
¶
-
class
qecsim.models.color.
Color666MPSDecoder
(chi=None, tol=None)¶ Bases:
qecsim.model.Decoder
Implements a planar Matrix Product State (MPS) decoder.
A version of this decoder yielded results reported in https://arxiv.org/abs/1812.08186.
Decoding algorithm:
A sample recovery operation \(f\) is found by resolving the syndrome to plaquettes (
qecsim.models.planar.PlanarCode.syndrome_to_plaquette_indices()
), finding the boundary of the same color for each plaquette (qecsim.models.planar.PlanarCode.virtual_plaquette_index()
), constructing a recovery operation by applying the correcting operator along a path between each plaquette and its corresponding boundary.The probability of the left coset \(fG\) of the stabilizer group \(G\) of the planar code with respect to \(f\) is found by contracting an appropriately defined MPS-based tensor network.
The complexity of the algorithm can managed by defining a bond dimension \(\chi\) to which the MPS bond dimension is truncated after each row/column of the tensor network is contracted into the MPS.
The probability of cosets \(f\bar{X}G\), \(f\bar{Y}G\) and \(f\bar{Z}G\) are calculated similarly.
Contraction is column-by-column starting from the rightmost column w.r.t. the tensor network described below.
A sample recovery operation from the most probable coset is returned.
Notes:
Specifying chi=None gives an exact contract (up to rounding errors) but is exponentially slow in the size of the lattice.
The code is optimised to evaluate cosets that differ only in the first column together. It is important, therefore, that the logical operators of the Color666Pauli act on the first column.
Lattice to tensor network mapping (by analogy to https://arxiv.org/abs/1405.4883):
The following figures show how a size 5 color 6.6.6 triangular lattice, as depicted in
qecsim.models.color.Color666Code
, is mapped to a tensor network that contracts to a coset probability.Stabilizers are denoted by
@
, single qubits are denoted byo
, and paired qubits are denoted by8
.Single links
-
have dimension 4, and double links=
have dimension 16.Stabilizer tensors are defined such that each element has value 1 if all indices are identical, and value 0 otherwise.
Single qubit tensors are defined such that each element has the probability associated with the product of the Pauli of the sample recovery restricted to that qubit with the Paulis associated with link indices where 0 -> I, 1 -> X, 2 -> Y, 3 -> Z.
Figure 1, size 5 triangular lattice:
o | o @ \ @ o - o | \ o - o @ o | \ | o @ o - o @ \ | \ @ o - o @ o - o | \ | \ o - o @ o - o @ o
Figure 2, tensor network corresponding to figure 1:
o \ o - @ | | \ @ - o o | \ \ | o o - @ - o \ | | \ \ o - @ - o o - @ | | \ \ | | \ @ - o o - @ - o o | \ \ | | \ \ | o o - @ - o o - @ - o
Figure 3, square tensor network equivalent to figure 2:
8 = @ - o | | | @ = 8 = @ = 8 = @ - o | | | | | | 8 = @ = 8 = @ = 8 = @ - o | | | | @ = 8 = @ - o | o
Figure 4, stabilizers can be split and summed into neighbouring qubits to reduce leg dimension from 16 to 4:
8 8 8 | | | 8 = @ = 8 => 8 = @ - @ - @ = 8 => 8.- @ -.8 | | | 8 8 8
Figure 5, tensor network equivalent to figure 3 (after splitting and summing stabilizers):
8.- @ - o | | | @ -.8.- @ -.8.- @ - o | | | | | | 8.- @ -.8.- @ -.8.- @ - o | | | | @ -.8.- @ - o | o
-
__init__
(chi=None, tol=None)¶ Initialise new planar MPS decoder.
- Parameters
chi (int or None) – Truncated bond dimension. (default=None, unrestricted=falsy)
tol (float or None) – Tolerance for treating normalised singular values as zero. (default=None, unrestricted=falsy)
- Raises
ValueError – if chi is not falsy or > 0.
ValueError – if tol is not falsy or > 0.0.
TypeError – if any parameter is of an invalid type.
-
decode
(code, syndrome, error_model=DepolarizingErrorModel(), error_probability=0.1, **kwargs)¶ See
qecsim.model.Decoder.decode()
Note: The optional keyword parameters
error_model
anderror_probability
are used to determine the prior probability distribution for use in the decoding algorithm. Any provided error model must implementprobability_distribution()
.- Parameters
code (Color666Code) – Color 666 code.
syndrome (numpy.array (1d)) – Syndrome as binary vector.
error_model (ErrorModel) – Error model. (default=DepolarizingErrorModel())
error_probability (float) – Overall probability of an error on a single qubit. (default=0.1)
- Returns
Recovery operation as binary symplectic vector.
- Return type
numpy.array (1d)
-
property
label
¶
-
classmethod
sample_recovery
(code, syndrome)¶ Return a sample Pauli consistent with the syndrome, created by applying a path between each plaquette identified by the syndrome and the nearest boundary of the same type as the plaquette.
- Parameters
code (Color666Code) – Color 666 code.
syndrome (numpy.array (1d)) – Syndrome as binary vector.
- Returns
Sample recovery operation as color 666 Pauli.
- Return type