InQuanto-HamLib¶
InQuanto-HamLib is an extension for accessing the HamLib database of quantum computing problems for benchmarking purposes [82]. This database holds over 1,000,000 Hamiltonians for benchmarking quantum algorithms and hardware. Over 30,000 of those Hamiltonians describe problems in condensed matter physics, e.g. Fermi-Hubbard and Bose-Hubbard models, as well as in computational chemistry, e.g. electronic and vibrational structure Hamiltonians. Other instances in HamLib include common optimization problems, e.g. Traveling Salesman Problem and Max-k-cut problems.
HamLib contains the qubit hamiltonians for several popular mappings: Jordan Wigner, parity and Bravi-Kitaev mappings, and often the unmapped Hamiltonians are also stored for convenience.
All of the Hamiltonians can be accessed by initiating the HamLibDatasetLoader
with a url containing the desired problem. Here, we show how to access the chemistry
Hamiltonians first, followed by condensed matter problems in the next section.
Chemistry Hamiltonians¶
All Hamiltonians for varying parameters (e.g. basis, bond length) are stores in separate zip files, so a url for a specific file is used.
from inquanto.extensions.hamlib import HamLibDatasetLoader
path0 = "https://portal.nersc.gov/cfs/m888/dcamps/hamlib/"
# Example chemistry Hamiltonian: H2 for sto-6g
url_chem = (
path0 + "chemistry/electronic/hydrogen_data/H2_linear/ES_H2_linear_R0.5_sto-6g.zip"
)
The method print_hdf5_structure() can be
used to print the contents of the file.
Then get_qubit_operator() and
get_fermion_operator() allow access to
selected Hamiltonians in the qubit or fermionic basis.
The method print_hdf5_ham_properties()
has also been provided to view the resources for this problem.
# Initiate the dataset loader for chemistry
hld_chem = HamLibDatasetLoader(url_chem)
# Inspect the Hamiltonians included in the file
hld_chem.print_hdf5_structure()
# Access the qubit and the fermion operators
print("Qubit operator:", hld_chem.get_qubit_operator("ham_JW"))
print("Fermion operator:", hld_chem.get_fermion_operator("ham_molec"))
# Print resources of the Hamiltonian
hld_chem.print_hdf5_ham_properties()
Condensed matter Hamiltonians¶
The problems in condensed matter are stored collectively in zip files, divided into 1D,
2D and 3D cases for Fermi-Hubbard model and additionally, into bosonic mode truncation level
for Bose-Hubbard model. The range of available parameters is stored in .csv files, which can be
queried using the print_keys_csv()
method. This method allows
for searching with a desired string and restricting the range of results. Once the specific
problem is identified, the Dataset column can be used to pass a key to the
get_qubit_operator() or
get_fermion_operator() methods.
import numpy as np
# First specify the path to Fermi Hubbard data
path_condensed = path0 + "condensedmatter/fermihubbard/"
csv = path_condensed + "condensedmatter_fermihubbard.csv"
# Initiate the csv dataset loader
hld_csv = HamLibDatasetLoader(csv)
# Define the parameters of the csv search
ind_range = np.s_[0:10]
str_search = "Lx-10_Ly-10_Lz-10"
# Print available condensed matter Hamiltonians
hld_csv.print_keys_csv(index_range=ind_range, string_search=str_search)
All the unmapped fermionic Hamiltonians are stored in one zip file, which can be searched just like the ones containing qubit Hamiltonians.
# Specify the path to 1D Fermi Hubbard model qubit and fermion data
url_qubit_condensed = path_condensed + "FH_D-1.zip"
url_fermion_condensed = path_condensed + "all-fh-symbolic-unencoded.zip"
# Initiate the dataset loader for the condensed matter qubit and fermion Hamiltonian
hld_qubit_condensed = HamLibDatasetLoader(url_qubit_condensed)
hld_fermion_condensed = HamLibDatasetLoader(url_fermion_condensed)
# Select the model from the outcomes of the csv search
qubit_model = "fh-graph-1D-grid-nonpbc-qubitnodes_Lx-2_U-2_enc-jw"
fermion_model = "graph-1D-grid-nonpbc-qubitnodes_Lx-2_U-2"
# Access the qubit and fermion operators
qop = hld_qubit_condensed.get_qubit_operator(qubit_model)
fop = hld_fermion_condensed.get_fermion_operator(fermion_model)
print(f"Qubit operator for model: {qubit_model} \n {qop}")
print(f"Fermion operator for model: {fermion_model} \ {fop}")