qat.fermion.hamiltonians.FermionHamiltonian
- class qat.fermion.hamiltonians.FermionHamiltonian(nqbits: int, terms: List[Term], constant_coeff: float = 0.0, normal_order: bool = True)
Implementation of a fermionic Hamiltonian.
- Parameters
nqbits (int) – The total number of qubits
terms (List[Term]) – The list of terms
constant_coeff (float) – Constant term
normal_order (bool, optional) – If the fermionic terms should be normal (or Wick) ordered. Default to True. True is recommended always.
- nbqbits
The total number of qubits
- Type
int
- constant_coeff
Constant term.
- Type
float
- matrix
The corresponding matrix (None by default, can be set by calling get_matrix method).
- Type
np.ndarray
- normal_order
If the fermionic terms should be normal (or Wick) ordered.
- Type
bool
Note
Fermionic Hamiltonians are by default automatically normally ordered.
Example
from qat.core import Term from qat.fermion import FermionHamiltonian hamiltonian = FermionHamiltonian(2, [Term(0.3, "Cc", [0, 1]), Term(1.4, "CcCc", [0, 1, 1, 0])]) print(f"H = {hamiltonian}") print(f"H matrix: {hamiltonian.get_matrix()}")
H = 0.3 * (Cc|[0, 1]) + 1.4 * (Cc|[0, 0]) + 1.4 * (CCcc|[0, 1, 0, 1]) H matrix: [[0. +0.j 0. +0.j 0. +0.j 0. +0.j] [0. +0.j 0. +0.j 0. +0.j 0. +0.j] [0. +0.j 0.3+0.j 1.4+0.j 0. +0.j] [0. +0.j 0. +0.j 0. +0.j 0. +0.j]]
- copy()
Deepcopy the current class.
- Returns
Copy of the FermionHamiltonian.
- Return type
- dag() FermionHamiltonian
Compute the conjugate transpose of the Hamiltonian.
- Returns
Conjugate transpose of the Hamiltonian.
- Return type
- get_matrix(sparse: bool = False) ndarray
This function returns the matrix corresponding to \(H\) in the computational basis.
- Parameters
sparse (Optional[bool]) – Whether to return in sparse representation.
False. (Defaults to) –
- Returns
The matrix of the FermionHamiltonian.
- Return type
numpy.ndarray
Warning
This method should not be used if the Hamiltonian is too large.
- to_electronic()
Converts a fermionic Hamiltonian to a electronic-structure Hamiltonian. This can be done only if the Hamiltonian contains only single and double interaction operators (i.e. only “Cc” and “CCcc” fermionic operators).
- Returns
Electronic-structure Hamiltonian.
- Return type
- to_spin(method: Optional[str] = 'jordan-wigner')
Maps the fermionic Hamiltonian to a spin Hamiltonian.
- Parameters
method (str, optional) –
Method to use for the transformation to a spin representation. Available methods are :
”jordan-wigner” : Jordan-Wigner transform (default),
”bravyi-kitaev” : Bravyi-Kitaev transform,
”parity” : Parity transform.
- Returns
Hamiltonian in spin representation.
- Return type