|View source on GitHub|
The BinaryCode class provides a representation of an encoding-decoding
openfermion.ops.BinaryCode( encoding, decoding )
Used in the notebooks
|Used in the tutorials|
pair for binary vectors of different lengths, where the decoding is allowed to be non-linear.
As the occupation number of fermionic mode is effectively binary, a length-N vector (v) of binary number can be utilized to describe a configuration of a many-body fermionic state on N modes. An n-qubit product state configuration |w0> |w1> |w2> ... |wn-1>, on the other hand is described by a length-n binary vector w=(w0, w1, ..., wn-1). To map a subset of N-Orbital Fermion states to n-qubit states we define a binary code, which consists of a (here: linear) encoding (e) and a (non-linear) decoding (d), such that for every v from that subset, w = e(v) is a length-n binary vector with d(w) = v. This can be used to save qubits given a Hamiltonian that dictates such a subset, otherwise n=N.
Two binary codes (e,d) and (e',d') can construct a third code (e",d") by two possible operations:
Concatenation: (e",d") = (e,d) * (e',d') which means e": v" -> e'( e(v") ) and d": w" -> d( d'(w") ) where n" = n' and N" = N, with n = N' as necessary condition.
Appendage: (e",d") = (e,d) + (e',d') which means e": (v + v') -> e(v) + e'(v') and d": (w + w') -> d(w) + d'( w') where the addition is to be understood as appending two vectors together, so N" = N' + N and n" = n + n'.
Appending codes is particularly useful when considering segment codes or segmented transforms.
A BinaryCode-instance is initialized by BinaryCode(A,d), given the encoding (e) as n x N array or matrix-like nested lists A, such that e(v) = (A v) mod 2. The decoding d is an array or a list input of length N, which has entries either of type BinaryPolynomial, or of valid type for an input of the BinaryPolynomial-constructor.
The signs + and *, += and *= are overloaded to implement concatenation and appendage on BinaryCode-objects.
|encoding (np.ndarray or list): nested lists or binary 2D-array decoding (array or list): list of BinaryPolynomial (list or str).|
||non-list, array like encoding or decoding, unsuitable BinaryPolynomial generators,|
||in case of decoder/encoder size mismatch or decoder size, qubits indexed mismatch|
__add__( appendix )
Appends two binary codes via addition +.
|appendix (BinaryCode): The code to append to the present one.|
Returns (BinaryCode): global binary code
__mul__( factor )
Concatenation of two codes or appendage the same code factor times in case of integer factor.
|factor (int or BinaryCode): the BinaryCode to concatenate. In case of int, it will append the code to itself factor times.|
Returns (BinaryCode): segmented or concatenated code
__rmul__( factor )
Appending the same code factor times.
|factor (int): integer defining number of appendages.|
Returns (BinaryCode): Segmented code.
||factor must be an integer|