QuaEC includes a class, qecc.StabilizerCode, that represents error-correcting codes specified using the stabilizer formalism [Got97]. To construct a stabilizer code in QuaEC, the generators of a stabilizer group must be specified along with a particular assignment of logical operators acting on states encoded in the stabilizer code.
>>> import qecc as q
>>> stab = q.StabilizerCode(['ZZI', 'IZZ'], ['XXX'], ['ZZZ'])
>>> print stab
S = <i^0 ZZI, i^0 IZZ>
Xbars = PauliList(i^0 XXX)
Zbars = PauliList(i^0 ZZZ)
For convienence, several static methods are provided to create instances for well-known stabilizer codes.
>>> stab = q.StabilizerCode.perfect_5q_code()
>>> print stab
5-qubit perfect code
S = <i^0 XZZXI, i^0 IXZZX, i^0 XIXZZ, i^0 ZXIXZ>
Xbars = PauliList(i^0 XXXXX)
Zbars = PauliList(i^0 ZZZZZ)
Once constructed, an instance of qecc.StabilizerCode exposes properties that describe the number of physical and logical qubits, as well as the distance of the code. (Please note that calculating the distance can be extremely slow for large codes.)
>>> print (stab.nq, stab.nq_logical, stab.distance)
(5, 1, 3)
Encoders and decoders for stabilizer codes can be found in a straightforward manner using qecc.StabilizerCode.
>>> enc = stab.encoding_cliffords().next()
>>> print enc
X[0] |-> +X[0] X[1] X[2] X[3] X[4]
X[1] |-> +X[0] X[2] X[3] X[4]
X[2] |-> +X[1] X[2]
X[3] |-> +Y[0] X[1] X[3] Y[4]
X[4] |-> +X[0] X[1] Y[3] Y[4]
Z[0] |-> +Z[0] Z[1] Z[2] Z[3] Z[4]
Z[1] |-> +X[0] Z[1] Z[2] X[3]
Z[2] |-> +X[1] Z[2] Z[3] X[4]
Z[3] |-> +X[0] X[2] Z[3] Z[4]
Z[4] |-> +Z[0] X[1] X[3] Z[4]
>>> print enc.inv()
X[0] |-> -X[0] Z[3] X[4]
X[1] |-> +X[0] X[1]
X[2] |-> +X[0] X[1] X[2]
X[3] |-> -X[0] X[2] X[3] Z[4]
X[4] |-> +X[0] Y[3] Y[4]
Z[0] |-> -Z[0] Y[1] Y[3] Z[4]
Z[1] |-> -Z[0] Y[2] Z[3] Y[4]
Z[2] |-> +Z[0] Z[1] Z[2] X[3]
Z[3] |-> -Z[0] Y[1] Z[3] Y[4]
Z[4] |-> -Z[0] Z[1] X[2] Z[3] Z[4]
Stabilizer codes may be combined by the tensor product (reprsented in QuaEC by &), or by concatenation:
>>> print stab & stab
S = <i^0 XZZXIIIIII, i^0 IXZZXIIIII, i^0 XIXZZIIIII, i^0 ZXIXZIIIII, i^0 IIIIIXZZXI, i^0 IIIIIIXZZX, i^0 IIIIIXIXZZ, i^0 IIIIIZXIXZ>
Xbars = PauliList(i^0 XXXXXIIIII, i^0 IIIIIXXXXX)
Zbars = PauliList(i^0 ZZZZZIIIII, i^0 IIIIIZZZZZ)
>>> print q.StabilizerCode.bit_flip_code(1).concatenate(q.StabilizerCode.phase_flip_code(1))
S = <i^0 Z[0] Z[1], i^0 Z[1] Z[2], i^0 Z[3] Z[4], i^0 Z[4] Z[5], i^0 Z[6] Z[7], i^0 Z[7] Z[8], i^0 XXXXXXIII, i^0 IIIXXXXXX>
Xbars = PauliList(i^0 XXXXXXXXX)
Zbars = PauliList(i^0 ZZZZZZZZZ)
Class representing a stabilizer code specified by the generators of its stabilizer group and by representatives for the logical operators acting on the code.
Parameters: |
|
---|
The number of physical qubits into which this code encodes.
The number of stabilizer constraints on valid codewords.
The number of logical qubits admitted by this code.
Derives logical operators, given logical
and
operators.
Returns a list of all logical operators for a code in the form [Xs, Ys, Zs].
The distance of this code, defined by , where
is the stabilizer group
for this code.
Warning: this property is currently very slow to compute.
The number of errors correctable by this code, defined by
, where
is
the distance of the code, given by the distance property.
Iterator onto all elements of the stabilizer group describing
this code, or onto a coset
of the stabilizer group.
Parameters: | coset_rep (qecc.Pauli) – A Pauli operator ![]() ![]() |
---|---|
Yields : | All elements of the coset ![]() ![]() |
Iterator onto the group , where
is
the stabilizer group describing this code. Each member of the group
is specified by a coset representative drawn from the respective
elements of
. These representatives are
chosen to be the logical
and
operators specified
as properties of this instance.
Parameters: | incl_identity (bool) – If False, the identity coset ![]() |
---|---|
Yields : | A representative for each element of ![]() |
Returns all elements of the normalizer of the stabilizer group. If
mod_s is True, returns the set .
Returns an iterator onto all Clifford operators that encode into this
stabilizer code, starting from an input register such that the state to
be encoded is a state of the first qubits, and such that the
rest of the qubits in the input register are initialized to
.
Yields : | instances C of qecc.Clifford such that C(q.StabilizerCode.unencoded_state(k, n - k)) equals this code. |
---|
Returns a Pauli operator which corrects an error on the stabilizer code self, given the syndrome synd, a bitstring indicating which generators the implied error commutes with and anti-commutes with.
Parameters: | synd – a string, list, tuple or other sequence type with entries consisting only of 0 or 1. This parameter will be certified before use. |
---|
Outputs an iterator onto tuples of syndromes and appropriate recovery operators.
Returns the recovery operator (as specified by syndromes_and_recovery_operators()), expressed as a Qcircuit array.
Parameters: |
---|
Returns a tuple of a decoding Clifford and a qecc.PauliList
specifying the recovery operation to perform as a function of the result
of a measurement on the ancilla register.
For syndromes corresponding to errors of weight greater than the distance, the relevant element of the recovery list will be set to qecc.Unspecified.
Parameters: |
|
---|
Reorders the stabilizer group generators of this code to minimize the Hamming distance with the group generators of another code, using a greedy heuristic algorithm.
Returns a array whose rows form a basis for
the codespace of this code. Please note that by necessity, this code
is exponentially slow as a function of the numbers of physical and
logical qubits.
Given a Pauli operator acting on
, finds a Pauli
operator
on
qubits that corresponds
to the logical operator acting across
blocks of this code.
Note that this method is only supported for single logical qubit codes.
Produces a circuit that measures the stabilizer code generator self.group_generators[gen_idx] onto the qubit labelled by stab.nq (that is, the next qubit not in the physical register used by the code).
Parameters: | gen_idx (int) – Index of a generator of the stabilizer group, as specified by the group_generators property of this instance. |
---|---|
Returns qecc.Circuit: | |
A circuit that maps a measurement of
group_generators[gen_idx] onto a measurement of ![]() |
Returns a circuit which measures all stabilizer generators onto ancillae, using measure_gen_onto_ancilla.
Returns a stabilizer code with generators related to the generators of self, with every instance of {X,Y,Z} replaced with {perm[0],perm[1],perm[2]}.
Parameters: | perm (list) – A list containing ‘X’,’Y’, and ‘Z’ in any order, indicating which permutation is to be applied. |
---|
>>> new_stab = q.StabilizerCode.bit_flip_code(1).permute_gen_ops('ZYX')
>>> assert new_stab.group_generators == q.StabilizerCode.phase_flip_code(1).group_generators
Returns the stabilizer for a concatenated code, given the
stabilizers for two codes. At this point, it only works for two
codes.
Returns an iterator onto all qecc.Clifford objects which take states specified by self, and return states specified by other.
Parameters: | other – qecc.StabilizerCode |
---|
Searches the iterator provided by transcoding_cliffords for the shortest circuit decomposition.
Creates an instance of qecc.StabilizerCode representing an
ancilla register of nq qubits, initialized in the state
.
Return type: | qecc.StabilizerCode |
---|
Creates an instance of qecc.StabilizerCode representing an unencoded register of nq_logical qubits tensored with an ancilla register of nq_ancilla qubits.
Parameters: | nq_logical (int) – Number of qubits to |
---|---|
Return type: | qecc.StabilizerCode |
Creates an instance of qecc.StabilizerCode representing a code that protects against weight-n_correctable flip errors of a single kind.
This method generalizes the bit-flip and phase-flip codes, corresponding to stab_kind=qecc.Z and stab_kind=qecc.X, respectively.
Parameters: |
|
---|---|
Return type: | qecc.StabilizerCode |
Creates an instance of qecc.StabilizerCode representing a code that protects against weight-n_correctable bit-flip errors.
Parameters: | n_correctable (int) – Maximum weight of the bit-flip errors that can be corrected by this code. |
---|---|
Return type: | qecc.StabilizerCode |
Creates an instance of qecc.StabilizerCode representing a code that protects against weight-n_correctable phase-flip errors.
Parameters: | n_correctable (int) – Maximum weight of the phase-flip errors that can be corrected by this code. |
---|---|
Return type: | qecc.StabilizerCode |
Creates an instance of qecc.StabilizerCode representing the 5-qubit perfect code.
Return type: | qecc.StabilizerCode |
---|
Creates an instance of qecc.StabilizerCode representing the 7-qubit Steane code.
Return type: | qecc.StabilizerCode |
---|
Creates an instance of qecc.StabilizerCode representing the 9-qubit Shor code.
Return type: | qecc.StabilizerCode |
---|
Not yet implemented.
Not yet implemented.
Not yet implemented.