mindquantum.core.operators.Hamiltonian

View Source On Gitee
class mindquantum.core.operators.Hamiltonian(hamiltonian, dtype=None)[source]

A QubitOperator hamiltonian wrapper.

Parameters
  • hamiltonian (Union[QubitOperator, scipy.sparse]) – The pauli qubit operator or a sparse matrix.

  • dtype (mindquantum.dtype) – data type of hamiltonian. Default: None.

Examples

>>> from mindquantum.core.operators import QubitOperator, Hamiltonian
>>> ham = Hamiltonian(QubitOperator('Z0 Y1', 0.3))
>>> ham
3/10 [Z0 Y1]
astype(dtype)[source]

Convert hamiltonian to other type.

Parameters

dtype (mindquantum.dtype) – the new type of hamiltonian.

property dtype

Get hamiltonian data type.

get_cpp_obj(hermitian=False)[source]

Get the underlying C++ object.

Parameters

hermitian (bool) – Whether to get the cpp object of this hamiltonian in hermitian version.

property ham_termlist

Get the Pauli term list of the Hamiltonian.

property hamiltonian

Get the QubitOperator of the Hamiltonian.

sparse(n_qubits=1)[source]

Calculate the sparse matrix of this hamiltonian in pqc operator.

Parameters

n_qubits (int) – The total qubit of this hamiltonian, only need when mode is 'frontend'. Default: 1.

property sparse_matrix

Get the sparse matrix representation of the Hamiltonian.