mindquantum.algorithm.library.mat_to_op
- mindquantum.algorithm.library.mat_to_op(mat, little_endian: bool = True)[source]
Convert a matrix to a QubitOperator. Default output is in little endian.
- Parameters
mat – the qubit matrix that needs to be converted to a QubitOperator.
little_endian (bool) – whether the qubit order is little endian. This means the leftmost qubit is the qubit with the highest index. Default:
True
.
- Returns
QubitOperator
, the QubitOperator obtained after the matrix conversion.
Examples
>>> import numpy as np >>> from mindquantum.algorithm.library.qudit_mapping import mat_to_op >>> mat = np.array([[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]) >>> print(mat_to_op(mat, 2)) 1 [] + 1 [X0 X1]