Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torchani
Commits
258e6c36
Unverified
Commit
258e6c36
authored
Nov 03, 2021
by
Jinze (Richard) Xue
Committed by
GitHub
Nov 03, 2021
Browse files
cuaev def_pickle (#602)
parent
11f44927
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
tests/test_cuaev.py
tests/test_cuaev.py
+27
-0
torchani/cuaev/cuaev.cpp
torchani/cuaev/cuaev.cpp
+29
-1
No files found.
tests/test_cuaev.py
View file @
258e6c36
...
...
@@ -34,6 +34,18 @@ class TestCUAEVNoGPU(TestCase):
coordinates
=
make_tensor
((
8
,
0
,
3
),
'cpu'
,
torch
.
float32
,
low
=-
5
,
high
=
5
)
self
.
assertIn
(
"cuaev::run"
,
str
(
s
.
graph_for
((
species
,
coordinates
))))
def
testPickle
(
self
):
path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
const_file
=
os
.
path
.
join
(
path
,
'../torchani/resources/ani-1x_8x/rHCNO-5.2R_16-3.5A_a4-8.params'
)
# noqa: E501
consts
=
torchani
.
neurochem
.
Constants
(
const_file
)
aev_computer
=
torchani
.
AEVComputer
(
**
consts
,
use_cuda_extension
=
True
)
tmpfile
=
'/tmp/cuaev.pkl'
with
open
(
tmpfile
,
'wb'
)
as
file
:
pickle
.
dump
(
aev_computer
,
file
)
with
open
(
tmpfile
,
'rb'
)
as
file
:
aev_computer
=
pickle
.
load
(
file
)
os
.
remove
(
tmpfile
)
@
skipIfNoGPU
@
skipIfNoCUAEV
...
...
@@ -140,6 +152,21 @@ class TestCUAEV(TestCase):
self
.
testSimpleDoubleBackward_2
()
self
.
setUp
(
device
=
'cuda:0'
)
def
testPickleCorrectness
(
self
):
ref_aev_computer
=
self
.
cuaev_computer
tmpfile
=
'/tmp/cuaev.pkl'
with
open
(
tmpfile
,
'wb'
)
as
file
:
pickle
.
dump
(
ref_aev_computer
,
file
)
with
open
(
tmpfile
,
'rb'
)
as
file
:
test_aev_computer
=
pickle
.
load
(
file
)
os
.
remove
(
tmpfile
)
coordinates
=
torch
.
rand
([
2
,
50
,
3
],
device
=
self
.
device
)
*
5
species
=
torch
.
randint
(
-
1
,
3
,
(
2
,
50
),
device
=
self
.
device
)
_
,
ref_aev
=
ref_aev_computer
((
species
,
coordinates
))
_
,
test_aev
=
test_aev_computer
((
species
,
coordinates
))
self
.
assertEqual
(
ref_aev
,
test_aev
)
def
testSimpleBackward
(
self
):
coordinates
=
torch
.
tensor
([
[[
0.03192167
,
0.00638559
,
0.01301679
],
...
...
torchani/cuaev/cuaev.cpp
View file @
258e6c36
...
...
@@ -150,7 +150,35 @@ Tensor run_autograd(
TORCH_LIBRARY
(
cuaev
,
m
)
{
m
.
class_
<
CuaevComputer
>
(
"CuaevComputer"
)
.
def
(
torch
::
init
<
double
,
double
,
Tensor
,
Tensor
,
Tensor
,
Tensor
,
Tensor
,
Tensor
,
int64_t
>
());
.
def
(
torch
::
init
<
double
,
double
,
Tensor
,
Tensor
,
Tensor
,
Tensor
,
Tensor
,
Tensor
,
int64_t
>
())
.
def_pickle
(
// __getstate__
[](
const
c10
::
intrusive_ptr
<
CuaevComputer
>&
self
)
->
std
::
vector
<
Tensor
>
{
std
::
vector
<
Tensor
>
state
;
state
.
push_back
(
torch
::
tensor
(
self
->
aev_params
.
Rcr
));
state
.
push_back
(
torch
::
tensor
(
self
->
aev_params
.
Rca
));
state
.
push_back
(
self
->
aev_params
.
EtaR_t
);
state
.
push_back
(
self
->
aev_params
.
ShfR_t
);
state
.
push_back
(
self
->
aev_params
.
EtaA_t
);
state
.
push_back
(
self
->
aev_params
.
Zeta_t
);
state
.
push_back
(
self
->
aev_params
.
ShfA_t
);
state
.
push_back
(
self
->
aev_params
.
ShfZ_t
);
state
.
push_back
(
torch
::
tensor
(
self
->
aev_params
.
num_species
));
return
state
;
},
// __setstate__
[](
std
::
vector
<
Tensor
>
state
)
->
c10
::
intrusive_ptr
<
CuaevComputer
>
{
return
c10
::
make_intrusive
<
CuaevComputer
>
(
state
[
0
].
item
<
double
>
(),
state
[
1
].
item
<
double
>
(),
state
[
2
],
state
[
3
],
state
[
4
],
state
[
5
],
state
[
6
],
state
[
7
],
state
[
8
].
item
<
int64_t
>
());
});
m
.
def
(
"run"
,
run_only_forward
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment