Skip to content

Commit

Permalink
Merge pull request #111 from UCL-CCS/faster_fermionic_ham
Browse files Browse the repository at this point in the history
Added qubit transformation to Hartree-Fock state builder
  • Loading branch information
TimWeaving authored Mar 9, 2023
2 parents 56dd624 + 76fc0be commit 36fe36a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 2 additions & 4 deletions symmer/chemistry/build_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pyscf.scf.addons import get_ghf_orbspin
from symmer import QuantumState
from symmer.symplectic.utils import safe_PauliwordOp_to_dict
from symmer.chemistry.utils import list_to_xyz, build_bk_matrix
from symmer.chemistry.utils import list_to_xyz
from symmer.chemistry import (
PySCFDriver,
get_hamiltonian,
Expand Down Expand Up @@ -65,9 +65,7 @@ def __init__(self,
self.H_q = get_hamiltonian(self.pyscf_obj.pyscf_hf, qubit_transformation=qubit_transformation)
self.CC_q = get_coupled_cluster_operator(self.pyscf_obj.pyscf_ccsd, qubit_transformation=qubit_transformation, orbspin=orbspin)
self.MP_q = get_perturbation_operator(self.pyscf_obj.pyscf_mp2, qubit_transformation=qubit_transformation)
self.hf_array = get_hf_state(self.pyscf_obj.pyscf_hf, state_type='array')
if self.qubit_transformation in ['bravyi_kitaev', 'BK']:
self.hf_array = (build_bk_matrix(self.n_qubits) @ self.hf_array.reshape(-1,1)).reshape(-1) % 2
self.hf_array = get_hf_state(self.pyscf_obj.pyscf_hf, state_type='array', qubit_transformation=qubit_transformation)
self.hf_state = QuantumState(self.hf_array)
# build various molecular symmetries
self.symmetries = get_molecular_symmetries(self.n_qubits, qubit_transformation=qubit_transformation)
Expand Down
10 changes: 8 additions & 2 deletions symmer/chemistry/molecular_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
get_fermionic_up_down_parity_operators,
get_parity_operators_BK, get_parity_operators_JW,
array_to_dict_nonzero_indices,
fermion_to_qubit_operator
fermion_to_qubit_operator,
build_bk_matrix
)

class PySCFDriver:
Expand Down Expand Up @@ -291,7 +292,7 @@ def get_hamiltonian(scf_obj=None,
fermionic_molecular_hamiltonian += FermionOperator(f'{p}^ {q}^ {r} {s}', coeff*.5)
return fermionic_molecular_hamiltonian

def get_hf_state(scf_obj, state_type = 'QuantumState'):
def get_hf_state(scf_obj, state_type = 'QuantumState', qubit_transformation='JW'):
"""
"""
n_spinorbs = scf_obj.mol.nao*2
Expand All @@ -305,6 +306,11 @@ def get_hf_state(scf_obj, state_type = 'QuantumState'):
hf_array[::2] = np.hstack([np.ones(n_alpha), np.zeros(n_spinorbs//2-n_alpha)])
hf_array[1::2] = np.hstack([np.ones(n_beta), np.zeros(n_spinorbs//2-n_beta)])

if qubit_transformation in ['bravyi_kitaev', 'BK']:
hf_array = (build_bk_matrix(n_spinorbs) @ hf_array.reshape(-1,1)).reshape(-1) % 2
else:
assert qubit_transformation in ['jordan_wigner', 'JW',], 'Invaild qubit transformation'

if state_type == 'array':
return hf_array
elif state_type == 'QuantumState':
Expand Down

0 comments on commit 36fe36a

Please sign in to comment.