Skip to content

Commit

Permalink
Update DM21 pinned requirements and bazel config for compiling functi…
Browse files Browse the repository at this point in the history
…onal to C++.

PiperOrigin-RevId: 505176617
  • Loading branch information
jsspencer authored and diegolascasas committed Jan 31, 2023
1 parent c7e2ef2 commit cb555c2
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 163 deletions.
324 changes: 204 additions & 120 deletions density_functional_approximation_dm21/.bazelrc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions density_functional_approximation_dm21/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.3.0
34 changes: 16 additions & 18 deletions density_functional_approximation_dm21/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ be found in the paper (reference below). Note that the results in our paper also
include D3 corrections, which must be
[included separately](https://pyscf.org/user/dft.html#dispersion-corrections).


### Best practices for using the neural functionals.

In this section, we suggest some tips for using the neural functionals in a way
similar to how they were used for benchmarking in the paper. The tensorflow
network that we used is running at single precision, and as such it is very
hard to converge calculations to the high convergence thresholds which are
default in pyscf. For example, the following script should allow users to
run an atomization energy calculation for methane.
network that we used is running at single precision, and as such it is very hard
to converge calculations to the high convergence thresholds which are default in
pyscf. For example, the following script should allow users to run an
atomization energy calculation for methane.

```python
import density_functional_approximation_dm21 as dm21
Expand Down Expand Up @@ -178,17 +177,16 @@ print({'CH4': energies[0], 'C': energies[1], 'H': energies[2]})
```

This script should produce three energies (in Hartrees) for the water molecule
and the two atoms of
`{'CH4': -40.51785372584538, 'C': -37.84542045526023, 'H': -0.5011533955627797}`
, this leads to an atomization energy of 419.06 kcal/mol, which is then
corrected with the D3(BJ) correction for methane (1.20 kcal/mol) to yield a
predicted atomization energy of 420.26 kcal/mol. Comparing this to the
literature value of 420.42, leads us to deduce an error of around 0.2 kcal/mol.

It should also be noted that if a closed shell system is run unrestricted it
can give a small difference between spin densities and eigenvalues with a
negligible effect on the energy.
and the two atoms of `{'CH4': -40.51785372584538, 'C': -37.84542045526023, 'H':
-0.5011533955627797}` , this leads to an atomization energy of 419.06 kcal/mol,
which is then corrected with the D3(BJ) correction for methane (1.20 kcal/mol)
to yield a predicted atomization energy of 420.26 kcal/mol. Comparing this to
the literature value of 420.42, leads us to deduce an error of around 0.2
kcal/mol.

It should also be noted that if a closed shell system is run unrestricted it can
give a small difference between spin densities and eigenvalues with a negligible
effect on the energy.

## Using DM21 from C++

Expand All @@ -210,18 +208,18 @@ library is provided in `cc/dm21_aot_compiled_example.cc`. This requires a
link-time dependency on parts of the `xla_compiled_cpu_runtime_standalone`
library, which are not included in the compiled functional library. The easiest
way to build this is to use [Bazel](https://bazel.build). The first step is to
[install Bazel](https://docs.bazel.build/versions/4.2.0/install.html).
[install Bazel](https://docs.bazel.build/versions/5.3.0/install.html).
[Bazelisk](https://docs.bazel.build/versions/main/install-bazelisk.html) is
another way to install Bazel if a native installer is not available. The
following has been tested with Bazel 4.2.0. It is best to continue working
following has been tested with Bazel 5.3.0. It is best to continue working
inside a virtual environment.

Assuming the above installation steps using `git clone` have been followed, and
`Bazel` has been installed, the example can be built and run using:

```
pip install -r requirements_aot_compilation.txt
bazel run --experimental_repo_remote_exec :run_dm21_aot_compiled_example
bazel run --experimental_cc_shared_library --experimental_repo_remote_exec :run_dm21_aot_compiled_example
```

where the `pip install` command is only required if a fresh virtual environment
Expand Down
17 changes: 4 additions & 13 deletions density_functional_approximation_dm21/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,16 @@ pip_install(

http_archive(
name = "io_abseil_py",
strip_prefix = "abseil-py-pypi-v0.15.0",
urls = ["https://github.com/abseil/abseil-py/archive/pypi-v0.15.0.tar.gz"],
)

http_archive(
name = "six_archive",
build_file = "@io_abseil_py//third_party:six.BUILD",
strip_prefix = "six-1.12.0",
urls = [
"https://pypi.python.org/packages/source/s/six/six-1.12.0.tar.gz",
],
strip_prefix = "abseil-py-1.4.0",
urls = ["https://github.com/abseil/abseil-py/archive/refs/tags/v1.4.0.tar.gz"],
)

http_archive(
name = "org_tensorflow",
patch_args = ["-p1"],
patches = ["tf_bazel.patch"],
strip_prefix = "tensorflow-2.10.0",
urls = ["https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.10.0.tar.gz"],
strip_prefix = "tensorflow-2.11.0",
urls = ["https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.11.0.tar.gz"],
)

# The cascade of load() statements and tf_workspace?() calls works around the
Expand Down
23 changes: 18 additions & 5 deletions density_functional_approximation_dm21/external/tf_bazel.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,36 @@ Subject: [PATCH] Set dependencies for saved_model_compile_aot rule,
tensorflow, and absl version.

---
tensorflow/compiler/tf2xla/BUILD | 2 +-
tensorflow/python/tools/tools.bzl | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
tensorflow/compiler/tf2xla/BUILD | 2 +-
tensorflow/compiler/xla/mlir/ir/runtime/BUILD | 1 +
tensorflow/python/tools/tools.bzl | 4 ++--
3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/tensorflow/compiler/tf2xla/BUILD b/tensorflow/compiler/tf2xla/BUILD
index cfe63b16675..cd273aaf29e 100644
--- a/tensorflow/compiler/tf2xla/BUILD
+++ b/tensorflow/compiler/tf2xla/BUILD
@@ -235,7 +235,7 @@ cc_library(
copts = runtime_copts() + tf_openmp_copts(),
features = ["fully_static_link"],
"-parse_headers",
],
linkstatic = 1,
- visibility = [":friends"],
+ visibility = ["//visibility:public"],
# Note, we specifically removed MKL and multithreaded dependencies so the
# standalone does not require the MKL binary blob or threading libraries.
#
diff --git a/tensorflow/compiler/xla/mlir/ir/runtime/BUILD b/tensorflow/compiler/xla/mlir/ir/runtime/BUILD
index 8c693fa5d49..bf95a3de622 100644
--- a/tensorflow/compiler/xla/mlir/ir/runtime/BUILD
+++ b/tensorflow/compiler/xla/mlir/ir/runtime/BUILD
@@ -90,6 +90,7 @@ cc_library(
"rt_ops.h",
],
compatible_with = get_compatible_with_cloud(),
+ visibility = ["//visibility:public"],
deps = [
":rt_inc_gen",
"//tensorflow/compiler/xla/runtime:constraints",
diff --git a/tensorflow/python/tools/tools.bzl b/tensorflow/python/tools/tools.bzl
index db886746006..bc597e29de9 100644
--- a/tensorflow/python/tools/tools.bzl
Expand Down
10 changes: 5 additions & 5 deletions density_functional_approximation_dm21/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
absl-py==0.13.0
attrs==21.2.0
h5py==3.7.0
numpy==1.23.4
absl-py==1.4.0
attrs==22.2.0
h5py==3.8.0
numpy==1.24.1
pyscf==2.1.1
pytest==6.2.4
scipy==1.9.3
tensorflow==2.10.0
tensorflow==2.11.0
tensorflow-hub==0.12.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Keras-Preprocessing==1.1.2
numpy==1.23.4
tensorflow-estimator==2.10.0
numpy==1.24.1
tensorflow-estimator==2.11.0

0 comments on commit cb555c2

Please sign in to comment.