Skip to content

Commit cf53c06

Browse files
authored
fault-tolerant resource estimates for chemical hamiltonians (#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
1 parent 6187085 commit cf53c06

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4897
-4
lines changed

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ Follow the links below to learn more!
8787
High performance simulators
8888
------------------------------------------
8989
* `OpenFermion-FQE <https://github.com/quantumlib/OpenFermion-FQE>`__ is
90-
a high performance emulator of fermionic quantum evolutions specified
91-
by a sequence of fermion operators, which can exploit fermionic
92-
symmetries such as spin and particle number.
90+
a high performance emulator of fermionic quantum evolutions specified
91+
by a sequence of fermion operators, which can exploit fermionic
92+
symmetries such as spin and particle number.
9393

9494
Circuit compilation plugins
9595
------------------------------------------

dev_tools/conf/.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# Failure to do so will result in false positives.
55
omit =
66
./profiling/performance_benchmarks.py
7-
./dev_tools/*
7+
./dev_tools/*
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
### Disclaimer: testing, dependencies, etc.
2+
3+
Code is system tested on Debian GNU/Linux with Python 3.8.5. All the code comes with tests (use `pytest`), but not unit tested with GitHub worflows.
4+
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](https://pyscf.org/). 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
6+
7+
```
8+
pyscf
9+
h5py~=3.3.0
10+
jax
11+
jaxlib
12+
```
13+
14+
For THC factorization, it also requires [BTAS](https://github.com/ValeevGroup/BTAS) and the [PyBTAS](https://github.com/ncrubin/pybtas) wrapper, which require their own installation + depends.
15+
16+
### Overview
17+
18+
Module `openfermion.resource_estimates` to facilitate fault-tolerant (FT) resource estimates for chemical Hamiltonians.
19+
20+
The following factorizations are included:
21+
* The [single](https://arxiv.org/abs/1902.02134) [factorization](https://arxiv.org/abs/1808.02625) (SF) method
22+
* The [double factorization](https://arxiv.org/pdf/2007.14460) (DF) method
23+
* The [tensor hypercontraction](https://arxiv.org/abs/2011.03494) (THC) method
24+
25+
For the methods listed above, there are sub-routines which:
26+
* factorize the two-electron integrals, `factorize()`
27+
* compute the lambda values, `compute_lambda()`
28+
* estimate the number of logical qubits and Toffoli gates required to simulate with this factorization, `compute_cost()`
29+
30+
There are also some costing routines for the [sparse factorization](https://arxiv.org/abs/1902.02134), but this is a work in progress.
31+
32+
### Details
33+
34+
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:
35+
36+
```python
37+
from pyscf import gto, scf
38+
39+
# input is just like any other PySCF script
40+
mol = gto.M(
41+
atom = '''O 0.000000 -0.075791844 0.000000
42+
H 0.866811829 0.601435779 0.000000
43+
H -0.866811829 0.601435779 0.000000
44+
''',
45+
basis = 'augccpvtz',
46+
symmetry = False,
47+
charge = 1,
48+
spin = 1
49+
)
50+
mf = scf.ROHF(mol)
51+
mf.verbose = 4
52+
mf.kernel() # run the SCF
53+
```
54+
55+
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](https://pubs.acs.org/doi/10.1021/acs.jctc.7b00128). Continuing our example:
56+
57+
```python
58+
from openfermion.resource_estimates.molecule import stability, localize, avas_active_space
59+
60+
# make sure wave function is stable before we proceed
61+
mf = stability(mf)
62+
63+
# localize before automatically selecting active space with AVAS
64+
mf = localize(mf, loc_type='pm') # default is loc_type ='pm' (Pipek-Mezey)
65+
66+
# you can use larger basis for `minao` to select non-valence...here select O 3s and 3p as well
67+
mol, mf = avas_active_space(mf, ao_list=['H 1s', 'O 2s', 'O 2p', 'O 3s', 'O 3p'], minao='ccpvtz')
68+
```
69+
70+
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.
71+
72+
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()`.
73+
74+
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:
75+
76+
```python
77+
from openfermion.resource_estimates import sf
78+
79+
# make pretty SF costing table
80+
sf.generate_costing_table(mf, name='water', rank_range=[20,25,30,35,40,45,50])
81+
```
82+
which outputs to a file called `single_factorization_water.txt`, and contains:
83+
84+
```
85+
Single low rank factorization data for 'water'.
86+
[*] using CAS((5a, 4b), 11o)
87+
[+] E(SCF): -75.63393088
88+
[+] Active space CCSD(T) E(cor): -0.08532629
89+
[+] Active space CCSD(T) E(tot): -75.71925716
90+
============================================================================================================
91+
L ||ERI - SF|| lambda CCSD(T) error (mEh) logical qubits Toffoli count
92+
------------------------------------------------------------------------------------------------------------
93+
20 1.7637e-01 212.7 -2.97 298 4.3e+08
94+
25 5.7546e-02 215.0 1.53 298 4.7e+08
95+
30 2.9622e-02 216.1 0.11 298 5.1e+08
96+
35 1.3728e-02 216.5 -0.07 301 5.5e+08
97+
40 2.1439e-03 216.7 0.00 460 5.8e+08
98+
45 2.8662e-04 216.8 0.00 460 6.0e+08
99+
50 1.1826e-04 216.8 0.00 460 6.2e+08
100+
============================================================================================================
101+
```
102+
103+
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.
104+
105+
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
106+
107+
```python
108+
from openfermion.resource_estimates import df, thc
109+
110+
# make pretty DF costing table
111+
df.generate_costing_table(mf, name='water', thresh_range=[1e-2,5e-3,1e-3,5e-4,1e-4,5e-5,1e-5])
112+
113+
# make pretty THC costing table
114+
# if you want to save each THC result to a file, you can set 'save_thc' to True
115+
thc.generate_costing_table(mf, name='water', nthc_range=[20,25,30,35,40,45,50], save_thc=False)
116+
```
117+
118+
Which generate similar outputs, e.g. the above would generate tables in `double_factorization_water.txt` and `thc_factorization_water.txt`.
119+
120+
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
121+
122+
```python
123+
factorized_eris, df_factors, _, _ = df.factorize(mf._eri, cutoff_threshhold)
124+
df_lambda = df.compute_lambda(mf, df_factors)
125+
_, number_toffolis, num_logical_qubits = df.compute_cost(num_spin_orbitals, df_lambda, *args)
126+
```
127+
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,
128+
129+
```python
130+
sf.factorize()
131+
df.factorize()
132+
thc.factorize()
133+
```
134+
135+
are all valid, as are the methods `compute_lambda()` and `compute_cost()` for the factorizations.
136+
137+
138+
For THC factorization, it also requires [BTAS](https://github.com/ValeevGroup/BTAS) and the [PyBTAS](https://github.com/ncrubin/pybtas) wrapper, which require their own installation + depends.
139+
140+
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.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#coverage:ignore
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
#coverage: ignore
14+
import pytest
15+
16+
try:
17+
import pyscf
18+
except ImportError:
19+
pytest.skip('Need pyscf for resource estimates', allow_module_level=True)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#coverage:ignore
2+
# Copyright 2020 Google LLC
3+
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from .compute_lambda_df import compute_lambda
17+
from .compute_cost_df import compute_cost
18+
from .factorize_df import factorize
19+
from .generate_costing_table_df import generate_costing_table

0 commit comments

Comments
 (0)