Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
207 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import torch | ||
|
||
|
||
def torch_derivative(fx, x, create_graph=False): | ||
if len(fx.shape) == 2: | ||
fx = fx.unsqueeze(0) | ||
dfdx = [] | ||
flat_fx = fx.reshape(-1) | ||
for i in range(len(flat_fx)): | ||
(grad_x,) = torch.autograd.grad( | ||
flat_fx[i], | ||
x, | ||
torch.ones_like(flat_fx[i]), | ||
retain_graph=True, | ||
create_graph=create_graph, | ||
) | ||
dfdx.append(grad_x) | ||
return torch.stack(dfdx).reshape(fx.shape[2] * x.shape[1], fx.shape[1] * x.shape[2]) | ||
|
||
|
||
def get_derivative_names(property, avail): | ||
if property not in avail: | ||
if property == "forces" and "energy" in avail: | ||
init_property, out_name, derivative = "energy", "forces", -1 | ||
wrt = ["_positions"] | ||
elif property == "hessian" and "forces" in avail: | ||
init_property, out_name, derivative = "forces", "hessian", -1 | ||
wrt = ["_positions"] | ||
elif property == "hessian" and "energy" in avail: | ||
init_property, out_name, derivative = "energy", "hessian", 2 | ||
wrt = ["_positions", "_positions"] | ||
else: | ||
raise ValueError( | ||
"The property {} is not in the available properties of the model : {}.".format( | ||
property, avail | ||
) | ||
) | ||
elif property == "energy" and "energy_U0" in avail: | ||
init_property, out_name, derivative, wrt = "energy_U0", "", 0, [] | ||
else: | ||
init_property, out_name, derivative, wrt = property, "", 0, [] | ||
return init_property, out_name, derivative, wrt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
pip==20.0.2 | ||
wheel==0.34.2 | ||
black==19.10b0 | ||
numpy==1.18.1 | ||
numpy==1.18.2 | ||
torch==1.4.0 | ||
torchvision==0.5.0 | ||
twine==3.1.1 | ||
pytest==5.3.5 | ||
pytest-cov==2.8.1 | ||
pytest-sugar==0.9.2 | ||
coveralls==1.10.0 | ||
coveralls==1.11.1 | ||
schnetpack==0.3 | ||
sphinx==2.4.2 | ||
sphinx==2.4.4 | ||
sphinx-rtd-theme==0.4.3 | ||
m2r==0.2.1 |
Binary file not shown.
Oops, something went wrong.