models.toric: toric stabilizer codes

qecsim.models.toric

This module contains implementations relevant to toric stabilizer codes.

qecsim.models.toric.ToricCode

class qecsim.models.toric.ToricCode(rows, columns)

Bases: qecsim.model.StabilizerCode

Implements a toric code defined by its lattice size.

In addition to the members defined in qecsim.model.StabilizerCode, it provides several lattice methods as described below.

Lattice methods:

Indices:

  • Indices are in the format (lattice, row, column).

  • Qubit sites (i.e. edges) are indexed with lattice=0 and lattice=1 indicating horizontal and vertical edges, respectively, on the primal lattice.

For example, site indices on a 3 x 3 toric lattice (primal lattice edges shown):

 --|----(0,0,0)----|----(0,0,1)----|----(0,0,2)--
   |               |               |
(1,0,0)         (1,0,1)         (1,0,2)
   |               |               |
 --|----(0,1,0)----|----(0,1,1)----|----(0,1,2)--
   |               |               |
(1,1,0)         (1,1,1)         (1,1,2)
   |               |               |
 --|----(0,2,0)----|----(0,2,1)----|----(0,2,2)--
   |               |               |
(1,2,0)         (1,2,1)         (1,2,2)
   |               |               |
  • Stabilizer plaquettes are indexed by their northern edge with lattice=0 indicating plaquettes on the primal lattice, and lattice=1 indicating plaquettes on the dual lattice. (Equivalently, vertices are indicated by their northern edge with lattice=0 indicating vertices on the dual lattice, and lattice=1 indicating vertices on the primal lattice.)

For example, plaquette indices on the primal 3 x 3 lattice (primal lattice edges shown):

--|---------------|---------------|-------------
  |               |               |
  |    (0,0,0)    |    (0,0,1)    |    (0,0,2)
  |               |               |
--|---------------|---------------|-------------
  |               |               |
  |    (0,1,0)    |    (0,1,1)    |    (0,1,2)
  |               |               |
--|---------------|---------------|-------------
  |               |               |
  |    (0,2,0)    |    (0,2,1)    |    (0,2,2)
  |               |               |

For example, plaquette indices on the dual 3 x 3 lattice (dual lattice edges shown):

(1,2,0)    :    (1,2,1)    :    (1,2,2)    :
           :               :               :
 - - - - - : - - - - - - - : - - - - - - - : - -
           :               :               :
(1,0,0)    :    (1,0,1)    :    (1,0,2)    :
           :               :               :
 - - - - - : - - - - - - - : - - - - - - - : - -
           :               :               :
(1,1,0)    :    (1,1,1)    :    (1,1,2)    :
           :               :               :
 - - - - - : - - - - - - - : - - - - - - - : - -
           :               :               :
__init__(rows, columns)

Initialise new toric code.

Parameters
  • rows (int) – Number of rows in lattice.

  • columns (int) – Number of columns in lattice.

Raises
  • ValueError – if (rows, columns) smaller than (2, 2) in either dimension.

  • TypeError – if any parameter is of an invalid type.

ascii_art(syndrome=None, pauli=None)

Return ASCII art style lattice showing primal lattice lines with syndrome bits and Pauli operators as given.

Parameters
  • syndrome (numpy.array (1d)) – Syndrome (optional) as binary vector.

  • pauli (ToricPauli) – Toric Pauli (optional)

Returns

ASCII art style lattice.

Return type

str

property label

See qecsim.model.StabilizerCode.label()

property logical_xs

See qecsim.model.StabilizerCode.logical_xs()

property logical_zs

See qecsim.model.StabilizerCode.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() and logical_zs().

Return type

numpy.array (2d)

property n_k_d

See qecsim.model.StabilizerCode.n_k_d()

new_pauli(bsf=None)

Convenience constructor of toric 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

Toric Pauli

Return type

ToricPauli

property shape

Shape of the lattice in format (lattices, rows, columns), where lattice=0 is primal and lattice=1 is dual.

Return type

3-tuple of int

property size

Size of the lattice in format (rows, columns), e.g. (5, 5).

Return type

2-tuple of int

property stabilizers

See qecsim.model.StabilizerCode.stabilizers()

Notes:

  • Includes a stabilizer for each plaquette on primal and dual. So the full set is not independent.

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

Set of plaquette indices.

Return type

set of 3-tuple of int

translation(a_index, b_index)

Evaluate the shortest taxi-cab translation from A to B in format (row_steps, col_steps).

Notes:

  • Indices are in the format (lattice, row, column).

  • Both indices must index the same lattice.

  • Indices are modulo the lattice shape, i.e. on a (5, 5) lattice, (2, 6, -1) indexes the same plaquette as (0, 1, 4).

  • Negative row_steps / col_steps indicate steps in the direction of decreasing index.

Parameters
  • a_index (3-tuple of int) – Index identifying a plaquette in the format (lattice, row, column).

  • b_index (3-tuple of int) – Index identifying a plaquette in the format (lattice, row, column).

Returns

Taxi-cab translation between plaquettes.

Return type

2-tuple of int

Raises

IndexError – If indices do not index the same valid lattice.

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.

qecsim.models.toric.ToricPauli

class qecsim.models.toric.ToricPauli(code, bsf=None)

Defines a Pauli operator on a toric lattice.

Notes:

Use cases:

__init__(code, bsf=None)

Initialise new toric Pauli.

Notes:

  • For performance reasons, the new Pauli is a view of the given bsf. Modifying one will modify the other.

Parameters
  • code (ToricCode) – The toric code.

  • bsf (numpy.array (1d)) – Binary symplectic representation of Pauli. (Optional. Defaults to identity.)

property code

The toric code.

Return type

ToricCode

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

ToricPauli

logical_x1()

Apply a logical X1 operator, i.e. column of X on horizontal-edge sites of plaquettes on primal.

Returns

self (to allow chaining)

Return type

ToricPauli

logical_x2()

Apply a logical X2 operator, i.e. row of X on horizontal-edge sites of plaquettes on dual.

Returns

self (to allow chaining)

Return type

ToricPauli

logical_z1()

Apply a logical Z1 operator, i.e. row of Z on horizontal-edge sites of plaquettes on primal.

Returns

self (to allow chaining)

Return type

ToricPauli

logical_z2()

Apply a logical Z2 operator, i.e. column of Z on horizontal-edge sites of plaquettes on dual.

Returns

self (to allow chaining)

Return type

ToricPauli

operator(index)

Returns the operator on the site identified by the index.

Notes:

  • Index is in the format (lattice, row, column).

  • Index is modulo the lattice shape, i.e. on a (5, 5) lattice, (2, 6, -1) indexes the same site as (0, 1, 4).

Parameters

index (3-tuple of int) – Index identifying a site in the format (lattice, row, column).

Returns

Pauli operator. One of ‘I’, ‘X’, ‘Y’, ‘Z’.

Return type

str

path(a_index, b_index)

Apply the shortest taxi-cab path of operators between the plaquettes indexed by A and B.

Notes:

  • Indices are in the format (lattice, row, column).

  • Both indices must index the same lattice.

  • If the primal lattice is indexed (i.e. lattice=0) then X operators are applied along the shortest path on dual lattice edges.

  • If the dual lattice is indexed (i.e. lattice=1) then Z operators are applied along the shortest path on primal lattice edges.

  • Indices are modulo the lattice shape, i.e. on a (5, 5) lattice, (2, 6, -1) indexes the same plaquette as (0, 1, 4).

Parameters
  • a_index (3-tuple of int) – Index identifying a plaquette in the format (lattice, row, column).

  • b_index (3-tuple of int) – Index identifying a plaquette in the format (lattice, row, column).

Returns

self (to allow chaining)

Return type

ToricPauli

Raises

IndexError – If indices do not index the same valid lattice.

plaquette(index)

Apply a plaquette operator at the given index.

Notes:

  • Index is in the format (lattice, row, column).

  • If the primal lattice is indexed (i.e. lattice=0), then Z operators are applied around the indexed plaquette. (This is equivalent to a vertex operator on the dual lattice.)

  • If the dual lattice is indexed (i.e. lattice=1), then X operators are applied around the indexed plaquette. (This is equivalent to a vertex operator on the primal lattice.)

  • Index is modulo the lattice shape, i.e. on a (5, 5) lattice, (2, 6, -1) indexes the same plaquette as (0, 1, 4).

Parameters

index (3-tuple of int) – Index identifying the plaquette in the format (lattice, row, column).

Returns

self (to allow chaining)

Return type

ToricPauli

site(operator, *indices)

Apply the operator to site identified by the index.

Notes:

  • Index is in the format (lattice, row, column).

  • Index is modulo the lattice shape, i.e. on a (5, 5) lattice, (2, 6, -1) indexes the same site as (0, 1, 4).

Parameters
  • operator (str) – Pauli operator. One of ‘I’, ‘X’, ‘Y’, ‘Z’.

  • indices (Any number of 3-tuple of int) – Any number of indices identifying a site in the format (lattice, row, column).

Returns

self (to allow chaining)

Return type

ToricPauli

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.toric.ToricMWPMDecoder

class qecsim.models.toric.ToricMWPMDecoder

Bases: qecsim.model.Decoder

Implements a toric Minimum Weight Perfect Matching (MWPM) decoder.

Decoding algorithm:

decode(code, syndrome, **kwargs)

See qecsim.model.Decoder.decode()

classmethod distance(code, a_index, b_index)

Distance between plaquettes in terms of plaquette steps.

Note: This implementation returns the taxi-cab distance based on qecsim.models.toric.ToricCode.translation().

Parameters
  • code (ToricCode) – Toric code.

  • a_index (3-tuple of int) – Index identifying a plaquette in the format (lattice, row, column).

  • b_index (3-tuple of int) – Index identifying a plaquette in the format (lattice, row, column).

Returns

Distance between plaquettes.

Return type

int

Raises

IndexError – If indices do not index the same valid lattice.

property label

See qecsim.model.Decoder.label()