quairkit.core.hamiltonian

The module of the hamiltonian class.

class quairkit.core.hamiltonian.Hamiltonian(pauli_str, compress=True)

Hamiltonian class in QuAIRKit.

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). Defaults to True.

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 : Iterable[float]

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

property coefficients : list[float]

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

property pauli_words : list[str]

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

property pauli_words_r : list[str]

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

property pauli_words_matrix : list[Tensor]

The list of matrices with respect to simplied Pauli words.

property matrix : Tensor

The matrix form of the Hamiltonian.

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

class quairkit.core.hamiltonian.SpinOps(size, use_sparse=False)

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\).