Skip to content

Commit

Permalink
Fixing typing issues associated with openfermion v1.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
max-radin committed Feb 9, 2024
1 parent 0c32d45 commit 21ea28b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def get_double_factorized_hamiltonian_block_encoding(
lam = compute_lambda_df(h1, eri_rr, LR)

allowable_phase_estimation_error = 1
(
step_cost,
total_cost,
num_qubits,
) = _get_double_factorized_qpe_info(
(step_cost, total_cost, num_qubits,) = _get_double_factorized_qpe_info(
h1,
eri,
threshold,
Expand Down
13 changes: 6 additions & 7 deletions src/benchq/problem_ingestion/hamiltonian_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import h5py
import numpy as np
import openfermion as of
from openfermion import InteractionOperator, jordan_wigner
from openfermion import InteractionOperator, QubitOperator, jordan_wigner
from orquestra.integrations.cirq.conversions import from_openfermion
from orquestra.quantum.operators import PauliSum, PauliTerm
from orquestra.quantum.utils import ensure_open
Expand Down Expand Up @@ -115,7 +115,7 @@ def _get_hamiltonian_from_hdf5(file_name: str) -> PauliSum:
if "q_matrix" in data.keys():
return _qaoa_hamiltonian_from_hdf5(data)
elif "basis" in data.attrs:
return _molecule_hamiltonian_from_hdf5(data)
return from_openfermion(_molecule_hamiltonian_from_hdf5(data))
else:
raise ValueError(
f"Hamiltonian extraction failed for {file_name}. "
Expand Down Expand Up @@ -165,16 +165,16 @@ def _qaoa_hamiltonian_from_hdf5(data: h5py.File) -> PauliSum:
return hamiltonian


def _molecule_hamiltonian_from_hdf5(data: h5py.File) -> PauliSum:
def _molecule_hamiltonian_from_hdf5(data: h5py.File) -> QubitOperator:
"""Given a file with a hamiltonian, generate hamiltonian terms corresponding to it.
This function only accepts hamiltonians in the format with one and two body terms as
attributes of the hdf5 file.
Args:
data (h5py.File): a file with a hamiltonian described by one and two body terms
data: A file with a hamiltonian described by one and two body terms.
Returns:
PauliSum: the terms of the haimltonian
The Jordan-Wigner transformed Hamiltonian.
"""
one_body_term = data["one_body_tensor"]
two_body_term = data["two_body_tensor"]
Expand All @@ -184,5 +184,4 @@ def _molecule_hamiltonian_from_hdf5(data: h5py.File) -> PauliSum:
one_body_tensor=one_body_term,
two_body_tensor=two_body_term,
)
hamiltonian = jordan_wigner(hamiltonian)
return hamiltonian
return jordan_wigner(hamiltonian)
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,10 @@ def _get_molecular_data(

molecular_data.hf_energy = float(mean_field_object.e_tot)

molecular_data._pyscf_data = pyscf_data = {}
pyscf_data["mol"] = molecule
pyscf_data["scf"] = mean_field_object
molecular_data._pyscf_data = { # type: ignore
"mol": molecule,
"scf": mean_field_object,
}

molecular_data.canonical_orbitals = mean_field_object.mo_coeff.astype(float)
molecular_data.orbital_energies = mean_field_object.mo_energy.astype(float)
Expand Down

0 comments on commit 21ea28b

Please sign in to comment.