def flip_code(n_correctable, stab_kind='Z'): """ Creates an instance of :class:`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. :param int n_correctable: Maximum weight of the errors that can be corrected by this code. :param qecc.Pauli stab_kind: Single-qubit Pauli operator specifying which kind of operators to use for the new stabilizer code. :rtype: qecc.StabilizerCode """ nq = 2 * n_correctable + 1 stab_kind = p.ensure_pauli(stab_kind) if len(stab_kind) != 1: raise ValueError("stab_kind must be single-qubit.") return StabilizerCode( [p.eye_p(j) & stab_kind & stab_kind & p.eye_p(nq-j-2) for j in range(nq-1)], ['X'*nq], ['Z'*nq], label='{}-flip code (t = {})'.format(stab_kind.op, n_correctable) )
def flip_code(n_correctable, stab_kind='Z'): """ Creates an instance of :class:`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. :param int n_correctable: Maximum weight of the errors that can be corrected by this code. :param qecc.Pauli stab_kind: Single-qubit Pauli operator specifying which kind of operators to use for the new stabilizer code. :rtype: qecc.StabilizerCode """ nq = 2 * n_correctable + 1 stab_kind = p.ensure_pauli(stab_kind) if len(stab_kind) != 1: raise ValueError("stab_kind must be single-qubit.") return StabilizerCode([ p.eye_p(j) & stab_kind & stab_kind & p.eye_p(nq - j - 2) for j in range(nq - 1) ], ['X' * nq], ['Z' * nq], label='{}-flip code (t = {})'.format( stab_kind.op, n_correctable))