1
$\begingroup$

I wonder what is the Hartree Fock state in openfermion. Is it 110000 or 000011, assume 6 qubits and 2 particles?

$\endgroup$

1 Answer 1

2
$\begingroup$

The Hartree-Fock state in Openfermion has $1$'s in the left positions, and $0$'s in the right positions. In other words, the spin orbitals (i.e: the qubits) are ordered from least energy to most energy. So for your 6 qubit 2 particle example, the HF state is $|110000\rangle$.

Here is an example code that shows this for a 4 qubit 2 particle system.

import numpy as np
from openfermion import *
from openfermionpyscf import run_pyscf

#create Hamiltonian and compute HF energy
geometry = [
    ['H', [0,0,0]],
    ['H', [0,0,1]]
]
basis = 'sto-3g'
multiplicity = 1
charge = 0

molecule = MolecularData(geometry, basis, multiplicity, charge)
molecule = run_pyscf(molecule, run_scf=True)
HF_energy = molecule.hf_energy

#convert Hamiltonian to matrix form; this is a 4 qubit system
H = get_sparse_operator(molecule.get_molecular_hamiltonian())
n_qubits = 4

#Now, compute energy manually with formula E_psi = <psi|H|psi>

#compute energy with |1100>. This is a 2**n_qubits sized vector with 1 in the int('1100', 2) index
v1100 = np.zeros(2**n_qubits)
v1100[int('1100', 2)] = 1
E1100 = v1100 @ H @ v1100

#compute energy with |0011>. This is a 2**n_qubits sized vector with 1 in the int('0011', 2) index
v0011 = np.zeros(2**n_qubits)
v0011[int('0011', 2)] = 1
E0011 = v0011 @ H @ v0011

#print results
print("Hartree Fock Energy: {}\n".format(HF_energy))
print("<1100|H|1100> = {}\n".format(E1100))
print("<0011|H|0011> = {}\n".format(E0011))

The output is

Hartree Fock Energy: -1.0661086493179366

<1100|H|1100> = (-1.0661086493179368+0j)

<0011|H|0011> = (0.00400595045040808+0j)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.