forked from plumed/plumed2
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
fea6c95
commit 0053e98
Showing
34 changed files
with
383 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
!/tools | ||
!/sasa | ||
!/s2cm | ||
!/pytorch | ||
# These files we just want to ignore completely | ||
tmp | ||
report.txt |
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,2 @@ | ||
include ../scripts/module.make | ||
|
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,14 @@ | ||
#! FIELDS time phi model.node-0 | ||
#! SET min_phi -pi | ||
#! SET max_phi pi | ||
0.000000 -2.85656 -0.281187 | ||
5.000000 -2.29224 -0.750853 | ||
10.000000 -2.13168 -0.846786 | ||
15.000000 -2.92489 -0.215007 | ||
20.000000 -2.56135 -0.548228 | ||
25.000000 -1.10925 -0.895364 | ||
30.000000 1.47871 0.995763 | ||
35.000000 -1.27313 -0.956024 | ||
40.000000 -1.10608 -0.893949 | ||
45.000000 -3.03879 -0.102622 | ||
50.000000 -1.69099 -0.992786 |
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,12 @@ | ||
#! FIELDS time parameter model.node-0 | ||
0.000000 0 -0.9596529007 | ||
5.000000 0 -0.6604691148 | ||
10.000000 0 -0.5319328904 | ||
15.000000 0 -0.9766126275 | ||
20.000000 0 -0.8363288045 | ||
25.000000 0 0.4453351200 | ||
30.000000 0 0.0919610485 | ||
35.000000 0 0.2932883203 | ||
40.000000 0 0.4481694996 | ||
45.000000 0 -0.9947203994 | ||
50.000000 0 -0.1199020892 |
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 @@ | ||
include ../../scripts/test.make |
Binary file not shown.
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,10 @@ | ||
plumed_needs=libtorch | ||
plumed_modules=pytorch | ||
type=driver | ||
arg="--plumed plumed.dat --mf_xtc alanine.xtc" | ||
|
||
# note: model has been previously created with create-pytorch-model.py | ||
# the following crashes in CI | ||
# function plumed_regtest_before(){ | ||
# python create-pytorch-model.py | ||
#} |
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,43 @@ | ||
import torch | ||
print(torch.__version__) | ||
|
||
def my_torch_cv(x): | ||
''' | ||
Here goes the definition of the CV. | ||
Inputs: | ||
x (torch.tensor): input, either scalar or 1-D array | ||
Return: | ||
y (torch.tensor): collective variable (scalar) | ||
''' | ||
# CV definition | ||
y = torch.sin(x) | ||
|
||
return y | ||
|
||
input_size = 1 | ||
|
||
# -- DEFINE INPUT -- | ||
#random | ||
#x = torch.rand(input_size, dtype=torch.float32, requires_grad=True).unsqueeze(0) | ||
#or by choosing the value(s) of the array | ||
x = torch.tensor([0.], dtype=torch.float32, requires_grad=True) | ||
|
||
# -- CALCULATE CV -- | ||
y = my_torch_cv(x) | ||
|
||
# -- CALCULATE DERIVATIVES -- | ||
for yy in y: | ||
dy = torch.autograd.grad(yy, x, create_graph=True) | ||
# -- PRINT -- | ||
print('CV TEST') | ||
print('n_input\t: {}'.format(input_size)) | ||
print('x\t: {}'.format(x)) | ||
print('cv\t: {}'.format(yy)) | ||
print('der\t: {}'.format(dy)) | ||
|
||
# Compile via tracing | ||
traced_cv = torch.jit.trace ( my_torch_cv, example_inputs=x ) | ||
filename='torch_model.pt' | ||
traced_cv.save(filename) | ||
|
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,14 @@ | ||
# vim:ft=plumed | ||
|
||
#define input x | ||
phi: TORSION ATOMS=5,7,9,15 | ||
|
||
#load model computing y=sin(x) | ||
model: PYTORCH_MODEL FILE=torch_model.ptc ARG=phi | ||
|
||
#output derivatives dy/dx | ||
DUMPDERIVATIVES ARG=model.* STRIDE=5 FILE=DERIVATIVES | ||
|
||
#print colvar | ||
PRINT FMT=%g STRIDE=5 FILE=COLVAR ARG=phi,model.* | ||
ENDPLUMED |
Binary file not shown.
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,16 @@ | ||
#! FIELDS time phi psi model.node-0 model.node-1 | ||
#! SET min_phi -pi | ||
#! SET max_phi pi | ||
#! SET min_psi -pi | ||
#! SET max_psi pi | ||
0.000000 -2.85656 2.7909 -0.281187 0.343545 | ||
5.000000 -2.29224 1.14276 -0.750853 0.909781 | ||
10.000000 -2.13168 1.89325 -0.846786 0.94846 | ||
15.000000 -2.92489 2.86227 -0.215007 0.275709 | ||
20.000000 -2.56135 0.91674 -0.548228 0.793622 | ||
25.000000 -1.10925 1.61448 -0.895364 0.999046 | ||
30.000000 1.47871 -1.34139 0.995763 -0.973801 | ||
35.000000 -1.27313 0.919978 -0.956024 0.795588 | ||
40.000000 -1.10608 0.941929 -0.893949 0.808695 | ||
45.000000 -3.03879 -2.43909 -0.102622 -0.646133 | ||
50.000000 -1.69099 1.06944 -0.992786 0.876932 |
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,23 @@ | ||
#! FIELDS time parameter model.node-0 model.node-1 | ||
0.000000 0 -0.9596529007 0.0000000000 | ||
0.000000 1 0.0000000000 -0.9391362667 | ||
5.000000 0 -0.6604691148 0.0000000000 | ||
5.000000 1 0.0000000000 0.4150882959 | ||
10.000000 0 -0.5319328904 0.0000000000 | ||
10.000000 1 0.0000000000 -0.3168977797 | ||
15.000000 0 -0.9766126275 0.0000000000 | ||
15.000000 1 0.0000000000 -0.9612411261 | ||
20.000000 0 -0.8363288045 0.0000000000 | ||
20.000000 1 0.0000000000 0.6084106565 | ||
25.000000 0 0.4453351200 0.0000000000 | ||
25.000000 1 0.0000000000 -0.0436719432 | ||
30.000000 0 0.0919610485 0.0000000000 | ||
30.000000 1 0.0000000000 0.2274037302 | ||
35.000000 0 0.2932883203 0.0000000000 | ||
35.000000 1 0.0000000000 0.6058377624 | ||
40.000000 0 0.4481694996 0.0000000000 | ||
40.000000 1 0.0000000000 0.5882287621 | ||
45.000000 0 -0.9947203994 0.0000000000 | ||
45.000000 1 0.0000000000 -0.7632246017 | ||
50.000000 0 -0.1199020892 0.0000000000 | ||
50.000000 1 0.0000000000 0.4806151688 |
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 @@ | ||
include ../../scripts/test.make |
Binary file not shown.
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,10 @@ | ||
plumed_needs=libtorch | ||
plumed_modules=pytorch | ||
type=driver | ||
arg="--plumed plumed.dat --mf_xtc alanine.xtc" | ||
|
||
# note: model has been previously created with create-pytorch-model.py | ||
# the following crashes in CI | ||
# function plumed_regtest_before(){ | ||
# python create-pytorch-model.py | ||
#} |
45 changes: 45 additions & 0 deletions
45
regtest/pytorch/rt-pytorch_model_2d/create-pytorch-model.py
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,45 @@ | ||
import torch | ||
print(torch.__version__) | ||
|
||
def my_torch_cv(x): | ||
''' | ||
Here goes the definition of the CV. | ||
Inputs: | ||
x (torch.tensor): input, either scalar or 1-D array | ||
Return: | ||
y (torch.tensor): collective variable (scalar) | ||
''' | ||
# CV definition | ||
#y1 = torch.sin(x) | ||
#y2 = torch.cos(x) | ||
#y = torch.cat((y1,y2)) | ||
y = torch.sin(x) | ||
return y | ||
|
||
input_size = 2 | ||
|
||
# -- DEFINE INPUT -- | ||
#random | ||
#x = torch.rand(input_size, dtype=torch.float32, requires_grad=True).unsqueeze(0) | ||
#or by choosing the value(s) of the array | ||
x = torch.tensor([0.,1.57], dtype=torch.float32, requires_grad=True) | ||
|
||
# -- CALCULATE CV -- | ||
y = my_torch_cv(x) | ||
|
||
# -- CALCULATE DERIVATIVES -- | ||
for yy in y: | ||
dy = torch.autograd.grad(yy, x, create_graph=True) | ||
# -- PRINT -- | ||
print('CV TEST') | ||
print('n_input\t: {}'.format(input_size)) | ||
print('x\t: {}'.format(x)) | ||
print('cv\t: {}'.format(yy)) | ||
print('der\t: {}'.format(dy)) | ||
|
||
# Compile via tracing | ||
traced_cv = torch.jit.trace ( my_torch_cv, example_inputs=x ) | ||
filename='torch_model.pt' | ||
traced_cv.save(filename) | ||
|
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,15 @@ | ||
# vim:ft=plumed | ||
|
||
#define input x | ||
phi: TORSION ATOMS=5,7,9,15 | ||
psi: TORSION ATOMS=7,9,15,17 | ||
|
||
#load model computing [sin(x),cos(x)] | ||
model: PYTORCH_MODEL FILE=torch_model.ptc ARG=phi,psi | ||
|
||
#output derivatives dy/dx | ||
DUMPDERIVATIVES ARG=model.* STRIDE=5 FILE=DERIVATIVES | ||
|
||
#print colvar | ||
PRINT FMT=%g STRIDE=5 FILE=COLVAR ARG=phi,psi,model.* | ||
ENDPLUMED |
Binary file not shown.
14 changes: 14 additions & 0 deletions
14
regtest/pytorch/rt-pytorch_model_derivatives/COLVAR.reference
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,14 @@ | ||
#! FIELDS time phi model.node-0 sinphi | ||
#! SET min_phi -pi | ||
#! SET max_phi pi | ||
0.000000 -2.85656 -0.281187 -0.281187 | ||
5.000000 -2.29224 -0.750853 -0.750853 | ||
10.000000 -2.13168 -0.846786 -0.846787 | ||
15.000000 -2.92489 -0.215007 -0.215006 | ||
20.000000 -2.56135 -0.548228 -0.548228 | ||
25.000000 -1.10925 -0.895364 -0.895364 | ||
30.000000 1.47871 0.995763 0.995763 | ||
35.000000 -1.27313 -0.956024 -0.956024 | ||
40.000000 -1.10608 -0.893949 -0.893949 | ||
45.000000 -3.03879 -0.102622 -0.102622 | ||
50.000000 -1.69099 -0.992786 -0.992786 |
12 changes: 12 additions & 0 deletions
12
regtest/pytorch/rt-pytorch_model_derivatives/DERIVATIVES.reference
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,12 @@ | ||
#! FIELDS time parameter model.node-0 | ||
0.000000 0 -0.95965 | ||
5.000000 0 -0.66047 | ||
10.000000 0 -0.53193 | ||
15.000000 0 -0.97661 | ||
20.000000 0 -0.83633 | ||
25.000000 0 0.44534 | ||
30.000000 0 0.09196 | ||
35.000000 0 0.29329 | ||
40.000000 0 0.44817 | ||
45.000000 0 -0.99472 | ||
50.000000 0 -0.11990 |
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 @@ | ||
include ../../scripts/test.make |
Binary file not shown.
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,10 @@ | ||
plumed_needs=libtorch | ||
plumed_modules=pytorch | ||
type=driver | ||
arg="--plumed plumed.dat --mf_xtc alanine.xtc" | ||
|
||
# note: model has been previously created with create-pytorch-model.py | ||
# the following crashes in CI | ||
# function plumed_regtest_before(){ | ||
# python create-pytorch-model.py | ||
#} |
43 changes: 43 additions & 0 deletions
43
regtest/pytorch/rt-pytorch_model_derivatives/create-pytorch-model.py
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,43 @@ | ||
import torch | ||
print(torch.__version__) | ||
|
||
def my_torch_cv(x): | ||
''' | ||
Here goes the definition of the CV. | ||
Inputs: | ||
x (torch.tensor): input, either scalar or 1-D array | ||
Return: | ||
y (torch.tensor): collective variable (scalar) | ||
''' | ||
# CV definition | ||
y = torch.sin(x) | ||
|
||
return y | ||
|
||
input_size = 1 | ||
|
||
# -- DEFINE INPUT -- | ||
#random | ||
#x = torch.rand(input_size, dtype=torch.float32, requires_grad=True).unsqueeze(0) | ||
#or by choosing the value(s) of the array | ||
x = torch.tensor([0.], dtype=torch.float32, requires_grad=True) | ||
|
||
# -- CALCULATE CV -- | ||
y = my_torch_cv(x) | ||
|
||
# -- CALCULATE DERIVATIVES -- | ||
for yy in y: | ||
dy = torch.autograd.grad(yy, x, create_graph=True) | ||
# -- PRINT -- | ||
print('CV TEST') | ||
print('n_input\t: {}'.format(input_size)) | ||
print('x\t: {}'.format(x)) | ||
print('cv\t: {}'.format(yy)) | ||
print('der\t: {}'.format(dy)) | ||
|
||
# Compile via tracing | ||
traced_cv = torch.jit.trace ( my_torch_cv, example_inputs=x ) | ||
filename='torch_model.pt' | ||
traced_cv.save(filename) | ||
|
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,17 @@ | ||
# vim:ft=plumed | ||
|
||
#define input x | ||
phi: TORSION ATOMS=5,7,9,15 | ||
|
||
#load model computing y=sin(x) | ||
model: PYTORCH_MODEL FILE=torch_model.ptc ARG=phi | ||
#compute sin(x) with python | ||
sinphi: CUSTOM ARG=phi FUNC=sin(x) PERIODIC=NO | ||
|
||
#output derivatives dy/dx (copy the latter to reference file and change header) | ||
DUMPDERIVATIVES ARG=model.* STRIDE=5 FILE=DERIVATIVES FMT=%10.5f | ||
DUMPDERIVATIVES ARG=sinphi STRIDE=5 FILE=DERIVATIVES_REF FMT=%10.5f | ||
|
||
#print colvar | ||
PRINT FMT=%g STRIDE=5 FILE=COLVAR ARG=phi,model.*,sinphi | ||
ENDPLUMED |
Binary file not shown.
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,14 @@ | ||
#! FIELDS time phi model.node-0 | ||
#! SET min_phi -pi | ||
#! SET max_phi pi | ||
0.000000 -2.85656 0.29301 | ||
5.000000 -2.29224 1.13685 | ||
10.000000 -2.13168 1.5919 | ||
15.000000 -2.92489 0.220155 | ||
20.000000 -2.56135 0.655518 | ||
25.000000 -1.10925 -2.01054 | ||
30.000000 1.47871 0.995763 | ||
35.000000 -1.27313 -3.25967 | ||
40.000000 -1.10608 -1.99467 | ||
45.000000 -3.03879 0.103167 | ||
50.000000 -1.69099 8.27997 |
12 changes: 12 additions & 0 deletions
12
regtest/pytorch/rt-pytorch_model_script/DERIVATIVES.reference
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,12 @@ | ||
#! FIELDS time parameter model.node-0 | ||
0.000000 0 1.08585 | ||
5.000000 0 2.29242 | ||
10.000000 0 3.53416 | ||
15.000000 0 1.04847 | ||
20.000000 0 1.42970 | ||
25.000000 0 5.04227 | ||
30.000000 0 0.09196 | ||
35.000000 0 11.62547 | ||
40.000000 0 4.97869 | ||
45.000000 0 1.01064 | ||
50.000000 0 69.55791 |
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 @@ | ||
include ../../scripts/test.make |
Binary file not shown.
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,10 @@ | ||
plumed_needs=libtorch | ||
plumed_modules=pytorch | ||
type=driver | ||
arg="--plumed plumed.dat --mf_xtc alanine.xtc" | ||
|
||
# note: model has been previously created with create-pytorch-model.py | ||
# the following crashes in CI | ||
# function plumed_regtest_before(){ | ||
# python create-pytorch-model.py | ||
#} |
28 changes: 28 additions & 0 deletions
28
regtest/pytorch/rt-pytorch_model_script/create-pytorch-model.py
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,28 @@ | ||
import torch | ||
print(torch.__version__) | ||
|
||
def my_torch_cv(x): | ||
''' | ||
Here goes the definition of the CV. | ||
Inputs: | ||
x (torch.tensor): input, either scalar or 1-D array | ||
Return: | ||
y (torch.tensor): collective variable (scalar) | ||
''' | ||
if x > 0: | ||
# CV definition | ||
y = torch.sin(x) | ||
else: | ||
y = torch.tan(x) | ||
|
||
return y | ||
|
||
input_size = 1 | ||
|
||
# Compile via scripting | ||
scripted_cv = torch.jit.script( my_torch_cv ) | ||
|
||
filename='torch_model.pt' | ||
scripted_cv.save(filename) | ||
|
Oops, something went wrong.