Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fault-tolerant resource estimates for chemical hamiltonians #763

Merged
merged 8 commits into from
Jan 26, 2022

Conversation

jjgoings
Copy link
Contributor

@jjgoings jjgoings commented Jan 11, 2022

Overview

Add new module openfermion.resource_estimates to facilitate fault-tolerant (FT) resource estimates for chemical Hamiltonians. Addresses #723.

The following factorizations are included:

For the methods listed above, there are sub-routines which:

  • factorize the two-electron integrals, factorize()
  • compute the lambda values, compute_lambda()
  • estimate the number of logical qubits and Toffoli gates required to simulate with this factorization, compute_cost()

There are also some costing routines for the sparse factorization, but this is a work in progress.

Details

The philosophy for this new module is to rely on PySCF to generate, store, and manipulate molecular information. The data (integrals, etc) is stored as a PySCF mean-field (mf) object. As an example, one could input an ionized water molecule like so:

from pyscf import gto, scf

# input is just like any other PySCF script
mol = gto.M(
    atom = '''O    0.000000      -0.075791844    0.000000
              H    0.866811829    0.601435779    0.000000
              H   -0.866811829    0.601435779    0.000000
           ''',
    basis = 'augccpvtz',
    symmetry = False,
    charge = 1,
    spin = 1
)
mf = scf.ROHF(mol)
mf.verbose = 4
mf.kernel()  # run the SCF

Then, given the mf object, resource_estimates.molecule has routines to further manipulate the molecule, such as testing for stability (and reoptimizing), as well as localizing orbitals and performing automated active space selection with AVAS. Continuing our example:

from openfermion.resource_estimates.molecule import stability, localize, avas_active_space

# make sure wave function is stable before we proceed
mf = stability(mf)

# localize before automatically selecting active space with AVAS
mf = localize(mf, loc_type='pm')  # default is loc_type ='pm' (Pipek-Mezey)

# you can use larger basis for `minao` to select non-valence...here select O 3s and 3p as well 
mol, mf = avas_active_space(mf, ao_list=['H 1s', 'O 2s', 'O 2p', 'O 3s', 'O 3p'], minao='ccpvtz') 

In each case, the input is the mean-field mf object, and the output is a modified mf object. The mf object is not updated in-place, so it is possible to create additional copies in memory.

At this point, we have a stable wave function, localized the orbitals, and selected an active space. At any point, the molecular Hamiltonian (e.g. active space) can be written out to HDF5 using molecule.save_pyscf_to_casfile(), or, if it exists, read in using molecule.load_casfile_to_pyscf().

Once an active space is selected/generated, costing is relatively straightforward. There are helper functions for the SF, DF, and THC factorization schemes that will make a nice table given some parameters. For example:

from openfermion.resource_estimates import sf

# make pretty SF costing table
sf.generate_costing_table(mf, name='water', rank_range=[20,25,30,35,40,45,50])

which outputs to a file called single_factorization_water.txt, and contains:

 Single low rank factorization data for 'water'.
    [*] using CAS((5a, 4b), 11o)
        [+]                      E(SCF):       -75.63393088
        [+] Active space CCSD(T) E(cor):        -0.08532629
        [+] Active space CCSD(T) E(tot):       -75.71925716
============================================================================================================
     L          ||ERI - SF||       lambda      CCSD(T) error (mEh)       logical qubits       Toffoli count    
------------------------------------------------------------------------------------------------------------
     20          1.7637e-01        212.7              -2.97                   298                4.3e+08       
     25          5.7546e-02        215.0               1.53                   298                4.7e+08       
     30          2.9622e-02        216.1               0.11                   298                5.1e+08       
     35          1.3728e-02        216.5              -0.07                   301                5.5e+08       
     40          2.1439e-03        216.7               0.00                   460                5.8e+08       
     45          2.8662e-04        216.8               0.00                   460                6.0e+08       
     50          1.1826e-04        216.8               0.00                   460                6.2e+08       
============================================================================================================

Note that the automated costing relies on error in CCSD(T) - or CCSD, if desired - as the metric, so this may become a bottleneck for large active spaces.

The philosophy is that all costing methods are captured in the namespace related to the type of factorization (e.g., . So if one wanted to repeat the costing for DF or THC factorizations, one could

from openfermion.resource_estimates import df, thc

# make pretty DF costing table
df.generate_costing_table(mf, name='water', thresh_range=[1e-2,5e-3,1e-3,5e-4,1e-4,5e-5,1e-5]) 

# make pretty THC costing table
# if you want to save each THC result to a file, you can set 'save_thc' to True
thc.generate_costing_table(mf, name='water', nthc_range=[20,25,30,35,40,45,50], save_thc=False) 

Which generate similar outputs, e.g. the above would generate tables in double_factorization_water.txt and thc_factorization_water.txt.

More fine-grained control is given by subroutines that compute the factorization, the lambda values, and the cost estimates. For example, considering the double factorization, we could have

factorized_eris, df_factors, _, _ = df.factorize(mf._eri, cutoff_threshhold)
df_lambda  = df.compute_lambda(mf, df_factors)
_, number_toffolis, num_logical_qubits = df.compute_cost(num_spin_orbitals, df_lambda, *args)

which, unlike the pretty tables above, require the user to handle and input several molecular quantities and intermediates, but at the gain of more functionality and control. Switching between factorization schemes is generally as easy as swapping out the namespace, for example to perform different factorizations on the ERIs,

sf.factorize()
df.factorize()
thc.factorize()

are all valid, as are the methods compute_lambda() and compute_cost() for the factorizations.

Testing (+ dependencies)

All the code comes with tests (use pytest) and has been tested on Debian GNU/Linux with Python 3.8.5.

Since the FT costing is closely tied to manipulation of molecular integrals (localization, active space selection, benchmarking against CCSD(T), ...) the code depends on PySCF. Since we do not want to burden all OpenFermion users with this dependency, testing is disabled in the GitHub workflow. Moreover, the resource_estimates functionality requires the dependencies

pyscf
h5py~=3.3.0
jax
jaxlib

For THC factorization, it also requires BTAS and the PyBTAS wrapper, which require their own installation + depends.

Again, since we do not wish to burden all OpenFermion users with these dependencies, testing with GitHub workflows is disabled, but if you install the dependencies, running pytest should pass.

…cks for resource_estimates for now, as the resource_estimates module requires additional dependencies we don't want to burden the user with.
@jjgoings jjgoings requested a review from ncrubin January 19, 2022 20:03
Copy link
Collaborator

@ncrubin ncrubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Needs a code comment removal sweep but other than that it is good.

@jjgoings jjgoings marked this pull request as ready for review January 20, 2022 04:30
@jjgoings jjgoings requested a review from ncrubin January 20, 2022 22:52
@ncrubin ncrubin merged commit cf53c06 into quantumlib:master Jan 26, 2022
ncrubin pushed a commit to ncrubin/OpenFermion that referenced this pull request Jul 25, 2022
…ib#763)

* Initial commit of resource_estimates. Ignore testing and coverage checks for resource_estimates for now, as the resource_estimates module requires additional dependencies we don't want to burden the user with.

* clean up imports

* clean up imports

* readme for resource_estimates

* fixup some old comments

* fixup more comments

* more comment cleanup

* Update README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants