paddle_quantum.hamiltonian

The module of the hamiltonian class.

class paddle_quantum.hamiltonian.Hamiltonian(pauli_str, compress=True)

Bases: object

Hamiltonian class in Paddle Quantum.

User can instantiate the class with a Pauli string.

Parameters:
  • pauli_str (list) – A list of Hamiltonian information, e.g. [(1, 'Z0, Z1'), (2, 'I')]

  • compress (bool | None) – Determines whether the input list will be automatically merged (e.g. (1, 'Z0, Z1') and (2, 'Z1, Z0'), these two items will be automatically merged).

  • True. (Defaults to) –

Returns:

Create a Hamiltonian class

Note

If compress=False, the legitimacy of the input will not be checked.

property n_terms: int

Number of terms of the hamiltonian.

property pauli_str: list

The Pauli string corresponding to the hamiltonian.

property terms: list

All items in hamiltonian, i.e. [['Z0, Z1'], ['I']].

property coefficients: list

The coefficient of each term in the Hamiltonian,i.e. [1.0, 2.0].

property pauli_words: list

The Pauli word of each term, i.e. ['ZIZ', 'IIX'].

property pauli_words_r: list

A list of Pauli word (exclude I), i.e. ['ZXZZ', 'Z', 'X'].

property pauli_words_matrix: list

The list of matrices with respect to simplied Pauli words.

property sites: list

A list of qubits index corresponding to the hamiltonian.

property n_qubits: int

Number of qubits.

decompose_with_sites()

Decompose pauli_str into coefficients, a simplified form of Pauli strings, and the indices of qubits on which the Pauli operators act on.

Returns:

  • coefficients: the coefficient for each term.

  • pauli_words_r: the simplified form of the Pauli string for each item, e.g. the Pauli word of ‘Z0, Z1, X3’ is ‘ZZX’.

  • sites: a list of qubits index, e.g. the site of ‘Z0, Z1, X3’ is [0, 1, 3].

Return type:

A tuple containing the following elements

decompose_pauli_words()

Decompose pauli_str into coefficients and Pauli strings.

Returns:

  • coefficients: the coefficient for each term.

  • the Pauli string for each item, e.g. the Pauli word of ‘Z0, Z1, X3’ is ‘ZZIX’.

Return type:

A tuple containing the following elements

construct_h_matrix(qubit_num=None)

Construct a matrix form of the Hamiltonian in Z-basis.

Parameters:

qubit_num (int | None) – The number of qubits. Defaults to None.

Returns:

The matrix form of the Hamiltonian in Z-basis.

Return type:

ndarray

classmethod from_qubit_operator(qubitOp)
class paddle_quantum.hamiltonian.SpinOps(size, use_sparse=False)

Bases: object

The spin operators in matrix forms, could be used to construct Hamiltonian matrix or spin observables.

Parameters:
  • size (int) – Size of the system (number of qubits).

  • use_sparse (bool | None) – Decide whether to use the sparse matrix to calculate. Default is False.

property sigz_p: list

A list of \(S^z_i\) operators, different elements correspond to different indices \(i\).

property sigy_p: list

A list of \(S^y_i\) operators, different elements correspond to different indices \(i\).

property sigx_p: list

A list of \(S^x_i\) operators, different elements correspond to different indices \(i\).