def jordan_wigner_code(n_modes): """ The Jordan-Wigner transform as binary code. Args: n_modes (int): number of modes Returns (BinaryCode): The Jordan-Wigner BinaryCode """ return BinaryCode(numpy.identity(n_modes, dtype=int), linearize_decoder(numpy.identity(n_modes, dtype=int)))
def bravyi_kitaev_code(n_modes): """ The Bravyi-Kitaev transform as binary code. The implementation follows arXiv:1208.5986. Args: n_modes (int): number of modes Returns (BinaryCode): The Bravyi-Kitaev BinaryCode """ return BinaryCode(_encoder_bk(n_modes), linearize_decoder(_decoder_bk(n_modes)))
def parity_code(n_modes): """ The parity transform (arXiv:1208.5986) as binary code. This code is very similar to the Jordan-Wigner transform, but with long update strings instead of parity strings. It does not save qubits: n_qubits = n_modes. Args: n_modes (int): number of modes Returns (BinaryCode): The parity transform BinaryCode """ dec_mtx = numpy.reshape( ([1] + [0] * (n_modes - 1)) + ([1, 1] + (n_modes - 1) * [0]) * (n_modes - 2) + [1, 1], (n_modes, n_modes)) enc_mtx = numpy.tril(numpy.ones((n_modes, n_modes), dtype=int)) return BinaryCode(enc_mtx, linearize_decoder(dec_mtx))
def _decoder_checksum(modes, odd): """ Helper function for checksum_code that outputs the decoder. Args: modes (int): number of modes odd (int or bool): 1 (True) or 0 (False), if odd, we encode all states with odd Hamming weight Returns (list): list of BinaryPolynomial """ if odd: all_in = BinaryPolynomial('1') else: all_in = BinaryPolynomial() for mode in range(modes - 1): all_in += BinaryPolynomial('w' + str(mode)) djw = linearize_decoder(numpy.identity(modes - 1, dtype=int)) djw.append(all_in) return djw
def interleaved_code(modes): """ Linear code that reorders orbitals from even-odd to up-then-down. In up-then-down convention, one can append two instances of the same code 'c' in order to have two symmetric subcodes that are symmetric for spin-up and -down modes: ' c + c '. In even-odd, one can concatenate with the interleaved_code to have the same result:' interleaved_code * (c + c)'. This code changes the order of modes from (0, 1 , 2, ... , modes-1 ) to (0, modes/2, 1 modes/2+1, ... , modes-1, modes/2 - 1). n_qubits = n_modes. Args: modes (int): number of modes, must be even Returns (BinaryCode): code that interleaves orbitals """ if modes % 2 == 1: raise ValueError('number of modes must be even') else: mtx = numpy.zeros((modes, modes), dtype=int) for index in numpy.arange(modes // 2, dtype=int): mtx[index, 2 * index] = 1 mtx[modes // 2 + index, 2 * index + 1] = 1 return BinaryCode(mtx, linearize_decoder(mtx.transpose()))