qat.fermion.chemistry.wrapper.MolecularHamiltonian

class qat.fermion.chemistry.wrapper.MolecularHamiltonian(one_body_integrals: ndarray, two_body_integrals: ndarray, constant_coeff: ndarray)

MolecularHamiltonian helper class. It represents the electronic-structure Hamiltonian defined using one- and two-body integrals.

This electronic-structure Hamiltonian is defined by:

H=uvσIuvcuσcvσ+12uvwxσσIuvwxcuσcvσcwσcxσ+rI

with r the core repulsion constant, and with Iuv and Iuvwx the one- and two-body integrals defined by:

Iuv=drϕu(r)h1[ϕv(r)]Iuvwx=drdrϕu(r)ϕv(r)v[ϕw(r)ϕx(r)]

Here, {ϕi(r)}i=0...N1 is the single-particle basis, with N the size, which depends on the basis chosen. h1=hkin+hpot is the one-body Hamiltonian, and v the Coulomb operator.

Note

This electronic-structure Hamiltonian definition is different than the one used in ElectronicStructureHamiltonian.

Parameters:
  • one_body_integrals (np.ndarray) – One-body integral Iuv.

  • two_body_integrals (np.ndarray) – Two-body integral Iuvwx.

  • constant_coeff (np.ndarray) – Constant coefficient r (core repulsion).

nqbits

The total number of qubits.

Type:

int

one_body_integrals

One-body integral Iuv.

Type:

np.ndarray

two_body_integrals

Two-body integral Iuvwx.

Type:

np.ndarray

constant_coeff

Constant coefficient r (core repulsion).

Type:

np.ndarray

Example

import numpy as np
from qat.fermion.chemistry import MolecularHamiltonian

# Initialize random one- and two-body integrals, and a constant
one_body_integral = np.random.randn(2, 2)
two_body_integral = np.random.randn(2, 2, 2, 2)
constant = np.random.rand()

# Define the MolecularHamiltonian
mol_h = MolecularHamiltonian(one_body_integral, two_body_integral, constant)

print(mol_h)
 MolecularHamiltonian(
 - constant_coeff : 0.9796315264586001
 - integrals shape
    * one_body_integrals : (2, 2)
    * two_body_integrals : (2, 2, 2, 2)
)
get_electronic_hamiltonian() ElectronicStructureHamiltonian

Converts the MolecularHamiltonian to an ElectronicStructureHamiltonian. To do so, it converts from Iuv,Iuvwx to hpq,hpqrs, with

huσ,vσ=Iu,vδσ,σhuσ1,vσ2,wσ2,xσ1=Iuvwx((1δσ,σ)+δσ,σ(1δu,v)(1δw,x))

and where the one- and two-body integrals are defined as:

Iuv(u|h|v)=drϕu(r)Tϕv(r)
Iuvwx(ux|vw)=dr1dr2ϕu(r1)ϕx(r1)v(r12)ϕv(r2)ϕw(r2)

with T (resp. v) the one- (resp. two-) body potentials, and ϕu(r) is the molecular orbital wavefunction.

The h integrals are used to construct hamiltonians of the ElectronicStructureHamiltonian type.

Returns:

ElectronicStructureHamiltonian Electronic structure hamiltonian.

select_active_space(noons: List[float], n_electrons: int, threshold_1: float | None = 0.02, threshold_2: float | None = 0.001) Tuple[MolecularHamiltonian, List[int], List[int]]

Selects the right active space and freezes core electrons according to their NOONs ni.

This function is an implementation of the Complete Active Space (CAS) approach. It divides orbital space into sets of active and inactive orbitals, the occupation number of the latter remaining unchanged during the computation.

The active space indices are defined as:

A={i,ni[ε2,2ε1[}{i,ni2ε1,2(i+1)Ne}

The inactive occupied orbitals are defined as:

O={i,ni2ε1,2(i+1)<Ne}

The restriction of the one- and two-body integrals (and update of the core energy) is then carried out according to:

u,vA,Iuv(a)=Iuv+iO2Ii,u,v,iIi,u,i,v
u,v,w,xA,Iuvwx(a)=Iuvwx
Ecore(a)=Ecore+iOIii+ijO2IijjiIijij
Parameters:
  • noons (List[float]) – the natural-orbital occupation numbers ni, sorted in descending order (from high occupations to low occupations)

  • n_electrons (int) – The number of electrons Ne.

  • threshold_1 (Optional[float]) – The upper threshold ε1 on the NOON of an active orbital.

  • threshold_2 (Optional[float]) – The lower threshold ε2 on the NOON of an active orbital.

Returns:

  • the molecular Hamiltonian in active space H(a)

  • the list of indices corresponding to the active orbitals, A

  • the list of indices corresponding to the occupied orbitals, O

Return type:

Tuple[MolecularHamiltonian, List[int], List[int]]

transform_basis(transformation_matrix: ndarray) MolecularHamiltonian

Change one and two body integrals (indices p, q…) to new basis (indices i, j…) using transformation U such that

c^i=qUqicq

i.e

I^ij=pqUpiIpqUjqI^ijkl=pqrsUpiUqjIpqrsUkrUls
Parameters:

transformation_matrix (np.array) – transformation matrix U

Returns:

MolecularHamiltonian updated to the new basis.

Return type:

molecular_hamiltonian (MolecularHamiltonian)