Skip to content

Commit b74f60c

Browse files
author
corochann
committed
fix flake8
1 parent 35f6709 commit b74f60c

File tree

115 files changed

+394
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+394
-372
lines changed

chainer_chemistry/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'A module chainer_chemistry.datasets was not imported, '
1010
'probably because RDKit is not installed. '
1111
'To install RDKit, please follow instruction in '
12-
'https://github.com/pfnet-research/chainer-chemistry#installation.',
12+
'https://github.com/pfnet-research/chainer-chemistry#installation.', # NOQA
1313
UserWarning)
1414
else:
1515
raise(e)
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
from chainer_chemistry.dataset.converters.concat_mols import concat_mols # NOQA
2-
from chainer_chemistry.dataset.converters.megnet_converter import megnet_converter # NOQA
3-
from chainer_chemistry.dataset.converters.cgcnn_converter import cgcnn_converter # NOQA
4-
5-
converter_method_dict = {
6-
'ecfp': concat_mols,
7-
'nfp': concat_mols,
8-
'nfp_gwm': concat_mols,
9-
'ggnn': concat_mols,
10-
'ggnn_gwm': concat_mols,
11-
'gin': concat_mols,
12-
'gin_gwm': concat_mols,
13-
'schnet': concat_mols,
14-
'weavenet': concat_mols,
15-
'relgcn': concat_mols,
16-
'rsgcn': concat_mols,
17-
'rsgcn_gwm': concat_mols,
18-
'relgat': concat_mols,
19-
'gnnfilm': concat_mols,
20-
'megnet': megnet_converter,
21-
'cgcnn': cgcnn_converter
22-
}
1+
from chainer_chemistry.dataset.converters.cgcnn_converter import cgcnn_converter # NOQA
2+
from chainer_chemistry.dataset.converters.concat_mols import concat_mols # NOQA
3+
from chainer_chemistry.dataset.converters.megnet_converter import megnet_converter # NOQA
4+
5+
converter_method_dict = {
6+
'ecfp': concat_mols,
7+
'nfp': concat_mols,
8+
'nfp_gwm': concat_mols,
9+
'ggnn': concat_mols,
10+
'ggnn_gwm': concat_mols,
11+
'gin': concat_mols,
12+
'gin_gwm': concat_mols,
13+
'schnet': concat_mols,
14+
'weavenet': concat_mols,
15+
'relgcn': concat_mols,
16+
'rsgcn': concat_mols,
17+
'rsgcn_gwm': concat_mols,
18+
'relgat': concat_mols,
19+
'gnnfilm': concat_mols,
20+
'megnet': megnet_converter,
21+
'cgcnn': cgcnn_converter
22+
}

chainer_chemistry/dataset/converters/cgcnn_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import numpy
22

33
import chainer
4-
from chainer import functions
54
from chainer.dataset.convert import to_device
5+
from chainer import functions
66

77

88
@chainer.dataset.converter()
Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
import chainer
2-
3-
4-
@chainer.dataset.converter()
5-
def concat_mols(batch, device=None, padding=0):
6-
"""Concatenates a list of molecules into array(s).
7-
8-
This function converts an "array of tuples" into a "tuple of arrays".
9-
Specifically, given a list of examples each of which consists of
10-
a list of elements, this function first makes an array
11-
by taking the element in the same position from each example
12-
and concatenates them along the newly-inserted first axis
13-
(called `batch dimension`) into one array.
14-
It repeats this for all positions and returns the resulting arrays.
15-
16-
The output type depends on the type of examples in ``batch``.
17-
For instance, consider each example consists of two arrays ``(x, y)``.
18-
Then, this function concatenates ``x`` 's into one array, and ``y`` 's
19-
into another array, and returns a tuple of these two arrays. Another
20-
example: consider each example is a dictionary of two entries whose keys
21-
are ``'x'`` and ``'y'``, respectively, and values are arrays. Then, this
22-
function concatenates ``x`` 's into one array, and ``y`` 's into another
23-
array, and returns a dictionary with two entries ``x`` and ``y`` whose
24-
values are the concatenated arrays.
25-
26-
When the arrays to concatenate have different shapes, the behavior depends
27-
on the ``padding`` value. If ``padding`` is ``None``, it raises an error.
28-
Otherwise, it builds an array of the minimum shape that the
29-
contents of all arrays can be substituted to. The padding value is then
30-
used to the extra elements of the resulting arrays.
31-
32-
The current implementation is identical to
33-
:func:`~chainer.dataset.concat_examples` of Chainer, except the default
34-
value of the ``padding`` option is changed to ``0``.
35-
36-
.. admonition:: Example
37-
38-
>>> import numpy
39-
>>> from chainer_chemistry.dataset.converters import concat_mols
40-
>>> x0 = numpy.array([1, 2])
41-
>>> x1 = numpy.array([4, 5, 6])
42-
>>> dataset = [x0, x1]
43-
>>> results = concat_mols(dataset)
44-
>>> print(results)
45-
[[1 2 0]
46-
[4 5 6]]
47-
48-
.. seealso:: :func:`chainer.dataset.concat_examples`
49-
50-
Args:
51-
batch (list):
52-
A list of examples. This is typically given by a dataset
53-
iterator.
54-
device (int):
55-
Device ID to which each array is sent. Negative value
56-
indicates the host memory (CPU). If it is omitted, all arrays are
57-
left in the original device.
58-
padding:
59-
Scalar value for extra elements. If this is None (default),
60-
an error is raised on shape mismatch. Otherwise, an array of
61-
minimum dimensionalities that can accommodate all arrays is
62-
created, and elements outside of the examples are padded by this
63-
value.
64-
65-
Returns:
66-
Array, a tuple of arrays, or a dictionary of arrays:
67-
The type depends on the type of each example in the batch.
68-
"""
69-
return chainer.dataset.concat_examples(batch, device, padding=padding)
1+
import chainer
2+
3+
4+
@chainer.dataset.converter()
5+
def concat_mols(batch, device=None, padding=0):
6+
"""Concatenates a list of molecules into array(s).
7+
8+
This function converts an "array of tuples" into a "tuple of arrays".
9+
Specifically, given a list of examples each of which consists of
10+
a list of elements, this function first makes an array
11+
by taking the element in the same position from each example
12+
and concatenates them along the newly-inserted first axis
13+
(called `batch dimension`) into one array.
14+
It repeats this for all positions and returns the resulting arrays.
15+
16+
The output type depends on the type of examples in ``batch``.
17+
For instance, consider each example consists of two arrays ``(x, y)``.
18+
Then, this function concatenates ``x`` 's into one array, and ``y`` 's
19+
into another array, and returns a tuple of these two arrays. Another
20+
example: consider each example is a dictionary of two entries whose keys
21+
are ``'x'`` and ``'y'``, respectively, and values are arrays. Then, this
22+
function concatenates ``x`` 's into one array, and ``y`` 's into another
23+
array, and returns a dictionary with two entries ``x`` and ``y`` whose
24+
values are the concatenated arrays.
25+
26+
When the arrays to concatenate have different shapes, the behavior depends
27+
on the ``padding`` value. If ``padding`` is ``None``, it raises an error.
28+
Otherwise, it builds an array of the minimum shape that the
29+
contents of all arrays can be substituted to. The padding value is then
30+
used to the extra elements of the resulting arrays.
31+
32+
The current implementation is identical to
33+
:func:`~chainer.dataset.concat_examples` of Chainer, except the default
34+
value of the ``padding`` option is changed to ``0``.
35+
36+
.. admonition:: Example
37+
38+
>>> import numpy
39+
>>> from chainer_chemistry.dataset.converters import concat_mols
40+
>>> x0 = numpy.array([1, 2])
41+
>>> x1 = numpy.array([4, 5, 6])
42+
>>> dataset = [x0, x1]
43+
>>> results = concat_mols(dataset)
44+
>>> print(results)
45+
[[1 2 0]
46+
[4 5 6]]
47+
48+
.. seealso:: :func:`chainer.dataset.concat_examples`
49+
50+
Args:
51+
batch (list):
52+
A list of examples. This is typically given by a dataset
53+
iterator.
54+
device (int):
55+
Device ID to which each array is sent. Negative value
56+
indicates the host memory (CPU). If it is omitted, all arrays are
57+
left in the original device.
58+
padding:
59+
Scalar value for extra elements. If this is None (default),
60+
an error is raised on shape mismatch. Otherwise, an array of
61+
minimum dimensionalities that can accommodate all arrays is
62+
created, and elements outside of the examples are padded by this
63+
value.
64+
65+
Returns:
66+
Array, a tuple of arrays, or a dictionary of arrays:
67+
The type depends on the type of each example in the batch.
68+
"""
69+
return chainer.dataset.concat_examples(batch, device, padding=padding)
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
import chainer
2-
from chainer.dataset.convert import to_device
3-
4-
5-
@chainer.dataset.converter()
6-
def megnet_converter(batch, device=None, padding=0):
7-
"""MEGNet converter"""
8-
if len(batch) == 0:
9-
raise ValueError("batch is empty")
10-
11-
atom_feat, pair_feat, global_feat, target = [], [], [], []
12-
atom_idx, pair_idx, start_idx, end_idx = [], [], [], []
13-
batch_size = len(batch)
14-
current_atom_idx = 0
15-
for i in range(batch_size):
16-
element = batch[i]
17-
n_atom = element[0].shape[0]
18-
n_pair = element[1].shape[0]
19-
atom_feat.extend(element[0])
20-
pair_feat.extend(element[1])
21-
global_feat.append(element[2])
22-
atom_idx.extend([i]*n_atom)
23-
pair_idx.extend([i]*n_pair)
24-
start_idx.extend(element[3][0] + current_atom_idx)
25-
end_idx.extend(element[3][1] + current_atom_idx)
26-
target.append(element[4])
27-
current_atom_idx += n_atom
28-
29-
xp = device.xp
30-
atom_feat = to_device(device, xp.asarray(atom_feat))
31-
pair_feat = to_device(device, xp.asarray(pair_feat))
32-
global_feat = to_device(device, xp.asarray(global_feat))
33-
atom_idx = to_device(device, xp.asarray(atom_idx))
34-
pair_idx = to_device(device, xp.asarray(pair_idx))
35-
start_idx = to_device(device, xp.asarray(start_idx))
36-
end_idx = to_device(device, xp.asarray(end_idx))
37-
target = to_device(device, xp.asarray(target))
38-
result = (atom_feat, pair_feat, global_feat, atom_idx, pair_idx,
39-
start_idx, end_idx, target)
40-
41-
return result
1+
import chainer
2+
from chainer.dataset.convert import to_device
3+
4+
5+
@chainer.dataset.converter()
6+
def megnet_converter(batch, device=None, padding=0):
7+
"""MEGNet converter"""
8+
if len(batch) == 0:
9+
raise ValueError("batch is empty")
10+
11+
atom_feat, pair_feat, global_feat, target = [], [], [], []
12+
atom_idx, pair_idx, start_idx, end_idx = [], [], [], []
13+
batch_size = len(batch)
14+
current_atom_idx = 0
15+
for i in range(batch_size):
16+
element = batch[i]
17+
n_atom = element[0].shape[0]
18+
n_pair = element[1].shape[0]
19+
atom_feat.extend(element[0])
20+
pair_feat.extend(element[1])
21+
global_feat.append(element[2])
22+
atom_idx.extend([i]*n_atom)
23+
pair_idx.extend([i]*n_pair)
24+
start_idx.extend(element[3][0] + current_atom_idx)
25+
end_idx.extend(element[3][1] + current_atom_idx)
26+
target.append(element[4])
27+
current_atom_idx += n_atom
28+
29+
xp = device.xp
30+
atom_feat = to_device(device, xp.asarray(atom_feat))
31+
pair_feat = to_device(device, xp.asarray(pair_feat))
32+
global_feat = to_device(device, xp.asarray(global_feat))
33+
atom_idx = to_device(device, xp.asarray(atom_idx))
34+
pair_idx = to_device(device, xp.asarray(pair_idx))
35+
start_idx = to_device(device, xp.asarray(start_idx))
36+
end_idx = to_device(device, xp.asarray(end_idx))
37+
target = to_device(device, xp.asarray(target))
38+
result = (atom_feat, pair_feat, global_feat, atom_idx, pair_idx,
39+
start_idx, end_idx, target)
40+
41+
return result

chainer_chemistry/dataset/graph_dataset/base_graph_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy
2+
23
import chainer
34

45

chainer_chemistry/dataset/graph_dataset/base_graph_dataset.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import chainer
21
import numpy
2+
3+
import chainer
34
from chainer._backend import Device
4-
from chainer_chemistry.dataset.graph_dataset.base_graph_data import \
5-
BaseGraphData
5+
from chainer_chemistry.dataset.graph_dataset.base_graph_data import BaseGraphData # NOQA
66
from chainer_chemistry.dataset.graph_dataset.feature_converters \
77
import batch_with_padding, batch_without_padding, concat, shift_concat, \
8-
concat_with_padding, shift_concat_with_padding
8+
concat_with_padding, shift_concat_with_padding # NOQA
99

1010

1111
class BaseGraphDataset(object):
@@ -33,6 +33,7 @@ def register_feature(self, key, batch_method, skip_if_none=True):
3333

3434
def update_feature(self, key, batch_method):
3535
"""Update batch method of the feature
36+
3637
Args:
3738
key (str): name of the feature
3839
batch_method (function): batch method

chainer_chemistry/dataset/graph_dataset/feature_converters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import numpy
2+
23
from chainer.dataset.convert import _concat_arrays
34

45

chainer_chemistry/dataset/indexer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ def _extract_feature(self, data_index, j):
169169
if isinstance(data_index[0], (bool, numpy.bool, numpy.bool_)):
170170
# Access by bool flag list
171171
if len(data_index) != self.dataset_length:
172-
raise ValueError('Feature index wrong length {} instead of'
173-
' {}'.format(len(data_index),
174-
self.dataset_length))
172+
raise ValueError(
173+
'Feature index wrong length {} instead of'
174+
' {}'.format(len(data_index),
175+
self.dataset_length))
175176
data_index = numpy.argwhere(data_index).ravel()
176177

177178
res = [self.extract_feature(i, j) for i in data_index]

chainer_chemistry/dataset/networkx_preprocessors/base_networkx.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import numpy
21
import networkx
2+
import numpy
3+
34
import chainer
45
from chainer_chemistry.dataset.graph_dataset.base_graph_dataset import PaddingGraphDataset, SparseGraphDataset # NOQA
56
from chainer_chemistry.dataset.graph_dataset.base_graph_data import PaddingGraphData, SparseGraphData # NOQA
67
from chainer_chemistry.dataset.graph_dataset.feature_converters import batch_without_padding # NOQA
78

89

9-
class BaseNetworkxPreprocessor():
10+
class BaseNetworkxPreprocessor(object):
1011
"""Base class to preprocess `Networkx::Graph` object"""
1112

1213
def __init__(self, *args, **kwargs):
@@ -34,9 +35,9 @@ def get_y(self, graph):
3435

3536

3637
class BasePaddingNetworkxPreprocessor(BaseNetworkxPreprocessor):
37-
"""Base class to preprocess `Networkx::Graph` object into
38-
`PaddingGraphDataset`
39-
"""
38+
"""Base class to preprocess `Networkx::Graph` into `PaddingGraphDataset`
39+
40+
""" # NOQA
4041

4142
def __init__(self, use_coo=False, *args, **kwargs):
4243
self.use_coo = use_coo
@@ -105,8 +106,8 @@ def create_dataset(self, graph_list):
105106

106107

107108
class BaseSparseNetworkxPreprocessor(BaseNetworkxPreprocessor):
108-
"""Base class to preprocess `Networkx::Graph` object into
109-
`SparseGraphDataset`
109+
"""Base class to preprocess `Networkx::Graph` into `SparseGraphDataset`
110+
110111
"""
111112

112113
def construct_data(self, graph):

0 commit comments

Comments
 (0)