mindquantum.utils.random_hamiltonian

View Source On Gitee
mindquantum.utils.random_hamiltonian(n_qubits: int, n_terms: int, seed: int = None, dtype=None)[source]

Generate a random Pauli Hamiltonian.

Parameters
  • n_qubits (int) – Number of qubits

  • n_terms (int) – Number of Pauli terms

  • seed (int, optional) – Random seed. Defaults to None.

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

Returns

Hamiltonian, Randomly generated Hamiltonian

Examples

>>> ham = random_hamiltonian(4, 5, seed=42)
>>> print(ham)
-0.5018 [Z0] + 1.8029 [X0 X1] + 0.928 [Y0 X1 Y2] + 0.3946 [Z2 X3] - 1.3759 [Z1 Y3]