models.rotatedtoric: rotated toric stabilizer codes

qecsim.models.rotatedtoric

This module contains implementations relevant to rotated toric stabilizer codes.

qecsim.models.rotatedtoric.RotatedToricCode

class qecsim.models.rotatedtoric.RotatedToricCode(rows, columns)

Bases: qecsim.model.StabilizerCode

Implements a rotated 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 (x, y).

  • Qubit sites (vertices) are indexed by (x, y) coordinates with the origin at the lower left qubit.

  • Stabilizer plaquettes are indexed by (x, y) coordinates such that the lower left corner of the plaquette is on the qubit site at (x, y).

  • X-type stabilizer plaquette indices satisfy (x-y) % 2 == 1.

  • Z-type stabilizer plaquette indices satisfy (x-y) % 2 == 0.

For example, qubit site indices on a 4 x 4 lattice:

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

For example, stabilizer plaquette types and indices on a 4 x 4 lattice:

|    X    |    Z    |    X    |    Z
|  (0,3)  |  (1,3)  |  (2,3)  |  (3,3)
|         |         |         |
+---------+---------+---------+-------
|    Z    |    X    |    Z    |    X
|  (0,2)  |  (1,2)  |  (2,2)  |  (3,2)
|         |         |         |
+---------+---------+---------+-------
|    X    |    Z    |    X    |    Z
|  (0,1)  |  (1,1)  |  (2,1)  |  (3,1)
|         |         |         |
+---------+---------+---------+-------
|    Z    |    X    |    Z    |    X
|  (0,0)  |  (1,0)  |  (2,0)  |  (3,0)
|         |         |         |
+---------+---------+---------+-------
__init__(rows, columns)

Initialise new rotated 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.

  • ValueError – if rows or columns are odd.

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

ascii_art(syndrome=None, pauli=None, plaquette_labels=None, site_labels=None)

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

Notes:

  • Optional plaquette_labels override syndrome. (Out of bound indices are ignored.)

  • Optional site_labels override pauli. (Out of bound indices are ignored.)

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

  • pauli (RotatedToricPauli) – Rotated toric Pauli (optional)

  • plaquette_labels (dict of (int, int) to char) – Dictionary of plaquette indices as (x, y) to single-character labels (optional).

  • site_labels (dict of (int, int) to char) – Dictionary of site indices as (x, y) to single-character labels (optional).

Returns

ASCII art style lattice.

Return type

str

property bounds

Maximum x and y value that an index coordinate can take.

Return type

2-tuple of int

is_in_bounds(index)

Return True if the index is within lattice bounds inclusive.

Parameters

index (2-tuple of int) – Index in the format (x, y).

Returns

If the index is within lattice bounds inclusive.

Return type

bool

classmethod is_x_plaquette(index)

Return True if the plaquette index specifies an X-type plaquette, irrespective of lattice bounds.

Parameters

index (2-tuple of int) – Index in the format (x, y).

Returns

If the index specifies an X-type plaquette.

Return type

bool

classmethod is_z_plaquette(index)

Return True if the plaquette index specifies an Z-type plaquette, irrespective of lattice bounds.

Parameters

index (2-tuple of int) – Index in the format (x, y).

Returns

If the index specifies an Z-type plaquette.

Return type

bool

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 rotated 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

Rotated toric Pauli

Return type

RotatedToricPauli

property size

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

Return type

2-tuple of int

property stabilizers

See qecsim.model.StabilizerCode.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

Set of plaquette indices.

Return type

set of 2-tuple of int

translation(a_index, b_index)

Evaluate the shortest taxi-cab translation from plaquette A to plaquette B in format (x_steps, y_steps).

Notes:

  • Indices are in the format (x, y).

  • Indices are modulo lattice dimensions, i.e. on a (2, 2) lattice, (2, -1) indexes the same site as (0, 1).

  • Both plaquettes must be of the same type, i.e. X or Z.

  • Negative x_steps / y_steps indicate steps in the direction of decreasing index.

Parameters
  • a_index ((int, int)) – Plaquette index as (x, y).

  • b_index ((int, int)) – Plaquette index as (x, y).

Returns

Taxi-cab translation between plaquettes.

Return type

2-tuple of int

Raises

IndexError – If plaquettes are not of the same type (i.e. X or Z).

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.rotatedtoric.RotatedToricPauli

class qecsim.models.rotatedtoric.RotatedToricPauli(code, bsf=None)

Defines a Pauli operator on a rotated toric lattice.

Notes:

Use cases:

__init__(code, bsf=None)

Initialise new rotated toric Pauli.

Notes:

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

Parameters
  • code (RotatedToricCode) – The rotated toric code.

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

property code

The rotated toric code.

Return type

RotatedToricCode

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

RotatedToricPauli

logical_x1()

Apply a logical X1 operator, i.e. column of X at sizes with x = 0.

Returns

self (to allow chaining)

Return type

RotatedToricPauli

logical_x2()

Apply a logical X2 operator, i.e. row of X at sites with y = 0.

Returns

self (to allow chaining)

Return type

RotatedToricPauli

logical_z1()

Apply a logical Z1 operator, i.e. row of Z at sites with y = 0.

Returns

self (to allow chaining)

Return type

RotatedToricPauli

logical_z2()

Apply a logical Z2 operator, i.e. column of Z at sizes with x = 0.

Returns

self (to allow chaining)

Return type

RotatedToricPauli

operator(index)

Returns the operator on the site identified by the index.

Notes:

  • Index is in the format (x, y).

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

Parameters

index (2-tuple of int) – Index identifying a site in the format (x, y).

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 (x, y).

  • Indices are modulo lattice dimensions, i.e. on a (2, 2) lattice, (2, -1) indexes the same site as (0, 1).

  • Both plaquettes must be of the same type, i.e. X or Z.

  • If X plaquettes are indexed then Z operators are applied.

  • If Z plaquettes are indexed then X operators are applied.

Parameters
  • a_index ((int, int)) – Plaquette index as (x, y).

  • b_index ((int, int)) – Plaquette index as (x, y).

Returns

self (to allow chaining)

Return type

ToricPauli

Raises

IndexError – If plaquettes are not of the same type (i.e. X or Z).

plaquette(index)

Apply a plaquette operator at the given index.

Notes:

  • Index is in the format (x, y).

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

  • If an Z-type plaquette is indexed (i.e. (x - y) % 2 == 0), then Z operators are applied around the plaquette.

  • If an X-type plaquette is indexed (i.e. (x - y) % 2 == 1), then X operators are applied around the plaquette.

Parameters

index (2-tuple of int) – Index identifying the plaquette in the format (x, y).

Returns

self (to allow chaining)

Return type

RotatedToricPauli

site(operator, *indices)

Apply the operator to site identified by the index.

Notes:

  • Index is in the format (x, y).

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

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

  • indices (Any number of 2-tuple of int) – Any number of indices identifying sites in the format (x, y).

Returns

self (to allow chaining)

Return type

RotatedToricPauli

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.rotatedtoric.RotatedToricSMWPMDecoder

class qecsim.models.rotatedtoric.RotatedToricSMWPMDecoder(itp=False, eta=None)

Bases: qecsim.model.Decoder, qecsim.model.DecoderFTP

Implements a rotated toric Symmetry Minimum Weight Perfect Matching (SMWPM) decoder.

A version of this decoder yielded results reported in https://arxiv.org/abs/1907.02554.

Note: This decoder handles decoding for both qecsim.app.run() and qecsim.app.run_ftp() simulations.

This decoder is described conceptually in the aforementioned paper. We assume that the noise is highly biased towards Y errors. The decoding algorithm is the same as that of qecsim.models.rotatedplanar.RotatedPlanarSMWPMDecoder, without the complication of virtual nodes on the boundary, but with a test for time-like logical failures.

__init__(itp=False, eta=None)

Initialise new rotated toric SMWPM decoder.

Parameters
  • itp (bool) – Ignore time parity, i.e. decoder should not fail in case of time-like logical. (default=False)

  • eta (float or None) – Bias (default=None, take-from-error-model=None)

Raises
  • ValueError – if eta is not None or > 0.0.

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

decode(code, syndrome, error_model=BitPhaseFlipErrorModel(), error_probability=0.1, **kwargs)

See qecsim.model.Decoder.decode()

Note: The optional keyword parameters error_model and error_probability are used to determine the prior probability distribution for use in the decoding algorithm. Any provided error model must implement probability_distribution().

Parameters
  • code (RotatedToricCode) – Rotated toric code.

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

  • error_model (ErrorModel) – Error model. (default=BitPhaseFlipErrorModel())

  • 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)

decode_ftp(code, time_steps, syndrome, error_model=BitPhaseFlipErrorModel(), error_probability=0.1, measurement_error_probability=0.1, step_measurement_errors=None, **kwargs)

See qecsim.model.DecoderFTP.decode_ftp()

Note:

  • The optional keyword parameters error_model and error_probability are used to determine the prior probability distribution for use in the decoding algorithm. Any provided error model must implement probability_distribution().

  • This method always returns a DecodeResult with the following parameters:

    DecodeResult(
        success=None,  # None indicates to be evaluated by app
                       # False indicates time-like logical failure (overrides evaluation by app)
        logical_commutations=None,  # None indicates to be evaluated by app
        recovery=np.array(...),  # recovery operation (used by app to evaluate success and logical_commutations)
        custom_values=np.array([0, 0]),  # [0, 0] no time-like logical failure
                                         # [1, 0] time-like logical failure through X plaquettes
                                         # [0, 1] time-like logical failure through Z plaquettes
                                         # [1, 1] time-like logical failure through both X and Z plaquettes
    )
    
Parameters
  • code (RotatedToricCode) – Rotated toric code.

  • time_steps (int) – Number of time steps.

  • syndrome (numpy.array (2d)) – Syndrome as binary array.

  • error_model (ErrorModel) – Error model. (default=BitPhaseFlipErrorModel())

  • error_probability (float) – Overall probability of an error on a single qubit. (default=0.1)

  • measurement_error_probability (float) – Overall probability of an error on a single measurement. (default=0.1)

  • step_measurement_errors (list of numpy.array (1d)) – list of measurement error bits applied to step-syndromes index by time-step.

Returns

Decode result.

Return type

DecodeResult

property label

See qecsim.model.Decoder.label()