Skip to content

Commit 7884817

Browse files
authored
[PBC Resources Estimates 4/4] Add costing functions (#824)
* Add k-point THC code. * Add k-thc notebook. * Add utilities. * Add reference data. * Add missing __init__ * Add missing init / skipifs. * Fix formatting. * Resolve review comments. * Address comments. * Remove utils. * No more utils. * More review comments. * Fix formatting. * Formatting + add map to gvec_logic. * Fix import issues. * Add utility classes to handler different PBC Hamiltonian factorizations. Add inits. * No more utils. * Tidyup. * Fix formatting. * Add functionality to compute PBC lambda values. * Fix formatting and docstrings. * Fix whitespace. * Add costing PBC costing notebooks. * Add utility costing functions. * Make costing into package and add notebook. * Add missing utilities. * Refactor. * Fix tests. * Fix imports and whitespace. * Fix up some merge issues. * Mark slow test slow. * Remove file. * Add missing skipif. * Add missing import. * Address comments. * Fix formatting. * Fix lint /import errors. * Fix import.
1 parent 78bba46 commit 7884817

28 files changed

+3220
-8
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Resource Estimation for Periodic Systems
2+
3+
Module `openfermion.resource_estimates.pbc` facilitates fault-tolerant (FT) resource estimates for second-quantized symmetry-adapted Hamiltonians with periodic boundary conditions (PBC).
4+
5+
The module provides symmetry adapted sparse, single, double and tensor hypercontraction representations of the Hamiltonians.
6+
7+
For the methods listed above, there are sub-routines which:
8+
* factorize the two-electron integrals if appropriate
9+
* compute the associated lambda values, `compute_lambda()`
10+
* estimate the number of logical qubits and Toffoli gates required to simulate with this factorization, `compute_cost()`
11+
12+
### Details
13+
14+
Given a pyscf scf calculation of a periodic system with k-points:
15+
16+
```python
17+
from pyscf.pbc import gto, scf
18+
19+
cell = gto.Cell()
20+
cell.atom = '''
21+
C 0.000000000000 0.000000000000 0.000000000000
22+
C 1.685068664391 1.685068664391 1.685068664391
23+
'''
24+
cell.basis = 'gth-szv'
25+
cell.pseudo = 'gth-hf-rev'
26+
cell.a = '''
27+
0.000000000, 3.370137329, 3.370137329
28+
3.370137329, 0.000000000, 3.370137329
29+
3.370137329, 3.370137329, 0.000000000'''
30+
cell.unit = 'B'
31+
cell.verbose = 0
32+
cell.build()
33+
34+
kmesh = [1, 1, 3]
35+
kpts = cell.make_kpts(kmesh)
36+
nkpts = len(kpts)
37+
mf = scf.KRHF(cell, kpts).rs_density_fit()
38+
mf.kernel()
39+
```
40+
41+
then resource estimates for the SF, DF, and THC factorization schemes can be generated a range of cutoffs. For example:
42+
43+
```python
44+
from openfermion.resource_estimates.pbc import sf
45+
46+
costs = sf.generate_costing_table(mf, name='carbon_diamond', naux_cutoffs=[20,25,30,35,40,45,50])
47+
print(costs.to_string(index=False))
48+
```
49+
will generate a `pandas.DataFrame` of resource estimates for the single factorization Hamiltonian (`sf`) and MP2 correlation energies for the range of auxiliary dimension (`naux_cutoffs`).
50+
51+
52+
Note that the automated costing computes the MP2 correlation energy error as a reference point for monitoring the convergence of the factorization with respect to sparsity or the size of auxiliary dimension. MP2 may be a poor model chemistry depending on the system, changing the option `energy_method = "CCSD"` will use CCSD instead, but this may become too expensive as the system size grows.
53+
54+
The philosophy is that all costing methods are captured in the namespace related to the type of factorization. So if one wanted to repeat the costing for DF or THC factorizations, one could do
55+
56+
```python
57+
from openfermion.resource_estimates.pbc import df, thc
58+
59+
# We need to specify eigenvalue threshold for second factorization.
60+
df_cutoffs = [1e-2, 5e-3, 1e-3, 5e-4, 1e-4, 5e-5, 1e-5]
61+
df_table = df.generate_costing_table(
62+
mf,
63+
name='carbon-diamond',
64+
cutoffs=df_cutoffs)
65+
66+
# Specify THC rank parameter we wish to scan over.
67+
# Note THC dimension M = thc_rank_param * N, N = number of spin orbitals in the
68+
# unit cell.
69+
thc_rank_params = [2, 4, 6]
70+
# if you want to save each THC result to a file, you can set 'save_thc' to True
71+
thc_table = thc.generate_costing_table(mf, name='carbon-diamond', thc_rank_params=thc_rank_params)
72+
```
73+
74+
More fine-grained control is given by subroutines that compute the factorization, the lambda values, and the cost estimates.
75+
Further details are provided in a [tutorial](./notebooks/resource_estimates.ipynb). Note the THC factorization is more involved and we refer the reader to [thc-tutorial](../../notebooks/isdf.ipynb) for further details.
76+
77+
Similar to the case of molecular resource estimation, we do not wish to burden all OpenFermion users with these dependencies, and testing with GitHub workflows is disabled. Currently we only check if pyscf is available. If it is then pytest will pick up the pbc module and run the tests. Note the tests can be quite slow due to the cost associated with building the integrals.
78+
79+
## Requirements
80+
Requirements can be found in [resource_estimates.txt](../../../../dev_tools/requirements/deps/resource_estimates.txt)
81+
```
82+
pyscf
83+
jax
84+
jaxlib
85+
ase
86+
```

src/openfermion/resource_estimates/pbc/df/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@
99
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License.
12+
13+
from openfermion.resource_estimates import HAVE_DEPS_FOR_RESOURCE_ESTIMATES
14+
15+
if HAVE_DEPS_FOR_RESOURCE_ESTIMATES:
16+
from .compute_lambda_df import compute_lambda
17+
from .generate_costing_table_df import generate_costing_table
18+
from .df_integrals import DFABKpointIntegrals
19+
from .compute_df_resources import compute_cost

0 commit comments

Comments
 (0)