From b74f60c7fb18a4ef15da8c9f162bf96fb4b3e007 Mon Sep 17 00:00:00 2001 From: corochann Date: Mon, 9 Dec 2019 14:10:47 +0900 Subject: [PATCH] fix flake8 --- chainer_chemistry/__init__.py | 2 +- .../dataset/converters/__init__.py | 44 +++--- .../dataset/converters/cgcnn_converter.py | 2 +- .../dataset/converters/concat_mols.py | 138 +++++++++--------- .../dataset/converters/megnet_converter.py | 82 +++++------ .../dataset/graph_dataset/base_graph_data.py | 1 + .../graph_dataset/base_graph_dataset.py | 9 +- .../graph_dataset/feature_converters.py | 1 + chainer_chemistry/dataset/indexer.py | 7 +- .../networkx_preprocessors/base_networkx.py | 15 +- .../networkx_preprocessors/reddit_coo.py | 2 + .../dataset/parsers/data_frame_parser.py | 3 +- .../dataset/parsers/sdf_file_parser.py | 3 +- .../dataset/preprocessors/__init__.py | 6 +- .../preprocessors/cgcnn_preprocessor.py | 2 +- .../preprocessors/ggnn_preprocessor.py | 13 +- .../dataset/preprocessors/gin_preprocessor.py | 38 +++-- .../preprocessors/gnnfilm_preprocessor.py | 10 +- .../preprocessors/megnet_preprocessor.py | 8 +- .../preprocessors/relgcn_preprocessor.py | 3 +- chainer_chemistry/dataset/utils.py | 2 +- .../datasets/citation_network/citation.py | 2 +- .../datasets/citation_network/citeseer.py | 5 +- .../datasets/citation_network/cora.py | 11 +- chainer_chemistry/datasets/molnet/__init__.py | 2 +- .../datasets/molnet/molnet_config.py | 7 +- .../datasets/molnet/pdbbind_time.py | 3 +- .../datasets/numpy_tuple_dataset.py | 2 +- chainer_chemistry/datasets/reddit/reddit.py | 7 +- chainer_chemistry/functions/__init__.py | 2 +- .../functions/activation/shifted_softplus.py | 2 +- .../functions/evaluation/r2_score.py | 3 + chainer_chemistry/links/__init__.py | 2 +- .../links/connection/graph_mlp.py | 3 +- .../links/readout/cgcnn_readout.py | 2 +- .../links/readout/megnet_readout.py | 2 +- .../links/readout/scatter_ggnn_readout.py | 1 + .../links/readout/schnet_readout.py | 2 +- chainer_chemistry/links/scaler/flow_scaler.py | 1 + .../links/scaler/max_abs_scaler.py | 3 +- .../links/scaler/min_max_scaler.py | 3 +- .../links/scaler/standard_scaler.py | 3 +- .../links/update/cgcnn_update.py | 2 +- .../links/update/gnn_film_update.py | 12 +- .../links/update/megnet_update.py | 2 +- chainer_chemistry/links/update/mpnn_update.py | 2 +- .../links/update/relgcn_update.py | 3 +- .../links/update/schnet_update.py | 7 +- chainer_chemistry/models/__init__.py | 2 +- chainer_chemistry/models/cgcnn.py | 3 +- chainer_chemistry/models/ggnn.py | 2 +- chainer_chemistry/models/gin.py | 6 +- chainer_chemistry/models/gwm/__init__.py | 8 +- chainer_chemistry/models/gwm/gwm.py | 9 +- .../models/gwm/gwm_graph_conv_model.py | 16 +- chainer_chemistry/models/megnet.py | 4 +- chainer_chemistry/models/mpnn.py | 4 +- chainer_chemistry/models/nfp.py | 4 +- chainer_chemistry/models/prediction/base.py | 9 +- .../models/prediction/classifier.py | 1 + .../models/prediction/graph_conv_predictor.py | 2 +- .../models/prediction/node_classifier.py | 8 +- .../models/prediction/regressor.py | 4 +- .../models/prediction/set_up_predictor.py | 10 +- chainer_chemistry/models/relgat.py | 4 +- chainer_chemistry/models/relgcn.py | 16 +- chainer_chemistry/models/rsgcn.py | 3 +- chainer_chemistry/models/weavenet.py | 2 +- .../saliency/calculator/base_calculator.py | 2 +- .../saliency/calculator/calculator_utils.py | 2 +- .../calculator/gradient_calculator.py | 2 +- .../integrated_gradients_calculator.py | 2 +- .../saliency/visualizer/__init__.py | 2 +- .../saliency/visualizer/image_visualizer.py | 4 +- .../saliency/visualizer/mol_visualizer.py | 4 +- .../saliency/visualizer/table_visualizer.py | 2 +- .../saliency/visualizer/visualizer_utils.py | 2 +- .../training/extensions/__init__.py | 4 +- .../training/extensions/auto_print_report.py | 2 +- .../training/extensions/r2_score_evaluator.py | 2 +- chainer_chemistry/utils/__init__.py | 2 +- chainer_chemistry/utils/train_utils.py | 8 +- .../preprocessor_tests/test_common.py | 9 +- .../test_gwm_preprocessor.py | 2 +- .../test_weavenet_preprocessor.py | 2 +- .../activation/test_shifted_softplus.py | 5 +- .../activation/test_softmax.py | 3 - .../test_balanced_serial_iterator.py | 8 +- tests/iterators_tests/test_index_iterator.py | 12 +- .../test_variable_monitor_link_hook.py | 4 +- .../test_shape_transformer_to_2d.py | 2 +- .../readout_tests/test_cgcnn_readout.py | 4 +- .../readout_tests/test_general_readout.py | 2 +- .../readout_tests/test_mpnn_readout.py | 6 +- .../links_tests/readout_tests/test_set2set.py | 6 +- .../scaler_tests/test_flow_scaler.py | 2 +- .../scaler_tests/test_max_abs_scaler.py | 2 +- .../scaler_tests/test_min_max_scaler.py | 2 +- .../scaler_tests/test_standard_scaler.py | 2 +- .../update_tests/test_cgcnn_update.py | 4 +- .../update_tests/test_megnet_update.py | 1 - .../update_tests/test_mpnn_update.py | 2 +- .../update_tests/test_relgat_update.py | 2 +- tests/models_tests/gwm_tests/test_gwm.py | 2 +- .../gwm_tests/test_gwm_graph_conv_model.py | 19 +-- tests/models_tests/test_cgcnn.py | 1 - tests/models_tests/test_ggnn.py | 2 +- tests/models_tests/test_megnet.py | 1 - tests/models_tests/test_nfp.py | 2 +- tests/models_tests/test_relgcn.py | 2 +- .../calculator_tests/test_base_calculator.py | 2 +- .../visualizer_tests/test_image_visualizer.py | 2 +- .../visualizer_tests/test_table_visualizer.py | 3 +- .../test_auto_print_report.py | 1 + tests/utils_tests/test_train_utils.py | 3 +- 115 files changed, 394 insertions(+), 372 deletions(-) diff --git a/chainer_chemistry/__init__.py b/chainer_chemistry/__init__.py index c72bba18..62a2e308 100644 --- a/chainer_chemistry/__init__.py +++ b/chainer_chemistry/__init__.py @@ -9,7 +9,7 @@ 'A module chainer_chemistry.datasets was not imported, ' 'probably because RDKit is not installed. ' 'To install RDKit, please follow instruction in ' - 'https://github.com/pfnet-research/chainer-chemistry#installation.', + 'https://github.com/pfnet-research/chainer-chemistry#installation.', # NOQA UserWarning) else: raise(e) diff --git a/chainer_chemistry/dataset/converters/__init__.py b/chainer_chemistry/dataset/converters/__init__.py index 766f162d..eba6e92c 100644 --- a/chainer_chemistry/dataset/converters/__init__.py +++ b/chainer_chemistry/dataset/converters/__init__.py @@ -1,22 +1,22 @@ -from chainer_chemistry.dataset.converters.concat_mols import concat_mols # NOQA -from chainer_chemistry.dataset.converters.megnet_converter import megnet_converter # NOQA -from chainer_chemistry.dataset.converters.cgcnn_converter import cgcnn_converter # NOQA - -converter_method_dict = { - 'ecfp': concat_mols, - 'nfp': concat_mols, - 'nfp_gwm': concat_mols, - 'ggnn': concat_mols, - 'ggnn_gwm': concat_mols, - 'gin': concat_mols, - 'gin_gwm': concat_mols, - 'schnet': concat_mols, - 'weavenet': concat_mols, - 'relgcn': concat_mols, - 'rsgcn': concat_mols, - 'rsgcn_gwm': concat_mols, - 'relgat': concat_mols, - 'gnnfilm': concat_mols, - 'megnet': megnet_converter, - 'cgcnn': cgcnn_converter -} +from chainer_chemistry.dataset.converters.cgcnn_converter import cgcnn_converter # NOQA +from chainer_chemistry.dataset.converters.concat_mols import concat_mols # NOQA +from chainer_chemistry.dataset.converters.megnet_converter import megnet_converter # NOQA + +converter_method_dict = { + 'ecfp': concat_mols, + 'nfp': concat_mols, + 'nfp_gwm': concat_mols, + 'ggnn': concat_mols, + 'ggnn_gwm': concat_mols, + 'gin': concat_mols, + 'gin_gwm': concat_mols, + 'schnet': concat_mols, + 'weavenet': concat_mols, + 'relgcn': concat_mols, + 'rsgcn': concat_mols, + 'rsgcn_gwm': concat_mols, + 'relgat': concat_mols, + 'gnnfilm': concat_mols, + 'megnet': megnet_converter, + 'cgcnn': cgcnn_converter +} diff --git a/chainer_chemistry/dataset/converters/cgcnn_converter.py b/chainer_chemistry/dataset/converters/cgcnn_converter.py index b1fb7d97..60576fe2 100644 --- a/chainer_chemistry/dataset/converters/cgcnn_converter.py +++ b/chainer_chemistry/dataset/converters/cgcnn_converter.py @@ -1,8 +1,8 @@ import numpy import chainer -from chainer import functions from chainer.dataset.convert import to_device +from chainer import functions @chainer.dataset.converter() diff --git a/chainer_chemistry/dataset/converters/concat_mols.py b/chainer_chemistry/dataset/converters/concat_mols.py index ca55cb15..da92440e 100644 --- a/chainer_chemistry/dataset/converters/concat_mols.py +++ b/chainer_chemistry/dataset/converters/concat_mols.py @@ -1,69 +1,69 @@ -import chainer - - -@chainer.dataset.converter() -def concat_mols(batch, device=None, padding=0): - """Concatenates a list of molecules into array(s). - - This function converts an "array of tuples" into a "tuple of arrays". - Specifically, given a list of examples each of which consists of - a list of elements, this function first makes an array - by taking the element in the same position from each example - and concatenates them along the newly-inserted first axis - (called `batch dimension`) into one array. - It repeats this for all positions and returns the resulting arrays. - - The output type depends on the type of examples in ``batch``. - For instance, consider each example consists of two arrays ``(x, y)``. - Then, this function concatenates ``x`` 's into one array, and ``y`` 's - into another array, and returns a tuple of these two arrays. Another - example: consider each example is a dictionary of two entries whose keys - are ``'x'`` and ``'y'``, respectively, and values are arrays. Then, this - function concatenates ``x`` 's into one array, and ``y`` 's into another - array, and returns a dictionary with two entries ``x`` and ``y`` whose - values are the concatenated arrays. - - When the arrays to concatenate have different shapes, the behavior depends - on the ``padding`` value. If ``padding`` is ``None``, it raises an error. - Otherwise, it builds an array of the minimum shape that the - contents of all arrays can be substituted to. The padding value is then - used to the extra elements of the resulting arrays. - - The current implementation is identical to - :func:`~chainer.dataset.concat_examples` of Chainer, except the default - value of the ``padding`` option is changed to ``0``. - - .. admonition:: Example - - >>> import numpy - >>> from chainer_chemistry.dataset.converters import concat_mols - >>> x0 = numpy.array([1, 2]) - >>> x1 = numpy.array([4, 5, 6]) - >>> dataset = [x0, x1] - >>> results = concat_mols(dataset) - >>> print(results) - [[1 2 0] - [4 5 6]] - - .. seealso:: :func:`chainer.dataset.concat_examples` - - Args: - batch (list): - A list of examples. This is typically given by a dataset - iterator. - device (int): - Device ID to which each array is sent. Negative value - indicates the host memory (CPU). If it is omitted, all arrays are - left in the original device. - padding: - Scalar value for extra elements. If this is None (default), - an error is raised on shape mismatch. Otherwise, an array of - minimum dimensionalities that can accommodate all arrays is - created, and elements outside of the examples are padded by this - value. - - Returns: - Array, a tuple of arrays, or a dictionary of arrays: - The type depends on the type of each example in the batch. - """ - return chainer.dataset.concat_examples(batch, device, padding=padding) +import chainer + + +@chainer.dataset.converter() +def concat_mols(batch, device=None, padding=0): + """Concatenates a list of molecules into array(s). + + This function converts an "array of tuples" into a "tuple of arrays". + Specifically, given a list of examples each of which consists of + a list of elements, this function first makes an array + by taking the element in the same position from each example + and concatenates them along the newly-inserted first axis + (called `batch dimension`) into one array. + It repeats this for all positions and returns the resulting arrays. + + The output type depends on the type of examples in ``batch``. + For instance, consider each example consists of two arrays ``(x, y)``. + Then, this function concatenates ``x`` 's into one array, and ``y`` 's + into another array, and returns a tuple of these two arrays. Another + example: consider each example is a dictionary of two entries whose keys + are ``'x'`` and ``'y'``, respectively, and values are arrays. Then, this + function concatenates ``x`` 's into one array, and ``y`` 's into another + array, and returns a dictionary with two entries ``x`` and ``y`` whose + values are the concatenated arrays. + + When the arrays to concatenate have different shapes, the behavior depends + on the ``padding`` value. If ``padding`` is ``None``, it raises an error. + Otherwise, it builds an array of the minimum shape that the + contents of all arrays can be substituted to. The padding value is then + used to the extra elements of the resulting arrays. + + The current implementation is identical to + :func:`~chainer.dataset.concat_examples` of Chainer, except the default + value of the ``padding`` option is changed to ``0``. + + .. admonition:: Example + + >>> import numpy + >>> from chainer_chemistry.dataset.converters import concat_mols + >>> x0 = numpy.array([1, 2]) + >>> x1 = numpy.array([4, 5, 6]) + >>> dataset = [x0, x1] + >>> results = concat_mols(dataset) + >>> print(results) + [[1 2 0] + [4 5 6]] + + .. seealso:: :func:`chainer.dataset.concat_examples` + + Args: + batch (list): + A list of examples. This is typically given by a dataset + iterator. + device (int): + Device ID to which each array is sent. Negative value + indicates the host memory (CPU). If it is omitted, all arrays are + left in the original device. + padding: + Scalar value for extra elements. If this is None (default), + an error is raised on shape mismatch. Otherwise, an array of + minimum dimensionalities that can accommodate all arrays is + created, and elements outside of the examples are padded by this + value. + + Returns: + Array, a tuple of arrays, or a dictionary of arrays: + The type depends on the type of each example in the batch. + """ + return chainer.dataset.concat_examples(batch, device, padding=padding) diff --git a/chainer_chemistry/dataset/converters/megnet_converter.py b/chainer_chemistry/dataset/converters/megnet_converter.py index 0d26bbae..88ce4d6f 100644 --- a/chainer_chemistry/dataset/converters/megnet_converter.py +++ b/chainer_chemistry/dataset/converters/megnet_converter.py @@ -1,41 +1,41 @@ -import chainer -from chainer.dataset.convert import to_device - - -@chainer.dataset.converter() -def megnet_converter(batch, device=None, padding=0): - """MEGNet converter""" - if len(batch) == 0: - raise ValueError("batch is empty") - - atom_feat, pair_feat, global_feat, target = [], [], [], [] - atom_idx, pair_idx, start_idx, end_idx = [], [], [], [] - batch_size = len(batch) - current_atom_idx = 0 - for i in range(batch_size): - element = batch[i] - n_atom = element[0].shape[0] - n_pair = element[1].shape[0] - atom_feat.extend(element[0]) - pair_feat.extend(element[1]) - global_feat.append(element[2]) - atom_idx.extend([i]*n_atom) - pair_idx.extend([i]*n_pair) - start_idx.extend(element[3][0] + current_atom_idx) - end_idx.extend(element[3][1] + current_atom_idx) - target.append(element[4]) - current_atom_idx += n_atom - - xp = device.xp - atom_feat = to_device(device, xp.asarray(atom_feat)) - pair_feat = to_device(device, xp.asarray(pair_feat)) - global_feat = to_device(device, xp.asarray(global_feat)) - atom_idx = to_device(device, xp.asarray(atom_idx)) - pair_idx = to_device(device, xp.asarray(pair_idx)) - start_idx = to_device(device, xp.asarray(start_idx)) - end_idx = to_device(device, xp.asarray(end_idx)) - target = to_device(device, xp.asarray(target)) - result = (atom_feat, pair_feat, global_feat, atom_idx, pair_idx, - start_idx, end_idx, target) - - return result +import chainer +from chainer.dataset.convert import to_device + + +@chainer.dataset.converter() +def megnet_converter(batch, device=None, padding=0): + """MEGNet converter""" + if len(batch) == 0: + raise ValueError("batch is empty") + + atom_feat, pair_feat, global_feat, target = [], [], [], [] + atom_idx, pair_idx, start_idx, end_idx = [], [], [], [] + batch_size = len(batch) + current_atom_idx = 0 + for i in range(batch_size): + element = batch[i] + n_atom = element[0].shape[0] + n_pair = element[1].shape[0] + atom_feat.extend(element[0]) + pair_feat.extend(element[1]) + global_feat.append(element[2]) + atom_idx.extend([i]*n_atom) + pair_idx.extend([i]*n_pair) + start_idx.extend(element[3][0] + current_atom_idx) + end_idx.extend(element[3][1] + current_atom_idx) + target.append(element[4]) + current_atom_idx += n_atom + + xp = device.xp + atom_feat = to_device(device, xp.asarray(atom_feat)) + pair_feat = to_device(device, xp.asarray(pair_feat)) + global_feat = to_device(device, xp.asarray(global_feat)) + atom_idx = to_device(device, xp.asarray(atom_idx)) + pair_idx = to_device(device, xp.asarray(pair_idx)) + start_idx = to_device(device, xp.asarray(start_idx)) + end_idx = to_device(device, xp.asarray(end_idx)) + target = to_device(device, xp.asarray(target)) + result = (atom_feat, pair_feat, global_feat, atom_idx, pair_idx, + start_idx, end_idx, target) + + return result diff --git a/chainer_chemistry/dataset/graph_dataset/base_graph_data.py b/chainer_chemistry/dataset/graph_dataset/base_graph_data.py index e4ce70c9..8d3552ac 100644 --- a/chainer_chemistry/dataset/graph_dataset/base_graph_data.py +++ b/chainer_chemistry/dataset/graph_dataset/base_graph_data.py @@ -1,4 +1,5 @@ import numpy + import chainer diff --git a/chainer_chemistry/dataset/graph_dataset/base_graph_dataset.py b/chainer_chemistry/dataset/graph_dataset/base_graph_dataset.py index a73cbd7e..e452bb2f 100644 --- a/chainer_chemistry/dataset/graph_dataset/base_graph_dataset.py +++ b/chainer_chemistry/dataset/graph_dataset/base_graph_dataset.py @@ -1,11 +1,11 @@ -import chainer import numpy + +import chainer from chainer._backend import Device -from chainer_chemistry.dataset.graph_dataset.base_graph_data import \ - BaseGraphData +from chainer_chemistry.dataset.graph_dataset.base_graph_data import BaseGraphData # NOQA from chainer_chemistry.dataset.graph_dataset.feature_converters \ import batch_with_padding, batch_without_padding, concat, shift_concat, \ - concat_with_padding, shift_concat_with_padding + concat_with_padding, shift_concat_with_padding # NOQA class BaseGraphDataset(object): @@ -33,6 +33,7 @@ def register_feature(self, key, batch_method, skip_if_none=True): def update_feature(self, key, batch_method): """Update batch method of the feature + Args: key (str): name of the feature batch_method (function): batch method diff --git a/chainer_chemistry/dataset/graph_dataset/feature_converters.py b/chainer_chemistry/dataset/graph_dataset/feature_converters.py index 087765fa..ef153592 100644 --- a/chainer_chemistry/dataset/graph_dataset/feature_converters.py +++ b/chainer_chemistry/dataset/graph_dataset/feature_converters.py @@ -1,4 +1,5 @@ import numpy + from chainer.dataset.convert import _concat_arrays diff --git a/chainer_chemistry/dataset/indexer.py b/chainer_chemistry/dataset/indexer.py index c8535797..4382ef6d 100644 --- a/chainer_chemistry/dataset/indexer.py +++ b/chainer_chemistry/dataset/indexer.py @@ -169,9 +169,10 @@ def _extract_feature(self, data_index, j): if isinstance(data_index[0], (bool, numpy.bool, numpy.bool_)): # Access by bool flag list if len(data_index) != self.dataset_length: - raise ValueError('Feature index wrong length {} instead of' - ' {}'.format(len(data_index), - self.dataset_length)) + raise ValueError( + 'Feature index wrong length {} instead of' + ' {}'.format(len(data_index), + self.dataset_length)) data_index = numpy.argwhere(data_index).ravel() res = [self.extract_feature(i, j) for i in data_index] diff --git a/chainer_chemistry/dataset/networkx_preprocessors/base_networkx.py b/chainer_chemistry/dataset/networkx_preprocessors/base_networkx.py index 38e62d0b..caa98110 100644 --- a/chainer_chemistry/dataset/networkx_preprocessors/base_networkx.py +++ b/chainer_chemistry/dataset/networkx_preprocessors/base_networkx.py @@ -1,12 +1,13 @@ -import numpy import networkx +import numpy + import chainer from chainer_chemistry.dataset.graph_dataset.base_graph_dataset import PaddingGraphDataset, SparseGraphDataset # NOQA from chainer_chemistry.dataset.graph_dataset.base_graph_data import PaddingGraphData, SparseGraphData # NOQA from chainer_chemistry.dataset.graph_dataset.feature_converters import batch_without_padding # NOQA -class BaseNetworkxPreprocessor(): +class BaseNetworkxPreprocessor(object): """Base class to preprocess `Networkx::Graph` object""" def __init__(self, *args, **kwargs): @@ -34,9 +35,9 @@ def get_y(self, graph): class BasePaddingNetworkxPreprocessor(BaseNetworkxPreprocessor): - """Base class to preprocess `Networkx::Graph` object into - `PaddingGraphDataset` - """ + """Base class to preprocess `Networkx::Graph` into `PaddingGraphDataset` + + """ # NOQA def __init__(self, use_coo=False, *args, **kwargs): self.use_coo = use_coo @@ -105,8 +106,8 @@ def create_dataset(self, graph_list): class BaseSparseNetworkxPreprocessor(BaseNetworkxPreprocessor): - """Base class to preprocess `Networkx::Graph` object into - `SparseGraphDataset` + """Base class to preprocess `Networkx::Graph` into `SparseGraphDataset` + """ def construct_data(self, graph): diff --git a/chainer_chemistry/dataset/networkx_preprocessors/reddit_coo.py b/chainer_chemistry/dataset/networkx_preprocessors/reddit_coo.py index 6daff6d1..8d033929 100644 --- a/chainer_chemistry/dataset/networkx_preprocessors/reddit_coo.py +++ b/chainer_chemistry/dataset/networkx_preprocessors/reddit_coo.py @@ -2,6 +2,7 @@ import numpy import scipy + import chainer from chainer_chemistry.dataset.graph_dataset.base_graph_data import PaddingGraphData # NOQA @@ -9,6 +10,7 @@ def get_reddit_coo_data(dirpath): """Temporary function to obtain reddit coo data for GIN + (because it takes to much time to convert it to networkx) Returns: diff --git a/chainer_chemistry/dataset/parsers/data_frame_parser.py b/chainer_chemistry/dataset/parsers/data_frame_parser.py index 56167b1a..a58bf451 100644 --- a/chainer_chemistry/dataset/parsers/data_frame_parser.py +++ b/chainer_chemistry/dataset/parsers/data_frame_parser.py @@ -7,7 +7,6 @@ from chainer_chemistry.dataset.parsers.base_parser import BaseFileParser from chainer_chemistry.dataset.preprocessors.common import MolFeatureExtractionError # NOQA from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA -from chainer_chemistry.datasets.numpy_tuple_dataset import NumpyTupleDataset import traceback @@ -110,7 +109,7 @@ def parse(self, df, return_smiles=False, target_index=None, if return_smiles: smiles_list.append(canonical_smiles) - except MolFeatureExtractionError as e: + except MolFeatureExtractionError as e: # NOQA # This is expected error that extracting feature failed, # skip this molecule. fail_count += 1 diff --git a/chainer_chemistry/dataset/parsers/sdf_file_parser.py b/chainer_chemistry/dataset/parsers/sdf_file_parser.py index 9c9836e1..c6ce5deb 100644 --- a/chainer_chemistry/dataset/parsers/sdf_file_parser.py +++ b/chainer_chemistry/dataset/parsers/sdf_file_parser.py @@ -7,7 +7,6 @@ from chainer_chemistry.dataset.parsers.base_parser import BaseFileParser from chainer_chemistry.dataset.preprocessors.common import MolFeatureExtractionError # NOQA from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA -from chainer_chemistry.datasets.numpy_tuple_dataset import NumpyTupleDataset class SDFFileParser(BaseFileParser): @@ -105,7 +104,7 @@ def parse(self, filepath, return_smiles=False, target_index=None, if return_smiles: smiles_list.append(canonical_smiles) - except MolFeatureExtractionError as e: + except MolFeatureExtractionError as e: # NOQA # This is expected error that extracting feature failed, # skip this molecule. fail_count += 1 diff --git a/chainer_chemistry/dataset/preprocessors/__init__.py b/chainer_chemistry/dataset/preprocessors/__init__.py index 01175e21..b035e14d 100644 --- a/chainer_chemistry/dataset/preprocessors/__init__.py +++ b/chainer_chemistry/dataset/preprocessors/__init__.py @@ -1,5 +1,6 @@ from chainer_chemistry.dataset.preprocessors.atomic_number_preprocessor import AtomicNumberPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.base_preprocessor import BasePreprocessor # NOQA +from chainer_chemistry.dataset.preprocessors.cgcnn_preprocessor import CGCNNPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.common import construct_adj_matrix # NOQA from chainer_chemistry.dataset.preprocessors.common import construct_atomic_number_array # NOQA from chainer_chemistry.dataset.preprocessors.common import construct_discrete_edge_matrix # NOQA @@ -7,7 +8,6 @@ from chainer_chemistry.dataset.preprocessors.common import MolFeatureExtractionError # NOQA from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms # NOQA from chainer_chemistry.dataset.preprocessors.ecfp_preprocessor import ECFPPreprocessor # NOQA -from chainer_chemistry.dataset.preprocessors.relgat_preprocessor import RelGATPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.ggnn_preprocessor import GGNNPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.gin_preprocessor import GINPreprocessor, GINSparsePreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.gnnfilm_preprocessor import GNNFiLMPreprocessor # NOQA @@ -15,14 +15,14 @@ from chainer_chemistry.dataset.preprocessors.gwm_preprocessor import GINGWMPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.gwm_preprocessor import NFPGWMPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.gwm_preprocessor import RSGCNGWMPreprocessor # NOQA +from chainer_chemistry.dataset.preprocessors.megnet_preprocessor import MEGNetPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.nfp_preprocessor import NFPPreprocessor # NOQA +from chainer_chemistry.dataset.preprocessors.relgat_preprocessor import RelGATPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.relgcn_preprocessor import RelGCNPreprocessor, RelGCNSparsePreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.rsgcn_preprocessor import RSGCNPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.schnet_preprocessor import SchNetPreprocessor # NOQA from chainer_chemistry.dataset.preprocessors.weavenet_preprocessor import WeaveNetPreprocessor # NOQA -from chainer_chemistry.dataset.preprocessors.megnet_preprocessor import MEGNetPreprocessor # NOQA -from chainer_chemistry.dataset.preprocessors.cgcnn_preprocessor import CGCNNPreprocessor # NOQA preprocess_method_dict = { 'ecfp': ECFPPreprocessor, diff --git a/chainer_chemistry/dataset/preprocessors/cgcnn_preprocessor.py b/chainer_chemistry/dataset/preprocessors/cgcnn_preprocessor.py index 0178ddc3..60838ab6 100644 --- a/chainer_chemistry/dataset/preprocessors/cgcnn_preprocessor.py +++ b/chainer_chemistry/dataset/preprocessors/cgcnn_preprocessor.py @@ -5,8 +5,8 @@ from chainer.dataset import download -from chainer_chemistry.dataset.utils import GaussianDistance from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA +from chainer_chemistry.dataset.utils import GaussianDistance from chainer_chemistry.utils import load_json download_url = 'https://raw.githubusercontent.com/txie-93/cgcnn/master/data/sample-regression/atom_init.json' # NOQA diff --git a/chainer_chemistry/dataset/preprocessors/ggnn_preprocessor.py b/chainer_chemistry/dataset/preprocessors/ggnn_preprocessor.py index e3f40b05..e75d914c 100644 --- a/chainer_chemistry/dataset/preprocessors/ggnn_preprocessor.py +++ b/chainer_chemistry/dataset/preprocessors/ggnn_preprocessor.py @@ -1,14 +1,11 @@ import numpy -from chainer_chemistry.dataset.graph_dataset.base_graph_data import \ - PaddingGraphData, SparseGraphData -from chainer_chemistry.dataset.graph_dataset.base_graph_dataset import \ - PaddingGraphDataset, SparseGraphDataset +from chainer_chemistry.dataset.graph_dataset.base_graph_data import SparseGraphData # NOQA +from chainer_chemistry.dataset.graph_dataset.base_graph_dataset import SparseGraphDataset # NOQA from chainer_chemistry.dataset.preprocessors.common \ - import construct_atomic_number_array, construct_discrete_edge_matrix -from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms -from chainer_chemistry.dataset.preprocessors.mol_preprocessor \ - import MolPreprocessor + import construct_atomic_number_array, construct_discrete_edge_matrix # NOQA +from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms # NOQA +from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA class GGNNPreprocessor(MolPreprocessor): diff --git a/chainer_chemistry/dataset/preprocessors/gin_preprocessor.py b/chainer_chemistry/dataset/preprocessors/gin_preprocessor.py index 1c155d56..e12d9791 100644 --- a/chainer_chemistry/dataset/preprocessors/gin_preprocessor.py +++ b/chainer_chemistry/dataset/preprocessors/gin_preprocessor.py @@ -1,13 +1,11 @@ import numpy -from chainer_chemistry.dataset.graph_dataset.base_graph_data import \ - PaddingGraphData, SparseGraphData -from chainer_chemistry.dataset.graph_dataset.base_graph_dataset import \ - PaddingGraphDataset, SparseGraphDataset + +from chainer_chemistry.dataset.graph_dataset.base_graph_data import SparseGraphData # NOQA +from chainer_chemistry.dataset.graph_dataset.base_graph_dataset import SparseGraphDataset # NOQA from chainer_chemistry.dataset.preprocessors.common \ - import construct_atomic_number_array, construct_adj_matrix + import construct_atomic_number_array, construct_adj_matrix # NOQA from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms -from chainer_chemistry.dataset.preprocessors.mol_preprocessor \ - import MolPreprocessor +from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA class GINPreprocessor(MolPreprocessor): @@ -16,19 +14,19 @@ class GINPreprocessor(MolPreprocessor): """ def __init__(self, max_atoms=-1, out_size=-1, add_Hs=False): - """ - initialize the GTN Preprocessor. - - :param max_atoms: integer, Max number of atoms for each molecule, - if the number of atoms is more than this value, - this data is simply ignored. - Setting negative value indicates no limit for max atoms. - :param out_size: integer, It specifies the size of array returned by - `get_input_features`. - If the number of atoms in the molecule is less than this value, - the returned arrays is padded to have fixed size. - Setting negative value indicates do not pad returned array. - :param add_Hs: boolean. if true, add Hydrogens explicitly. + """initialize the GIN Preprocessor. + + Args: + max_atoms (int): Max number of atoms for each molecule, + if the number of atoms is more than this value, + this data is simply ignored. + Setting negative value indicates no limit for max atoms. + out_size (int): It specifies the size of array returned by + `get_input_features`. + If the number of atoms in the molecule is less than this value, + the returned arrays is padded to have fixed size. + Setting negative value indicates do not pad returned array. + add_Hs (bool): If true, add Hydrogens explicitly. """ super(GINPreprocessor, self).__init__(add_Hs=add_Hs) if max_atoms >= 0 and out_size >= 0 and max_atoms > out_size: diff --git a/chainer_chemistry/dataset/preprocessors/gnnfilm_preprocessor.py b/chainer_chemistry/dataset/preprocessors/gnnfilm_preprocessor.py index 097b3abb..b49837fb 100644 --- a/chainer_chemistry/dataset/preprocessors/gnnfilm_preprocessor.py +++ b/chainer_chemistry/dataset/preprocessors/gnnfilm_preprocessor.py @@ -1,8 +1,7 @@ from chainer_chemistry.dataset.preprocessors.common \ - import construct_atomic_number_array, construct_discrete_edge_matrix -from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms -from chainer_chemistry.dataset.preprocessors.mol_preprocessor \ - import MolPreprocessor + import construct_atomic_number_array, construct_discrete_edge_matrix # NOQA +from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms # NOQA +from chainer_chemistry.dataset.preprocessors.mol_preprocessor import MolPreprocessor # NOQA class GNNFiLMPreprocessor(MolPreprocessor): @@ -44,5 +43,6 @@ def get_input_features(self, mol): """ type_check_num_atoms(mol, self.max_atoms) atom_array = construct_atomic_number_array(mol, out_size=self.out_size) - adj_array = construct_discrete_edge_matrix(mol, out_size=self.out_size, add_self_connection_channel=True) + adj_array = construct_discrete_edge_matrix( + mol, out_size=self.out_size, add_self_connection_channel=True) return atom_array, adj_array diff --git a/chainer_chemistry/dataset/preprocessors/megnet_preprocessor.py b/chainer_chemistry/dataset/preprocessors/megnet_preprocessor.py index 64a1526e..5f0b78c6 100644 --- a/chainer_chemistry/dataset/preprocessors/megnet_preprocessor.py +++ b/chainer_chemistry/dataset/preprocessors/megnet_preprocessor.py @@ -1,10 +1,10 @@ -import os from logging import getLogger +import os import traceback import numpy -from rdkit import Chem, RDConfig -from rdkit.Chem import AllChem, ChemicalFeatures, Descriptors, rdmolops +from rdkit import Chem, RDConfig # NOQA +from rdkit.Chem import AllChem, ChemicalFeatures, Descriptors, rdmolops # NOQA from chainer_chemistry.dataset.preprocessors.common import MolFeatureExtractionError # NOQA from chainer_chemistry.dataset.preprocessors.common import type_check_num_atoms # NOQA @@ -17,7 +17,7 @@ # create singleton class -class ChemicalFeaturesFactory: +class ChemicalFeaturesFactory(object): _instance = None @classmethod diff --git a/chainer_chemistry/dataset/preprocessors/relgcn_preprocessor.py b/chainer_chemistry/dataset/preprocessors/relgcn_preprocessor.py index c6de60ad..96c9a619 100644 --- a/chainer_chemistry/dataset/preprocessors/relgcn_preprocessor.py +++ b/chainer_chemistry/dataset/preprocessors/relgcn_preprocessor.py @@ -1,5 +1,4 @@ -from chainer_chemistry.dataset.preprocessors.ggnn_preprocessor \ - import GGNNPreprocessor, GGNNSparsePreprocessor +from chainer_chemistry.dataset.preprocessors.ggnn_preprocessor import GGNNPreprocessor, GGNNSparsePreprocessor # NOQA class RelGCNPreprocessor(GGNNPreprocessor): diff --git a/chainer_chemistry/dataset/utils.py b/chainer_chemistry/dataset/utils.py index 20347c07..f9aab63c 100644 --- a/chainer_chemistry/dataset/utils.py +++ b/chainer_chemistry/dataset/utils.py @@ -1,7 +1,7 @@ import numpy -class GaussianDistance: +class GaussianDistance(object): """Expand distance with Gaussian basis sit at centers and with width 0.5. Args: diff --git a/chainer_chemistry/datasets/citation_network/citation.py b/chainer_chemistry/datasets/citation_network/citation.py index 26139cf5..1514b986 100644 --- a/chainer_chemistry/datasets/citation_network/citation.py +++ b/chainer_chemistry/datasets/citation_network/citation.py @@ -1,7 +1,7 @@ import os -import numpy import networkx as nx +import numpy from tqdm import tqdm diff --git a/chainer_chemistry/datasets/citation_network/citeseer.py b/chainer_chemistry/datasets/citation_network/citeseer.py index 94fece90..95bc2e99 100644 --- a/chainer_chemistry/datasets/citation_network/citeseer.py +++ b/chainer_chemistry/datasets/citation_network/citeseer.py @@ -1,7 +1,7 @@ +from logging import getLogger import os import tarfile -from logging import getLogger -from typing import List, Tuple +from typing import List, Tuple # NOQA from chainer.dataset import download @@ -70,6 +70,7 @@ def get_citeseer_filepath(download_if_not_exist=True): def _get_citeseer_filepath(): # type: () -> Tuple[str, str] """Construct a filepath which stores citeseer dataset. + This method does not check if the file is already downloaded or not. Returns: feat_cache_path (str): file path for citeseer dataset (features). diff --git a/chainer_chemistry/datasets/citation_network/cora.py b/chainer_chemistry/datasets/citation_network/cora.py index 66671307..53228dfe 100644 --- a/chainer_chemistry/datasets/citation_network/cora.py +++ b/chainer_chemistry/datasets/citation_network/cora.py @@ -1,7 +1,7 @@ +from logging import getLogger import os import tarfile -from logging import getLogger -from typing import List, Tuple +from typing import List, Tuple # NOQA from chainer.dataset import download @@ -49,11 +49,14 @@ def get_cora_dirpath(download_if_not_exist=True): def get_cora_filepath(download_if_not_exist=True): # type: (bool) -> Tuple[str, str] """Construct a filepath which stores Cora dataset. + This method check whether the file exist or not, and downloaded it if necessary. + Args: download_if_not_exist (bool): If ``True``, download dataset if it is not downloaded yet. + Returns: feat_cache_path (str): file path for Cora dataset (features). edge_cache_path (str): file path for Cora dataset (edge index). @@ -72,7 +75,9 @@ def get_cora_filepath(download_if_not_exist=True): def _get_cora_filepath(): # type: () -> Tuple[str, str] """Construct a filepath which stores Cora dataset. + This method does not check if the file is already downloaded or not. + Returns: feat_cache_path (str): file path for Cora dataset (features). edge_cache_path (str): file path for Cora dataset (edge index). @@ -90,4 +95,4 @@ def download_and_extract_cora(save_dirpath): print('extracting cora dataset...') tf = tarfile.open(download_file_path, 'r') tf.extractall(os.path.dirname(save_dirpath)) - return True \ No newline at end of file + return True diff --git a/chainer_chemistry/datasets/molnet/__init__.py b/chainer_chemistry/datasets/molnet/__init__.py index 35a00464..c8985fed 100644 --- a/chainer_chemistry/datasets/molnet/__init__.py +++ b/chainer_chemistry/datasets/molnet/__init__.py @@ -4,8 +4,8 @@ from chainer_chemistry.datasets.molnet import pdbbind_time # NOQA from chainer_chemistry.datasets.molnet import toxcast_tasks # NOQA +from chainer_chemistry.datasets.molnet.molnet import get_grid_featurized_pdbbind_dataset # NOQA from chainer_chemistry.datasets.molnet.molnet import get_molnet_dataframe # NOQA from chainer_chemistry.datasets.molnet.molnet import get_molnet_dataset # NOQA from chainer_chemistry.datasets.molnet.molnet import get_molnet_filepath # NOQA -from chainer_chemistry.datasets.molnet.molnet import get_grid_featurized_pdbbind_dataset # NOQA from chainer_chemistry.datasets.molnet.molnet_config import molnet_default_config # NOQA diff --git a/chainer_chemistry/datasets/molnet/molnet_config.py b/chainer_chemistry/datasets/molnet/molnet_config.py index fce7162f..59d72eb8 100644 --- a/chainer_chemistry/datasets/molnet/molnet_config.py +++ b/chainer_chemistry/datasets/molnet/molnet_config.py @@ -138,12 +138,11 @@ def r2_score(x, t): 'NK1', 'OX1', 'OX2', 'PGP', 'PPB', 'RAT_F', 'TDI', 'THROMBIN' ], "test_url": molnet_base + 'KAGGLE_test2_' - 'disguised_combined_full.csv.gz', + 'disguised_combined_full.csv.gz', "train_url": molnet_base + 'KAGGLE_training_' - 'disguised_combined_full.csv.gz', - + 'disguised_combined_full.csv.gz', "valid_url": molnet_base + 'KAGGLE_test1_' - 'disguised_combined_full.csv.gz', + 'disguised_combined_full.csv.gz', }, "lipo": { diff --git a/chainer_chemistry/datasets/molnet/pdbbind_time.py b/chainer_chemistry/datasets/molnet/pdbbind_time.py index 555a6b37..dabca0d5 100644 --- a/chainer_chemistry/datasets/molnet/pdbbind_time.py +++ b/chainer_chemistry/datasets/molnet/pdbbind_time.py @@ -39,7 +39,8 @@ def get_pdbbind_time_filepath(download_if_not_exist=True): cache_path = _get_pdbbind_time_filepath(file_name) if not os.path.exists(cache_path): if download_if_not_exist: - is_successful = download_pdbbind_time(url, save_filepath=cache_path) + is_successful = download_pdbbind_time(url, + save_filepath=cache_path) if not is_successful: logger = getLogger(__name__) logger.warning('Download failed.') diff --git a/chainer_chemistry/datasets/numpy_tuple_dataset.py b/chainer_chemistry/datasets/numpy_tuple_dataset.py index a3ab4aba..5feada97 100644 --- a/chainer_chemistry/datasets/numpy_tuple_dataset.py +++ b/chainer_chemistry/datasets/numpy_tuple_dataset.py @@ -3,8 +3,8 @@ import numpy -from chainer_chemistry.dataset.indexers.numpy_tuple_dataset_feature_indexer import NumpyTupleDatasetFeatureIndexer # NOQA from chainer_chemistry.dataset.converters import concat_mols +from chainer_chemistry.dataset.indexers.numpy_tuple_dataset_feature_indexer import NumpyTupleDatasetFeatureIndexer # NOQA class NumpyTupleDataset(object): diff --git a/chainer_chemistry/datasets/reddit/reddit.py b/chainer_chemistry/datasets/reddit/reddit.py index 976f645d..a8e3e590 100644 --- a/chainer_chemistry/datasets/reddit/reddit.py +++ b/chainer_chemistry/datasets/reddit/reddit.py @@ -1,10 +1,11 @@ -import os from logging import getLogger +import os from zipfile import ZipFile -import numpy import networkx as nx +import numpy import scipy + from chainer.dataset import download download_url = 'https://s3.us-east-2.amazonaws.com/dgl.ai/dataset/reddit.zip' @@ -81,7 +82,9 @@ def get_reddit_filepath(download_if_not_exist=True): def _get_reddit_filepath(): # type: () -> Tuple[str, str] """Construct a filepath which stores reddit dataset. + This method does not check if the file is already downloaded or not. + Returns: feat_cache_path (str): file path for reddit dataset (features). edge_cache_path (str): file path for reddit dataset (edge index). diff --git a/chainer_chemistry/functions/__init__.py b/chainer_chemistry/functions/__init__.py index 3538d709..ffd79ea4 100644 --- a/chainer_chemistry/functions/__init__.py +++ b/chainer_chemistry/functions/__init__.py @@ -1,6 +1,6 @@ -from chainer_chemistry.functions.activation.softmax import softmax # NOQA from chainer_chemistry.functions.activation.megnet_softplus import megnet_softplus # NOQA from chainer_chemistry.functions.activation.shifted_softplus import shifted_softplus # NOQA +from chainer_chemistry.functions.activation.softmax import softmax # NOQA from chainer_chemistry.functions.evaluation.r2_score import r2_score # NOQA from chainer_chemistry.functions.evaluation.r2_score import R2Score # NOQA diff --git a/chainer_chemistry/functions/activation/shifted_softplus.py b/chainer_chemistry/functions/activation/shifted_softplus.py index eadb8eb1..029b0d09 100644 --- a/chainer_chemistry/functions/activation/shifted_softplus.py +++ b/chainer_chemistry/functions/activation/shifted_softplus.py @@ -8,7 +8,7 @@ def shifted_softplus(x, beta=1, shift=0.5, threshold=20): Args: x (Variable): Input variable beta (float): Parameter :math:`\\beta`. - shift (float): Shift Parameter + shift (float): Shift Parameter threshold (float): threshold to avoid overflow Returns: diff --git a/chainer_chemistry/functions/evaluation/r2_score.py b/chainer_chemistry/functions/evaluation/r2_score.py index 01756080..b8911470 100644 --- a/chainer_chemistry/functions/evaluation/r2_score.py +++ b/chainer_chemistry/functions/evaluation/r2_score.py @@ -52,6 +52,7 @@ def forward(self, inputs): def r2_score(pred, true, sample_weight=None, multioutput='uniform_average', ignore_nan=False): """Computes R^2(coefficient of determination) regression score function. + Args: pred(Variable): Variable holding a vector, matrix or tensor of estimated target values. @@ -64,10 +65,12 @@ def r2_score(pred, true, sample_weight=None, multioutput='uniform_average', 'uniform_average', this function returns an average of R^2 score of multiple output. If 'raw_average', this function return a set of R^2 score of multiple output. + Returns: Variable: A Variable holding a scalar array of the R^2 score if 'multioutput' is 'uniform_average' or a vector of R^2 scores if 'multioutput' is 'raw_values'. + .. note:: This function is non-differentiable. """ return R2Score(sample_weight=sample_weight, diff --git a/chainer_chemistry/links/__init__.py b/chainer_chemistry/links/__init__.py index d1d3a559..b3627069 100644 --- a/chainer_chemistry/links/__init__.py +++ b/chainer_chemistry/links/__init__.py @@ -11,8 +11,8 @@ from chainer_chemistry.links.readout.schnet_readout import SchNetReadout # NOQA from chainer_chemistry.links.readout.set2set import Set2Set # NOQA -from chainer_chemistry.links.scaler.standard_scaler import StandardScaler # NOQA from chainer_chemistry.links.scaler.flow_scaler import FlowScaler # NOQA +from chainer_chemistry.links.scaler.standard_scaler import StandardScaler # NOQA from chainer_chemistry.links.update.ggnn_update import GGNNUpdate # NOQA from chainer_chemistry.links.update.gin_update import GINUpdate # NOQA diff --git a/chainer_chemistry/links/connection/graph_mlp.py b/chainer_chemistry/links/connection/graph_mlp.py index d556abfb..df140eeb 100644 --- a/chainer_chemistry/links/connection/graph_mlp.py +++ b/chainer_chemistry/links/connection/graph_mlp.py @@ -1,5 +1,6 @@ -import chainer import numpy + +import chainer from chainer.functions import relu from chainer_chemistry.links.connection.graph_linear import GraphLinear diff --git a/chainer_chemistry/links/readout/cgcnn_readout.py b/chainer_chemistry/links/readout/cgcnn_readout.py index 4268bab1..d00baf47 100644 --- a/chainer_chemistry/links/readout/cgcnn_readout.py +++ b/chainer_chemistry/links/readout/cgcnn_readout.py @@ -1,5 +1,5 @@ import chainer -from chainer import functions, links +from chainer import functions, links # NOQA class CGCNNReadout(chainer.Chain): diff --git a/chainer_chemistry/links/readout/megnet_readout.py b/chainer_chemistry/links/readout/megnet_readout.py index 7279c114..52d6ecc5 100644 --- a/chainer_chemistry/links/readout/megnet_readout.py +++ b/chainer_chemistry/links/readout/megnet_readout.py @@ -1,5 +1,5 @@ import chainer -from chainer import functions, links +from chainer import functions, links # NOQA from chainer_chemistry.functions import megnet_softplus diff --git a/chainer_chemistry/links/readout/scatter_ggnn_readout.py b/chainer_chemistry/links/readout/scatter_ggnn_readout.py index 12d8e813..992599cc 100644 --- a/chainer_chemistry/links/readout/scatter_ggnn_readout.py +++ b/chainer_chemistry/links/readout/scatter_ggnn_readout.py @@ -1,4 +1,5 @@ import numpy + import chainer from chainer import functions diff --git a/chainer_chemistry/links/readout/schnet_readout.py b/chainer_chemistry/links/readout/schnet_readout.py index 922f2b9c..772444f4 100644 --- a/chainer_chemistry/links/readout/schnet_readout.py +++ b/chainer_chemistry/links/readout/schnet_readout.py @@ -1,8 +1,8 @@ import chainer from chainer import functions -from chainer_chemistry.links.connection.graph_linear import GraphLinear from chainer_chemistry.functions import shifted_softplus +from chainer_chemistry.links.connection.graph_linear import GraphLinear class SchNetReadout(chainer.Chain): diff --git a/chainer_chemistry/links/scaler/flow_scaler.py b/chainer_chemistry/links/scaler/flow_scaler.py index bf0dc481..db80db89 100644 --- a/chainer_chemistry/links/scaler/flow_scaler.py +++ b/chainer_chemistry/links/scaler/flow_scaler.py @@ -1,4 +1,5 @@ import numpy + import chainer from chainer_chemistry.links.scaler.base import BaseScaler, to_array # NOQA diff --git a/chainer_chemistry/links/scaler/max_abs_scaler.py b/chainer_chemistry/links/scaler/max_abs_scaler.py index f4698c17..d1be6f99 100644 --- a/chainer_chemistry/links/scaler/max_abs_scaler.py +++ b/chainer_chemistry/links/scaler/max_abs_scaler.py @@ -1,7 +1,8 @@ from logging import getLogger import numpy -from chainer import cuda, Variable + +from chainer import cuda, Variable # NOQA from chainer_chemistry.links.scaler.base import BaseScaler, to_array # NOQA from chainer_chemistry.links.array.shape_transformer_to_2d import ShapeTransformerTo2D # NOQA diff --git a/chainer_chemistry/links/scaler/min_max_scaler.py b/chainer_chemistry/links/scaler/min_max_scaler.py index f40f2f27..7a45de64 100644 --- a/chainer_chemistry/links/scaler/min_max_scaler.py +++ b/chainer_chemistry/links/scaler/min_max_scaler.py @@ -1,7 +1,8 @@ from logging import getLogger import numpy -from chainer import cuda, Variable + +from chainer import cuda, Variable # NOQA from chainer_chemistry.links.scaler.base import BaseScaler, to_array # NOQA from chainer_chemistry.links.array.shape_transformer_to_2d import ShapeTransformerTo2D # NOQA diff --git a/chainer_chemistry/links/scaler/standard_scaler.py b/chainer_chemistry/links/scaler/standard_scaler.py index 777b47ec..47a3f872 100644 --- a/chainer_chemistry/links/scaler/standard_scaler.py +++ b/chainer_chemistry/links/scaler/standard_scaler.py @@ -1,7 +1,8 @@ from logging import getLogger import numpy -from chainer import cuda, Variable + +from chainer import cuda, Variable # NOQA from chainer_chemistry.links.scaler.base import BaseScaler, to_array # NOQA from chainer_chemistry.links.array.shape_transformer_to_2d import ShapeTransformerTo2D # NOQA diff --git a/chainer_chemistry/links/update/cgcnn_update.py b/chainer_chemistry/links/update/cgcnn_update.py index 319a373e..477be90b 100644 --- a/chainer_chemistry/links/update/cgcnn_update.py +++ b/chainer_chemistry/links/update/cgcnn_update.py @@ -1,5 +1,5 @@ import chainer -from chainer import links, functions +from chainer import links, functions # NOQA class CGCNNUpdate(chainer.Chain): diff --git a/chainer_chemistry/links/update/gnn_film_update.py b/chainer_chemistry/links/update/gnn_film_update.py index 33998a2c..dbda6c89 100644 --- a/chainer_chemistry/links/update/gnn_film_update.py +++ b/chainer_chemistry/links/update/gnn_film_update.py @@ -14,15 +14,18 @@ class GNNFiLMUpdate(chainer.Chain): n_edge_types (int): number of types of edge """ - def __init__(self, hidden_channels=16, n_edge_types=5, activation=functions.relu): + def __init__(self, hidden_channels=16, n_edge_types=5, + activation=functions.relu): super(GNNFiLMUpdate, self).__init__() self.n_edge_types = n_edge_types self.activation = activation with self.init_scope(): self.W_linear = GraphLinear( - in_size=None, out_size=self.n_edge_types * hidden_channels, nobias=True) # W_l in eq. (6) + in_size=None, out_size=self.n_edge_types * hidden_channels, + nobias=True) # W_l in eq. (6) self.W_g = GraphLinear( - in_size=None, out_size=self.n_edge_types * hidden_channels * 2, nobias=True) # g in eq. (6) + in_size=None, out_size=self.n_edge_types * hidden_channels * 2, + nobias=True) # g in eq. (6) self.norm_layer = links.LayerNormalization() # l in eq. (6) def forward(self, h, adj): @@ -45,7 +48,8 @@ def forward(self, h, adj): # --- Update part --- - messages = functions.expand_dims(gamma, axis=3) * functions.expand_dims( + messages = functions.expand_dims( + gamma, axis=3) * functions.expand_dims( messages, axis=2) + functions.expand_dims(beta, axis=3) messages = self.activation(messages) # (minibatch, n_edge_types, atom, atom, out_ch) diff --git a/chainer_chemistry/links/update/megnet_update.py b/chainer_chemistry/links/update/megnet_update.py index 5e4d362f..2d08abfe 100644 --- a/chainer_chemistry/links/update/megnet_update.py +++ b/chainer_chemistry/links/update/megnet_update.py @@ -1,5 +1,5 @@ import chainer -from chainer import functions, links +from chainer import functions, links # NOQA from chainer_chemistry.functions import megnet_softplus diff --git a/chainer_chemistry/links/update/mpnn_update.py b/chainer_chemistry/links/update/mpnn_update.py index e5c27740..33c226d9 100644 --- a/chainer_chemistry/links/update/mpnn_update.py +++ b/chainer_chemistry/links/update/mpnn_update.py @@ -26,7 +26,7 @@ def __init__(self, in_channels=None, hidden_channels=16, out_channels=None, if out_channels is None: out_channels = hidden_channels if in_channels is None: - # Current `EdgeNet` hidden_channels must be same with input `h` dim. + # Current `EdgeNet` hidden_channels must be same with input `h` dim in_channels = out_channels super(MPNNUpdate, self).__init__() with self.init_scope(): diff --git a/chainer_chemistry/links/update/relgcn_update.py b/chainer_chemistry/links/update/relgcn_update.py index 1d8b6b49..aef088c5 100644 --- a/chainer_chemistry/links/update/relgcn_update.py +++ b/chainer_chemistry/links/update/relgcn_update.py @@ -25,7 +25,7 @@ def __init__(self, in_channels, out_channels, n_edge_types=4, self.out_channels = out_channels def __call__(self, h, adj, **kwargs): - """ + """main calculation Args: h: (batchsize, num_nodes, in_channels) @@ -33,7 +33,6 @@ def __call__(self, h, adj, **kwargs): Returns: (batchsize, num_nodes, ch) - """ mb, node, ch = h.shape diff --git a/chainer_chemistry/links/update/schnet_update.py b/chainer_chemistry/links/update/schnet_update.py index 5fd9b81f..c0cd5533 100644 --- a/chainer_chemistry/links/update/schnet_update.py +++ b/chainer_chemistry/links/update/schnet_update.py @@ -11,9 +11,8 @@ from chainer import functions from chainer import links - -from chainer_chemistry.links.connection.graph_linear import GraphLinear from chainer_chemistry.functions import shifted_softplus +from chainer_chemistry.links.connection.graph_linear import GraphLinear class CFConv(chainer.Chain): @@ -39,14 +38,14 @@ def __init__(self, num_rbf=300, radius_resolution=0.1, gamma=10.0, self.gamma = gamma def __call__(self, h, dist): - """ + """main calculation + Args: h (numpy.ndarray): axis 0 represents minibatch index, axis 1 represents atom_index and axis2 represents feature dimension. dist (numpy.ndarray): axis 0 represents minibatch index, axis 1 and 2 represent distance between atoms. - """ mb, atom, ch = h.shape if ch != self.hidden_dim: diff --git a/chainer_chemistry/models/__init__.py b/chainer_chemistry/models/__init__.py index a4582845..e4444ecc 100644 --- a/chainer_chemistry/models/__init__.py +++ b/chainer_chemistry/models/__init__.py @@ -14,6 +14,7 @@ from chainer_chemistry.models.ggnn import GGNN # NOQA from chainer_chemistry.models.ggnn import SparseGGNN # NOQA from chainer_chemistry.models.gin import GIN # NOQA +from chainer_chemistry.models.gnn_film import GNNFiLM # NOQA from chainer_chemistry.models.mlp import MLP # NOQA from chainer_chemistry.models.mpnn import MPNN # NOQA from chainer_chemistry.models.nfp import NFP # NOQA @@ -22,7 +23,6 @@ from chainer_chemistry.models.rsgcn import RSGCN # NOQA from chainer_chemistry.models.schnet import SchNet # NOQA from chainer_chemistry.models.weavenet import WeaveNet # NOQA -from chainer_chemistry.models.gnn_film import GNNFiLM # NOQA from chainer_chemistry.models.gwm.gwm_net import GGNN_GWM # NOQA from chainer_chemistry.models.gwm.gwm_net import GIN_GWM # NOQA diff --git a/chainer_chemistry/models/cgcnn.py b/chainer_chemistry/models/cgcnn.py index 8d77536f..17ddd563 100644 --- a/chainer_chemistry/models/cgcnn.py +++ b/chainer_chemistry/models/cgcnn.py @@ -1,9 +1,8 @@ import chainer from chainer import links - -from chainer_chemistry.links.update.cgcnn_update import CGCNNUpdate from chainer_chemistry.links.readout.cgcnn_readout import CGCNNReadout +from chainer_chemistry.links.update.cgcnn_update import CGCNNUpdate class CGCNN(chainer.Chain): diff --git a/chainer_chemistry/models/ggnn.py b/chainer_chemistry/models/ggnn.py index eecd5a03..022fbf5e 100644 --- a/chainer_chemistry/models/ggnn.py +++ b/chainer_chemistry/models/ggnn.py @@ -1,5 +1,5 @@ import chainer -from chainer import functions, cuda +from chainer import functions, cuda # NOQA from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links import EmbedAtomID diff --git a/chainer_chemistry/models/gin.py b/chainer_chemistry/models/gin.py index 52d33679..4b7c053d 100644 --- a/chainer_chemistry/models/gin.py +++ b/chainer_chemistry/models/gin.py @@ -1,11 +1,11 @@ import chainer -from chainer import functions, cuda +from chainer import functions, cuda # NOQA from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links import EmbedAtomID from chainer_chemistry.links.readout.ggnn_readout import GGNNReadout -from chainer_chemistry.links.readout.scatter_ggnn_readout import ScatterGGNNReadout -from chainer_chemistry.links.update.gin_update import GINUpdate, GINSparseUpdate +from chainer_chemistry.links.readout.scatter_ggnn_readout import ScatterGGNNReadout # NOQA +from chainer_chemistry.links.update.gin_update import GINUpdate, GINSparseUpdate # NOQA class GIN(chainer.Chain): diff --git a/chainer_chemistry/models/gwm/__init__.py b/chainer_chemistry/models/gwm/__init__.py index 4cefbf22..093f5941 100644 --- a/chainer_chemistry/models/gwm/__init__.py +++ b/chainer_chemistry/models/gwm/__init__.py @@ -1,8 +1,8 @@ -from chainer_chemistry.models.gwm import gwm -from chainer_chemistry.models.gwm import gwm_graph_conv_model -from chainer_chemistry.models.gwm import gwm_net +from chainer_chemistry.models.gwm import gwm # NOQA +from chainer_chemistry.models.gwm import gwm_graph_conv_model # NOQA +from chainer_chemistry.models.gwm import gwm_net # NOQA -from chainer_chemistry.models.gwm.gwm import GWM +from chainer_chemistry.models.gwm.gwm import GWM # NOQA from chainer_chemistry.models.gwm.gwm_graph_conv_model import GWMGraphConvModel # NOQA from chainer_chemistry.models.gwm.gwm_net import GGNN_GWM # NOQA from chainer_chemistry.models.gwm.gwm_net import GIN_GWM # NOQA diff --git a/chainer_chemistry/models/gwm/gwm.py b/chainer_chemistry/models/gwm/gwm.py index ff12698b..31cc74c9 100644 --- a/chainer_chemistry/models/gwm/gwm.py +++ b/chainer_chemistry/models/gwm/gwm.py @@ -43,8 +43,8 @@ def __init__(self, output_type='graph', hidden_dim=16, self.activation = activation def __call__(self, h, g): - # TODO: more efficient computation. Maybe we can calculate self.G(g) - # as Linear layer followed by broadcast to each atom. + # TODO(nakago): more efficient computation. Maybe we can calculate + # self.G(g) as Linear layer followed by broadcast to each atom. z = self.H(h) + self.G(g) if self.dropout_ratio > 0.0: @@ -75,7 +75,7 @@ def __init__(self, hidden_dim_super=16, hidden_dim=16, dropout_ratio=-1): self.dropout_ratio = dropout_ratio def __call__(self, g, n_nodes): - """ + """main calculation Args: g: super node feature. shape (bs, hidden_dim_super) @@ -257,7 +257,8 @@ def __init__(self, hidden_dim=16, hidden_dim_super=16, n_layers=4, self.wgu_activation = wgu_activation def __call__(self, h, h_new, g, step=0): - """ + """main calculation + Note: Do not forget to reset GRU for each batch. Args: diff --git a/chainer_chemistry/models/gwm/gwm_graph_conv_model.py b/chainer_chemistry/models/gwm/gwm_graph_conv_model.py index 2dd834c1..75c57036 100644 --- a/chainer_chemistry/models/gwm/gwm_graph_conv_model.py +++ b/chainer_chemistry/models/gwm/gwm_graph_conv_model.py @@ -1,12 +1,12 @@ import chainer from chainer import cuda -from chainer import links from chainer import functions +from chainer import links +from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links.connection.embed_atom_id import EmbedAtomID from chainer_chemistry.links.normalization.graph_batch_normalization import GraphBatchNormalization # NOQA from chainer_chemistry.links.readout.general_readout import GeneralReadout -from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.models.gwm.gwm import GWM from chainer_chemistry.models.relgcn import rescale_adj @@ -109,8 +109,8 @@ def __init__(self, hidden_channels, out_dim, update_layer, readout_layer, assert len(out_channels_list) == n_update_layers n_use_update_layers = 1 if weight_tying else n_update_layers - n_readout_layers = n_use_update_layers if concat_hidden or sum_hidden else 1 - n_activation = n_use_update_layers if n_activation is None else n_activation + n_readout_layers = n_use_update_layers if concat_hidden or sum_hidden else 1 # NOQA + n_activation = n_use_update_layers if n_activation is None else n_activation # NOQA if update_kwargs is None: update_kwargs = {} @@ -127,7 +127,8 @@ def __init__(self, hidden_channels, out_dim, update_layer, readout_layer, out_channels=out_channels_list[i], n_edge_types=n_edge_types, **update_kwargs) for i in range(n_use_update_layers)]) - # when use weight_tying option, hidden_channels must be same. So we can use -1 index + # when use weight_tying option, hidden_channels must be same. + # So we can use -1 index self.readout_layers = chainer.ChainList( *[readout_layer(out_dim=out_dim, # in_channels=hidden_channels[-1], @@ -144,7 +145,8 @@ def __init__(self, hidden_channels, out_dim, update_layer, readout_layer, if use_batchnorm: self.bnorms = chainer.ChainList( *[GraphBatchNormalization( - out_channels_list[i]) for i in range(n_use_update_layers)]) + out_channels_list[i]) for i in + range(n_use_update_layers)]) self.readout_layer = readout_layer self.update_layer = update_layer @@ -166,7 +168,7 @@ def __call__(self, atom_array, adj, super_node=None, is_real_node=None): if atom_array.dtype == self.xp.int32: h = self.embed(atom_array) else: - # TODO: GraphLinear or GraphMLP can be used. + # TODO(nakago): GraphLinear or GraphMLP can be used. h = atom_array h0 = functions.copy(h, cuda.get_device_from_array(h.data).id) diff --git a/chainer_chemistry/models/megnet.py b/chainer_chemistry/models/megnet.py index d56e7e66..b2443921 100644 --- a/chainer_chemistry/models/megnet.py +++ b/chainer_chemistry/models/megnet.py @@ -1,10 +1,10 @@ import chainer -from chainer import functions from chainer.backend import get_array_module +from chainer import functions from chainer_chemistry.functions import megnet_softplus -from chainer_chemistry.links.update.megnet_update import MEGNetUpdate from chainer_chemistry.links.readout.megnet_readout import MEGNetReadout +from chainer_chemistry.links.update.megnet_update import MEGNetUpdate def reshaped_feat(feat, idx): diff --git a/chainer_chemistry/models/mpnn.py b/chainer_chemistry/models/mpnn.py index 8725483d..fa60abe8 100644 --- a/chainer_chemistry/models/mpnn.py +++ b/chainer_chemistry/models/mpnn.py @@ -2,7 +2,7 @@ from typing import Optional # NOQA import chainer -from chainer import cuda, functions +from chainer import cuda, functions # NOQA from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links import EmbedAtomID @@ -10,7 +10,6 @@ from chainer_chemistry.links.readout.mpnn_readout import MPNNReadout from chainer_chemistry.links.update.ggnn_update import GGNNUpdate from chainer_chemistry.links.update.mpnn_update import MPNNUpdate -from chainer_chemistry.models.gwm.gwm_graph_conv_model import GWMGraphConvModel class MPNN(chainer.Chain): @@ -100,6 +99,7 @@ def __init__( def __call__(self, atom_array, adj): # type: (numpy.ndarray, numpy.ndarray) -> chainer.Variable """Forward propagation. + Args: atom_array (numpy.ndarray): minibatch of molecular which is represented with atom IDs (representing C, O, S, ...) diff --git a/chainer_chemistry/models/nfp.py b/chainer_chemistry/models/nfp.py index 0ebcd5b5..9bc1c2f6 100644 --- a/chainer_chemistry/models/nfp.py +++ b/chainer_chemistry/models/nfp.py @@ -1,5 +1,5 @@ import chainer -from chainer import Variable, functions +from chainer import Variable, functions # NOQA from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links import EmbedAtomID @@ -49,6 +49,7 @@ def __init__(self, out_dim, hidden_channels=16, n_update_layers=4, def __call__(self, atom_array, adj, is_real_node=None): """Forward propagation + Args: atom_array (numpy.ndarray): minibatch of molecular which is represented with atom IDs (representing C, O, S, ...) @@ -60,6 +61,7 @@ def __call__(self, atom_array, adj, is_real_node=None): is_real_node (numpy.ndarray): 2-dim array (minibatch, num_nodes). 1 for real node, 0 for virtual node. If `None`, all node is considered as real node. + Returns: ~chainer.Variable: minibatch of fingerprint """ diff --git a/chainer_chemistry/models/prediction/base.py b/chainer_chemistry/models/prediction/base.py index ca010c50..59f7f945 100644 --- a/chainer_chemistry/models/prediction/base.py +++ b/chainer_chemistry/models/prediction/base.py @@ -1,12 +1,13 @@ import pickle +import numpy + import chainer from chainer import cuda from chainer.dataset.convert import concat_examples from chainer.iterators import SerialIterator from chainer import link -import chainerx -import numpy +import chainerx # NOQA def _to_tuple(x): @@ -194,8 +195,8 @@ def load_pickle(filepath, device=-1): Args: filepath (str): file path of pickle file. - device (int or chainerx.Device): GPU device id of this model to be used. - -1 indicates to use in CPU. + device (int or chainerx.Device): GPU device id of this model to be + used. -1 indicates to use in CPU. """ with open(filepath, mode='rb') as f: diff --git a/chainer_chemistry/models/prediction/classifier.py b/chainer_chemistry/models/prediction/classifier.py index a2d6b887..0ad4d75c 100644 --- a/chainer_chemistry/models/prediction/classifier.py +++ b/chainer_chemistry/models/prediction/classifier.py @@ -115,6 +115,7 @@ def __init__(self, predictor, def _convert_to_scalar(self, value): """Converts an input value to a scalar if its type is a Variable, + numpy or cupy array, otherwise it returns the value as it is. """ if isinstance(value, Variable): diff --git a/chainer_chemistry/models/prediction/graph_conv_predictor.py b/chainer_chemistry/models/prediction/graph_conv_predictor.py index 5f4ea4d2..4157f5a5 100644 --- a/chainer_chemistry/models/prediction/graph_conv_predictor.py +++ b/chainer_chemistry/models/prediction/graph_conv_predictor.py @@ -51,7 +51,7 @@ def __call__(self, *args, **kwargs): def predict(self, atoms, adjs): # type: (numpy.ndarray, numpy.ndarray) -> chainer.Variable - # TODO (nakago): support super_node & is_real_node args. + # TODO(nakago): support super_node & is_real_node args. with chainer.no_backprop_mode(), chainer.using_config('train', False): x = self.__call__(atoms, adjs) return self.postprocess_fn(x) diff --git a/chainer_chemistry/models/prediction/node_classifier.py b/chainer_chemistry/models/prediction/node_classifier.py index 481a7d4a..7626096d 100644 --- a/chainer_chemistry/models/prediction/node_classifier.py +++ b/chainer_chemistry/models/prediction/node_classifier.py @@ -1,16 +1,12 @@ from chainer import reporter from chainer_chemistry.models.prediction.classifier import Classifier -from chainer_chemistry.dataset.graph_dataset.base_graph_data import PaddingGraphData # NOQA class NodeClassifier(Classifier): - - """A simple node classifier model. - """ + """A simple node classifier model.""" def __call__(self, data, train_mask, valid_mask, *args, **kwargs): - """Computes the loss value for an input and label pair. - """ + """Computes the loss value for an input and label pair.""" self.metrics = None self.y = self.predictor(data) # Support for padding pattern diff --git a/chainer_chemistry/models/prediction/regressor.py b/chainer_chemistry/models/prediction/regressor.py index 73133f57..26df3854 100644 --- a/chainer_chemistry/models/prediction/regressor.py +++ b/chainer_chemistry/models/prediction/regressor.py @@ -4,8 +4,9 @@ from chainer.dataset.convert import concat_examples from chainer import cuda, Variable # NOQA from chainer import reporter -from chainer_chemistry.models.prediction.base import BaseForwardModel + from chainer_chemistry.dataset.graph_dataset.base_graph_data import BaseGraphData # NOQA +from chainer_chemistry.models.prediction.base import BaseForwardModel class Regressor(BaseForwardModel): @@ -70,6 +71,7 @@ def __init__(self, predictor, def _convert_to_scalar(self, value): """Converts an input value to a scalar if its type is a Variable, + numpy or cupy array, otherwise it returns the value as it is. """ if isinstance(value, Variable): diff --git a/chainer_chemistry/models/prediction/set_up_predictor.py b/chainer_chemistry/models/prediction/set_up_predictor.py index bdbaf146..d53d2161 100644 --- a/chainer_chemistry/models/prediction/set_up_predictor.py +++ b/chainer_chemistry/models/prediction/set_up_predictor.py @@ -4,19 +4,19 @@ import chainer # NOQA +from chainer_chemistry.models.cgcnn import CGCNN from chainer_chemistry.models.ggnn import GGNN -from chainer_chemistry.models.gin import GIN, GINSparse +from chainer_chemistry.models.gin import GIN, GINSparse # NOQA +from chainer_chemistry.models.gnn_film import GNNFiLM +from chainer_chemistry.models.megnet import MEGNet from chainer_chemistry.models.mlp import MLP from chainer_chemistry.models.nfp import NFP from chainer_chemistry.models.prediction.graph_conv_predictor import GraphConvPredictor # NOQA from chainer_chemistry.models.relgat import RelGAT -from chainer_chemistry.models.relgcn import RelGCN, RelGCNSparse +from chainer_chemistry.models.relgcn import RelGCN, RelGCNSparse # NOQA from chainer_chemistry.models.rsgcn import RSGCN from chainer_chemistry.models.schnet import SchNet from chainer_chemistry.models.weavenet import WeaveNet -from chainer_chemistry.models.megnet import MEGNet -from chainer_chemistry.models.gnn_film import GNNFiLM -from chainer_chemistry.models.cgcnn import CGCNN from chainer_chemistry.models.gwm.gwm_net import GGNN_GWM # NOQA diff --git a/chainer_chemistry/models/relgat.py b/chainer_chemistry/models/relgat.py index 5dff903b..f0c0a1fe 100644 --- a/chainer_chemistry/models/relgat.py +++ b/chainer_chemistry/models/relgat.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import chainer -from chainer import functions, cuda +from chainer import functions, cuda # NOQA from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links import EmbedAtomID @@ -89,6 +89,7 @@ def __init__(self, out_dim, hidden_channels=16, n_update_layers=4, def __call__(self, atom_array, adj): """Forward propagation + Args: atom_array (numpy.ndarray): minibatch of molecular which is represented with atom IDs (representing C, O, S, ...) @@ -96,6 +97,7 @@ def __call__(self, atom_array, adj): molecule's `atom_index`-th atomic number adj (numpy.ndarray): minibatch of adjancency matrix with edge-type information + Returns: ~chainer.Variable: minibatch of fingerprint """ diff --git a/chainer_chemistry/models/relgcn.py b/chainer_chemistry/models/relgcn.py index 7482a844..e282101a 100644 --- a/chainer_chemistry/models/relgcn.py +++ b/chainer_chemistry/models/relgcn.py @@ -1,23 +1,25 @@ import chainer -from chainer import functions, cuda +from chainer import functions, cuda # NOQA from chainer.links import Linear from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links.readout.scatter_ggnn_readout import ScatterGGNNReadout # NOQA -from chainer_chemistry.links import EmbedAtomID, GraphLinear +from chainer_chemistry.links import EmbedAtomID, GraphLinear # NOQA from chainer_chemistry.links.readout.ggnn_readout import GGNNReadout -from chainer_chemistry.links.update.relgcn_update \ - import RelGCNUpdate, RelGCNSparseUpdate +from chainer_chemistry.links.update.relgcn_update import RelGCNUpdate, RelGCNSparseUpdate # NOQA def rescale_adj(adj): """Normalize adjacency matrix + It ensures that activations are on a similar scale irrespective of the number of neighbors + Args: adj (:class:`chainer.Variable`, or :class:`numpy.ndarray` \ or :class:`cupy.ndarray`): adjacency matrix + Returns: :class:`chainer.Variable`: normalized adjacency matrix """ @@ -83,7 +85,8 @@ def __init__(self, out_dim=64, hidden_channels=None, n_update_layers=None, self.scale_adj = scale_adj def __call__(self, x, adj): - """ + """main calculation + Args: x: (batchsize, num_nodes, in_channels) adj: (batchsize, num_edge_type, num_nodes, num_nodes) @@ -156,7 +159,8 @@ def __init__(self, out_dim=64, hidden_channels=None, n_update_layers=None, self.scale_adj = scale_adj def __call__(self, sparse_batch): - """ + """main calculation + Args: x: (batchsize, num_nodes, in_channels) adj: (batchsize, num_edge_type, num_nodes, num_nodes) diff --git a/chainer_chemistry/models/rsgcn.py b/chainer_chemistry/models/rsgcn.py index 2e5dbcdf..db871c65 100644 --- a/chainer_chemistry/models/rsgcn.py +++ b/chainer_chemistry/models/rsgcn.py @@ -1,5 +1,5 @@ import chainer -from chainer import functions, Variable +from chainer import functions, Variable # NOQA import chainer_chemistry from chainer_chemistry.config import MAX_ATOMIC_NUM @@ -69,6 +69,7 @@ def __init__(self, out_dim, hidden_channels=32, n_update_layers=4, def __call__(self, atom_array, adj, **kwargs): """Forward propagation + Args: atom_array (numpy.ndarray): minibatch of molecular which is represented with atom IDs (representing C, O, S, ...) diff --git a/chainer_chemistry/models/weavenet.py b/chainer_chemistry/models/weavenet.py index 38483fb2..93ae9ce5 100644 --- a/chainer_chemistry/models/weavenet.py +++ b/chainer_chemistry/models/weavenet.py @@ -4,8 +4,8 @@ from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.config import WEAVE_DEFAULT_NUM_MAX_ATOMS -from chainer_chemistry.links.readout.general_readout import GeneralReadout from chainer_chemistry.links.connection.embed_atom_id import EmbedAtomID +from chainer_chemistry.links.readout.general_readout import GeneralReadout WEAVENET_DEFAULT_WEAVE_CHANNELS = [50, ] diff --git a/chainer_chemistry/saliency/calculator/base_calculator.py b/chainer_chemistry/saliency/calculator/base_calculator.py index 8123ef18..efb25a4d 100644 --- a/chainer_chemistry/saliency/calculator/base_calculator.py +++ b/chainer_chemistry/saliency/calculator/base_calculator.py @@ -38,7 +38,7 @@ def _extract_numpy(x): def _concat(batch_list): try: return numpy.concatenate(batch_list) - except Exception as e: + except Exception as e: # NOQA # Thre is a case that each input has different shape, # we cannot concatenate into array in this case. diff --git a/chainer_chemistry/saliency/calculator/calculator_utils.py b/chainer_chemistry/saliency/calculator/calculator_utils.py index 61633a5c..aee50f66 100644 --- a/chainer_chemistry/saliency/calculator/calculator_utils.py +++ b/chainer_chemistry/saliency/calculator/calculator_utils.py @@ -25,4 +25,4 @@ def sample(self, target_array): else: raise ValueError("[ERROR] Unexpected value mode={}" .format(self.mode)) - return noise \ No newline at end of file + return noise diff --git a/chainer_chemistry/saliency/calculator/gradient_calculator.py b/chainer_chemistry/saliency/calculator/gradient_calculator.py index d180861b..d26375e9 100644 --- a/chainer_chemistry/saliency/calculator/gradient_calculator.py +++ b/chainer_chemistry/saliency/calculator/gradient_calculator.py @@ -1,4 +1,4 @@ -import chainer +import chainer # NOQA from chainer import functions from chainer_chemistry.saliency.calculator.base_calculator import BaseCalculator # NOQA diff --git a/chainer_chemistry/saliency/calculator/integrated_gradients_calculator.py b/chainer_chemistry/saliency/calculator/integrated_gradients_calculator.py index 63d74f9b..7f064a5e 100644 --- a/chainer_chemistry/saliency/calculator/integrated_gradients_calculator.py +++ b/chainer_chemistry/saliency/calculator/integrated_gradients_calculator.py @@ -44,7 +44,7 @@ def _compute_core(self, *inputs): total_grads = 0. self.model.cleargrads() # Need to forward once to get target_var - outputs = self.eval_fun(*inputs) + outputs = self.eval_fun(*inputs) # NOQA target_var = self.get_target_var(inputs) # output_var = self.get_output_var(outputs) diff --git a/chainer_chemistry/saliency/visualizer/__init__.py b/chainer_chemistry/saliency/visualizer/__init__.py index adf1408d..949b15e6 100644 --- a/chainer_chemistry/saliency/visualizer/__init__.py +++ b/chainer_chemistry/saliency/visualizer/__init__.py @@ -1,8 +1,8 @@ from chainer_chemistry.saliency.visualizer import base_visualizer # NOQA -from chainer_chemistry.saliency.visualizer import visualizer_utils # NOQA from chainer_chemistry.saliency.visualizer import image_visualizer # NOQA from chainer_chemistry.saliency.visualizer import mol_visualizer # NOQA from chainer_chemistry.saliency.visualizer import table_visualizer # NOQA +from chainer_chemistry.saliency.visualizer import visualizer_utils # NOQA from chainer_chemistry.saliency.visualizer.base_visualizer import BaseVisualizer # NOQA from chainer_chemistry.saliency.visualizer.image_visualizer import ImageVisualizer # NOQA diff --git a/chainer_chemistry/saliency/visualizer/image_visualizer.py b/chainer_chemistry/saliency/visualizer/image_visualizer.py index af9f1e55..c866a42b 100644 --- a/chainer_chemistry/saliency/visualizer/image_visualizer.py +++ b/chainer_chemistry/saliency/visualizer/image_visualizer.py @@ -1,8 +1,8 @@ from logging import getLogger -import numpy -import matplotlib.pyplot as plt import matplotlib.cm as cm +import matplotlib.pyplot as plt +import numpy from chainer import cuda diff --git a/chainer_chemistry/saliency/visualizer/mol_visualizer.py b/chainer_chemistry/saliency/visualizer/mol_visualizer.py index 512d5759..3c9a0d99 100644 --- a/chainer_chemistry/saliency/visualizer/mol_visualizer.py +++ b/chainer_chemistry/saliency/visualizer/mol_visualizer.py @@ -3,8 +3,8 @@ import numpy from rdkit import Chem -from rdkit.Chem import rdDepictor from rdkit.Chem.Draw import rdMolDraw2D +from rdkit.Chem import rdDepictor from chainer_chemistry.saliency.visualizer.base_visualizer import BaseVisualizer # NOQA @@ -130,7 +130,7 @@ def color_bond(bond): with open(save_filepath, 'w') as f: f.write(svg) elif extention == 'png': - # TODO (nakago): check it is possible without cairosvg or not + # TODO(nakago): check it is possible without cairosvg or not try: import cairosvg cairosvg.svg2png(bytestring=svg, write_to=save_filepath) diff --git a/chainer_chemistry/saliency/visualizer/table_visualizer.py b/chainer_chemistry/saliency/visualizer/table_visualizer.py index 4e27c19c..4b6111dc 100644 --- a/chainer_chemistry/saliency/visualizer/table_visualizer.py +++ b/chainer_chemistry/saliency/visualizer/table_visualizer.py @@ -1,5 +1,5 @@ -import numpy import matplotlib.pyplot as plt +import numpy from chainer_chemistry.saliency.visualizer.base_visualizer import BaseVisualizer # NOQA from chainer_chemistry.saliency.visualizer.visualizer_utils import abs_max_scaler # NOQA diff --git a/chainer_chemistry/saliency/visualizer/visualizer_utils.py b/chainer_chemistry/saliency/visualizer/visualizer_utils.py index da0dcf68..eec330fe 100644 --- a/chainer_chemistry/saliency/visualizer/visualizer_utils.py +++ b/chainer_chemistry/saliency/visualizer/visualizer_utils.py @@ -1,6 +1,6 @@ from logging import getLogger +import numpy # NOQA -import numpy from chainer import cuda diff --git a/chainer_chemistry/training/extensions/__init__.py b/chainer_chemistry/training/extensions/__init__.py index e5f5485e..f7930198 100644 --- a/chainer_chemistry/training/extensions/__init__.py +++ b/chainer_chemistry/training/extensions/__init__.py @@ -1,8 +1,8 @@ from chainer_chemistry.training.extensions import batch_evaluator # NOQA -from chainer_chemistry.training.extensions import roc_auc_evaluator # NOQA from chainer_chemistry.training.extensions import r2_score_evaluator # NOQA +from chainer_chemistry.training.extensions import roc_auc_evaluator # NOQA # import class and function from chainer_chemistry.training.extensions.batch_evaluator import BatchEvaluator # NOQA -from chainer_chemistry.training.extensions.roc_auc_evaluator import ROCAUCEvaluator # NOQA from chainer_chemistry.training.extensions.r2_score_evaluator import R2ScoreEvaluator # NOQA +from chainer_chemistry.training.extensions.roc_auc_evaluator import ROCAUCEvaluator # NOQA diff --git a/chainer_chemistry/training/extensions/auto_print_report.py b/chainer_chemistry/training/extensions/auto_print_report.py index 90e0601c..82319bd9 100644 --- a/chainer_chemistry/training/extensions/auto_print_report.py +++ b/chainer_chemistry/training/extensions/auto_print_report.py @@ -21,7 +21,7 @@ def create_header_and_templates(entries): def filter_and_sort_entries(all_entries, unit='epoch'): entries = deepcopy(all_entries) - # TODO: sort other entries if necessary + # TODO(nakago): sort other entries if necessary if 'iteration' in entries: # move iteration to head diff --git a/chainer_chemistry/training/extensions/r2_score_evaluator.py b/chainer_chemistry/training/extensions/r2_score_evaluator.py index 9aaf1166..d997f727 100644 --- a/chainer_chemistry/training/extensions/r2_score_evaluator.py +++ b/chainer_chemistry/training/extensions/r2_score_evaluator.py @@ -7,6 +7,7 @@ class R2ScoreEvaluator(BatchEvaluator): """Evaluator with calculates R^2 (coefficient of determination) + regression score. Args: @@ -54,7 +55,6 @@ class R2ScoreEvaluator(BatchEvaluator): eval_func: Evaluation function called at each iteration. pos_labels (list): labels of the positive class ignore_labels (list): labels to be ignored. - """ def __init__(self, iterator, target, converter=convert.concat_examples, diff --git a/chainer_chemistry/utils/__init__.py b/chainer_chemistry/utils/__init__.py index 27d8528e..b4d11035 100644 --- a/chainer_chemistry/utils/__init__.py +++ b/chainer_chemistry/utils/__init__.py @@ -1,5 +1,5 @@ from chainer_chemistry.utils.json_utils import load_json # NOQA from chainer_chemistry.utils.json_utils import save_json # NOQA -from chainer_chemistry.utils.sparse_utils import is_sparse # NOQA from chainer_chemistry.utils.sparse_utils import convert_sparse_with_edge_type # NOQA +from chainer_chemistry.utils.sparse_utils import is_sparse # NOQA from chainer_chemistry.utils.train_utils import run_train # NOQA diff --git a/chainer_chemistry/utils/train_utils.py b/chainer_chemistry/utils/train_utils.py index ba3a7442..ee6d11e6 100644 --- a/chainer_chemistry/utils/train_utils.py +++ b/chainer_chemistry/utils/train_utils.py @@ -1,7 +1,7 @@ import chainer -from chainer import optimizers, training, Optimizer +from chainer import optimizers, training, Optimizer # NOQA from chainer._backend import Device -from chainer.dataset import convert, Iterator +from chainer.dataset import convert, Iterator # NOQA from chainer.iterators import SerialIterator from chainer.training import extensions @@ -71,7 +71,7 @@ def run_train(model, train, valid=None, trainer.extend(extensions.LogReport()) trainer.extend(AutoPrintReport()) trainer.extend(extensions.ProgressBar(update_interval=10)) - # TODO: consider to include snapshot as default extension. + # TODO(nakago): consider to include snapshot as default extension. # trainer.extend(extensions.snapshot(), trigger=(frequency, 'epoch')) if extensions_list is not None: @@ -120,7 +120,7 @@ def one_batch_converter(batch, device): trainer.extend(extensions.LogReport()) trainer.extend(AutoPrintReport()) trainer.extend(extensions.ProgressBar(update_interval=10)) - # TODO: consider to include snapshot as default extension. + # TODO(nakago): consider to include snapshot as default extension. # trainer.extend(extensions.snapshot(), trigger=(frequency, 'epoch')) if extensions_list is not None: diff --git a/tests/dataset_tests/preprocessor_tests/test_common.py b/tests/dataset_tests/preprocessor_tests/test_common.py index d9504804..6a1e2a82 100644 --- a/tests/dataset_tests/preprocessor_tests/test_common.py +++ b/tests/dataset_tests/preprocessor_tests/test_common.py @@ -2,9 +2,10 @@ import pytest from rdkit import Chem +from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.dataset.preprocessors import common from chainer_chemistry.utils.extend import extend_adj -from chainer_chemistry.config import MAX_ATOMIC_NUM + @pytest.fixture def sample_molecule(): @@ -88,7 +89,7 @@ def test_normal_padding(self, sample_molecule_2): def test_normal_truncated(self, sample_molecule_2): with pytest.raises(ValueError): - adj = common.construct_adj_matrix(sample_molecule_2, 6) + adj = common.construct_adj_matrix(sample_molecule_2, 6) # NOQA class TestConstructDiscreteEdgeMatrix(object): @@ -178,8 +179,8 @@ def test_construct_super_node_feature_adj_ndim3(sample_molecule): assert s[3] == 1 assert s[4] == 0 assert s[5] == 0 - assert pytest.approx(s[6], 1 * 2 / adj.sum()) # symmetric - assert pytest.approx(s[7], 2 * 2 / adj.sum()) # symmetric + assert pytest.approx(s[6], 1 * 2 / adj.sum()) # symmetric + assert pytest.approx(s[7], 2 * 2 / adj.sum()) # symmetric assert s[8] == 0 assert s[9] == 0 assert s[9 + 6] == 1 # C diff --git a/tests/dataset_tests/preprocessors_tests/test_gwm_preprocessor.py b/tests/dataset_tests/preprocessors_tests/test_gwm_preprocessor.py index 9458eded..096acaae 100644 --- a/tests/dataset_tests/preprocessors_tests/test_gwm_preprocessor.py +++ b/tests/dataset_tests/preprocessors_tests/test_gwm_preprocessor.py @@ -2,7 +2,7 @@ from rdkit import Chem from chainer_chemistry.dataset.preprocessors.gwm_preprocessor import ( - NFPGWMPreprocessor, GGNNGWMPreprocessor, GINGWMPreprocessor, \ + NFPGWMPreprocessor, GGNNGWMPreprocessor, GINGWMPreprocessor, RSGCNGWMPreprocessor) # NOQA diff --git a/tests/dataset_tests/preprocessors_tests/test_weavenet_preprocessor.py b/tests/dataset_tests/preprocessors_tests/test_weavenet_preprocessor.py index 0fac4479..8739867e 100644 --- a/tests/dataset_tests/preprocessors_tests/test_weavenet_preprocessor.py +++ b/tests/dataset_tests/preprocessors_tests/test_weavenet_preprocessor.py @@ -27,7 +27,7 @@ def test_weave_preprocessor(max_atoms, use_fixed_atom_feature): assert adjs.shape[0] == max_atoms * max_atoms assert adjs.dtype == numpy.float32 - # TODO (nakago): test feature extraction behavior... + # TODO(nakago): test feature extraction behavior... atoms0, adjs0 = dataset[0] diff --git a/tests/functions_tests/activation/test_shifted_softplus.py b/tests/functions_tests/activation/test_shifted_softplus.py index 59a3ffbb..dbeefe0d 100644 --- a/tests/functions_tests/activation/test_shifted_softplus.py +++ b/tests/functions_tests/activation/test_shifted_softplus.py @@ -1,12 +1,9 @@ import numpy import pytest -import chainer from chainer import cuda -from chainer import gradient_check -import chainer_chemistry -from chainer_chemistry.functions.activation.shifted_softplus import shifted_softplus +from chainer_chemistry.functions.activation.shifted_softplus import shifted_softplus # NOQA def test_forward_cpu(): diff --git a/tests/functions_tests/activation/test_softmax.py b/tests/functions_tests/activation/test_softmax.py index 0b5f0b8f..85faec4c 100644 --- a/tests/functions_tests/activation/test_softmax.py +++ b/tests/functions_tests/activation/test_softmax.py @@ -1,11 +1,8 @@ import numpy import pytest -import chainer from chainer import cuda -from chainer import gradient_check -import chainer_chemistry from chainer_chemistry.functions.activation.softmax import softmax diff --git a/tests/iterators_tests/test_balanced_serial_iterator.py b/tests/iterators_tests/test_balanced_serial_iterator.py index 0029c4d1..56968bb9 100644 --- a/tests/iterators_tests/test_balanced_serial_iterator.py +++ b/tests/iterators_tests/test_balanced_serial_iterator.py @@ -103,7 +103,7 @@ def _test_balanced_serial_iterator_serialization_no_batch_balancing(): iterator = BalancedSerialIterator(NumpyTupleDataset(x, t), batch_size=9, labels=t, ignore_labels=-1, batch_balancing=False) - batch = iterator.next() + batch = iterator.next() # NOQA assert iterator.current_position == 0 assert iterator.epoch == 1 @@ -138,9 +138,9 @@ def _test_balanced_serial_iterator_serialization_with_batch_balancing(): iterator = BalancedSerialIterator(NumpyTupleDataset(x, t), batch_size=3, labels=t, ignore_labels=-1, batch_balancing=True) - batch1 = iterator.next() - batch2 = iterator.next() - batch3 = iterator.next() + batch1 = iterator.next() # NOQA + batch2 = iterator.next() # NOQA + batch3 = iterator.next() # NOQA assert iterator.current_position == 0 assert iterator.epoch == 1 diff --git a/tests/iterators_tests/test_index_iterator.py b/tests/iterators_tests/test_index_iterator.py index ed169ad5..5d52d28d 100644 --- a/tests/iterators_tests/test_index_iterator.py +++ b/tests/iterators_tests/test_index_iterator.py @@ -102,9 +102,9 @@ def _test_index_iterator_serialization_no_shuffle(): index_list = [1, 3, 5, 10] ii = IndexIterator(index_list, shuffle=False, num=2) - indices1 = ii.get_next_indices(3) - indices2 = ii.get_next_indices(6) - indices3 = ii.__next__() + indices1 = ii.get_next_indices(3) # NOQA + indices2 = ii.get_next_indices(6) # NOQA + indices3 = ii.__next__() # NOQA assert len(ii.current_index_list) == len(index_list) assert numpy.array_equal(ii.current_index_list, numpy.asarray(index_list)) @@ -124,9 +124,9 @@ def _test_index_iterator_serialization_with_shuffle(): index_list = [1, 3, 5, 10] ii = IndexIterator(index_list, shuffle=True, num=2) - indices1 = ii.get_next_indices(3) - indices2 = ii.get_next_indices(6) - indices3 = ii.__next__() + indices1 = ii.get_next_indices(3) # NOQA + indices2 = ii.get_next_indices(6) # NOQA + indices3 = ii.__next__() # NOQA assert len(ii.current_index_list) == len(index_list) for index in ii.current_index_list: diff --git a/tests/link_hooks_tests/test_variable_monitor_link_hook.py b/tests/link_hooks_tests/test_variable_monitor_link_hook.py index e57c5bd7..0f6072ac 100644 --- a/tests/link_hooks_tests/test_variable_monitor_link_hook.py +++ b/tests/link_hooks_tests/test_variable_monitor_link_hook.py @@ -2,7 +2,7 @@ import pytest import chainer -from chainer import Variable, cuda +from chainer import Variable, cuda # NOQA from chainer.links import Linear from chainer_chemistry.link_hooks import is_link_hooks_available @@ -86,7 +86,7 @@ def test_variable_monitor_link_hook_assert_raises(model): with pytest.raises(ValueError): # check timing args - pre_hook = VariableMonitorLinkHook(target_link=model.l1, timing='hoge') + pre_hook = VariableMonitorLinkHook(target_link=model.l1, timing='hoge') # NOQA hook = VariableMonitorLinkHook(target_link=model.l1) diff --git a/tests/links_tests/array_tests/test_shape_transformer_to_2d.py b/tests/links_tests/array_tests/test_shape_transformer_to_2d.py index 08abe2f9..28a0dbab 100644 --- a/tests/links_tests/array_tests/test_shape_transformer_to_2d.py +++ b/tests/links_tests/array_tests/test_shape_transformer_to_2d.py @@ -43,7 +43,7 @@ def test_shape_transformer_2d_error(): x = numpy.arange(6).reshape(2, 3) with pytest.raises(AttributeError): # call `inverse_transform` before `transform` - xt = st.inverse_transform(x) + xt = st.inverse_transform(x) # NOQA if __name__ == '__main__': diff --git a/tests/links_tests/readout_tests/test_cgcnn_readout.py b/tests/links_tests/readout_tests/test_cgcnn_readout.py index 565ce407..09ddb2ae 100644 --- a/tests/links_tests/readout_tests/test_cgcnn_readout.py +++ b/tests/links_tests/readout_tests/test_cgcnn_readout.py @@ -1,8 +1,8 @@ -from chainer import cuda -from chainer import gradient_check import numpy import pytest +from chainer import cuda + from chainer_chemistry.links.readout.cgcnn_readout import CGCNNReadout diff --git a/tests/links_tests/readout_tests/test_general_readout.py b/tests/links_tests/readout_tests/test_general_readout.py index 8340355f..bcbee26d 100644 --- a/tests/links_tests/readout_tests/test_general_readout.py +++ b/tests/links_tests/readout_tests/test_general_readout.py @@ -74,7 +74,7 @@ def test_backward_gpu(readouts, data): readout.to_gpu() if readout.mode == 'summax': y_grad = functions.concat((y_grad, y_grad), axis=1).data - # TODO (nakago): check why tolerance is so high. + # TODO(nakago): check why tolerance is so high. gradient_check.check_backward( readout, atom_data, y_grad, atol=1e-1, rtol=1e-1) diff --git a/tests/links_tests/readout_tests/test_mpnn_readout.py b/tests/links_tests/readout_tests/test_mpnn_readout.py index b8ca3152..5fb7d9d3 100644 --- a/tests/links_tests/readout_tests/test_mpnn_readout.py +++ b/tests/links_tests/readout_tests/test_mpnn_readout.py @@ -1,9 +1,11 @@ from typing import Tuple # NOQA -from chainer import cuda -from chainer import gradient_check + import numpy import pytest +from chainer import cuda +from chainer import gradient_check + from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links.readout.mpnn_readout import MPNNReadout from chainer_chemistry.utils.permutation import permute_node diff --git a/tests/links_tests/readout_tests/test_set2set.py b/tests/links_tests/readout_tests/test_set2set.py index 2dc5288d..0e32eaf4 100644 --- a/tests/links_tests/readout_tests/test_set2set.py +++ b/tests/links_tests/readout_tests/test_set2set.py @@ -1,11 +1,11 @@ from typing import Tuple # NOQA -import chainer -from chainer import cuda -from chainer import gradient_check import numpy import pytest +from chainer import cuda +from chainer import gradient_check + from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.links.readout.set2set import Set2Set from chainer_chemistry.utils.permutation import permute_node diff --git a/tests/links_tests/scaler_tests/test_flow_scaler.py b/tests/links_tests/scaler_tests/test_flow_scaler.py index c10679f8..ec11243c 100644 --- a/tests/links_tests/scaler_tests/test_flow_scaler.py +++ b/tests/links_tests/scaler_tests/test_flow_scaler.py @@ -3,7 +3,7 @@ import numpy import pytest import scipy.stats -from chainer import serializers, Variable, cuda, testing +from chainer import serializers, Variable, cuda, testing # NOQA from chainer_chemistry.links.scaler.flow_scaler import FlowScaler diff --git a/tests/links_tests/scaler_tests/test_max_abs_scaler.py b/tests/links_tests/scaler_tests/test_max_abs_scaler.py index d1850eed..2c21b489 100644 --- a/tests/links_tests/scaler_tests/test_max_abs_scaler.py +++ b/tests/links_tests/scaler_tests/test_max_abs_scaler.py @@ -2,7 +2,7 @@ import numpy import pytest -from chainer import serializers, Variable, cuda +from chainer import serializers, Variable, cuda # NOQA from chainer_chemistry.links.scaler.max_abs_scaler import MaxAbsScaler diff --git a/tests/links_tests/scaler_tests/test_min_max_scaler.py b/tests/links_tests/scaler_tests/test_min_max_scaler.py index f8f95bdc..41e4bed8 100644 --- a/tests/links_tests/scaler_tests/test_min_max_scaler.py +++ b/tests/links_tests/scaler_tests/test_min_max_scaler.py @@ -2,7 +2,7 @@ import numpy import pytest -from chainer import serializers, Variable, cuda +from chainer import serializers, Variable, cuda # NOQA from chainer_chemistry.links.scaler.min_max_scaler import MinMaxScaler diff --git a/tests/links_tests/scaler_tests/test_standard_scaler.py b/tests/links_tests/scaler_tests/test_standard_scaler.py index 77ff1eb3..2efe046f 100644 --- a/tests/links_tests/scaler_tests/test_standard_scaler.py +++ b/tests/links_tests/scaler_tests/test_standard_scaler.py @@ -3,7 +3,7 @@ import chainer import numpy import pytest -from chainer import serializers, Variable, cuda +from chainer import serializers, Variable, cuda # NOQA from chainer_chemistry.links.scaler.standard_scaler import StandardScaler diff --git a/tests/links_tests/update_tests/test_cgcnn_update.py b/tests/links_tests/update_tests/test_cgcnn_update.py index 8aca6910..19131338 100644 --- a/tests/links_tests/update_tests/test_cgcnn_update.py +++ b/tests/links_tests/update_tests/test_cgcnn_update.py @@ -1,8 +1,8 @@ -from chainer import cuda -from chainer import gradient_check import numpy import pytest +from chainer import cuda + from chainer_chemistry.links.update.cgcnn_update import CGCNNUpdate diff --git a/tests/links_tests/update_tests/test_megnet_update.py b/tests/links_tests/update_tests/test_megnet_update.py index 1ef9b393..54e5675c 100644 --- a/tests/links_tests/update_tests/test_megnet_update.py +++ b/tests/links_tests/update_tests/test_megnet_update.py @@ -1,5 +1,4 @@ from chainer import cuda -from chainer import gradient_check import numpy import pytest diff --git a/tests/links_tests/update_tests/test_mpnn_update.py b/tests/links_tests/update_tests/test_mpnn_update.py index 65f6b29f..d3b2c870 100644 --- a/tests/links_tests/update_tests/test_mpnn_update.py +++ b/tests/links_tests/update_tests/test_mpnn_update.py @@ -31,7 +31,7 @@ def update(): @pytest.fixture def data(): - # type: () -> Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] + # type: () -> Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] # NOQA numpy.random.seed(0) atom_data = numpy.random.randint( 0, high=MAX_ATOMIC_NUM, size=(batch_size, atom_size)).astype('i') diff --git a/tests/links_tests/update_tests/test_relgat_update.py b/tests/links_tests/update_tests/test_relgat_update.py index c7aaaa4a..ccf86a07 100644 --- a/tests/links_tests/update_tests/test_relgat_update.py +++ b/tests/links_tests/update_tests/test_relgat_update.py @@ -61,7 +61,7 @@ def test_backward_cpu(update, data): atom_data, adj_data, y_grad = data # gradient_check.check_backward( # update, (atom_data, adj_data), y_grad, atol=1e-3, rtol=1e-3) - params = tuple(update.params()) + params = tuple(update.params()) # NOQA gradient_check.check_backward(update, (atom_data, adj_data), y_grad, no_grads=[False, True], atol=1e-1, rtol=1e-1) diff --git a/tests/models_tests/gwm_tests/test_gwm.py b/tests/models_tests/gwm_tests/test_gwm.py index 288073bc..48ff1e90 100644 --- a/tests/models_tests/gwm_tests/test_gwm.py +++ b/tests/models_tests/gwm_tests/test_gwm.py @@ -151,7 +151,7 @@ def check_backward(gwm, embed_atom_data, new_embed_atom_data, supernode, y_grad, supernode_grad): gwm.reset_state() - # TODO: rtol is too high! GWM is too large to calculate + # TODO(nakago): rtol is too high! GWM is too large to calculate # numerical differentiation gradient_check.check_backward(gwm, (embed_atom_data, new_embed_atom_data, supernode), (y_grad, supernode_grad), diff --git a/tests/models_tests/gwm_tests/test_gwm_graph_conv_model.py b/tests/models_tests/gwm_tests/test_gwm_graph_conv_model.py index ca71e489..07ee47ac 100644 --- a/tests/models_tests/gwm_tests/test_gwm_graph_conv_model.py +++ b/tests/models_tests/gwm_tests/test_gwm_graph_conv_model.py @@ -3,19 +3,16 @@ import pytest from chainer_chemistry.config import MAX_ATOMIC_NUM -from chainer_chemistry.models.gwm.gwm_graph_conv_model import GWMGraphConvModel +from chainer_chemistry.links.readout.general_readout import GeneralReadout +from chainer_chemistry.links.readout.ggnn_readout import GGNNReadout +from chainer_chemistry.links.readout.nfp_readout import NFPReadout +from chainer_chemistry.links.readout.schnet_readout import SchNetReadout from chainer_chemistry.links.update.ggnn_update import GGNNUpdate from chainer_chemistry.links.update.gin_update import GINUpdate -from chainer_chemistry.links.update.mpnn_update import MPNNUpdate from chainer_chemistry.links.update.relgat_update import RelGATUpdate from chainer_chemistry.links.update.relgcn_update import RelGCNUpdate from chainer_chemistry.links.update.rsgcn_update import RSGCNUpdate -from chainer_chemistry.links.update.schnet_update import SchNetUpdate -from chainer_chemistry.links.readout.general_readout import GeneralReadout -from chainer_chemistry.links.readout.ggnn_readout import GGNNReadout -from chainer_chemistry.links.readout.mpnn_readout import MPNNReadout -from chainer_chemistry.links.readout.nfp_readout import NFPReadout -from chainer_chemistry.links.readout.schnet_readout import SchNetReadout +from chainer_chemistry.models.gwm.gwm_graph_conv_model import GWMGraphConvModel atom_size = 5 @@ -25,9 +22,9 @@ batch_size = 2 n_edge_types = 3 -# TODO (nakago): SchNetUpdate need `in_channels` kwargs, not supported. +# TODO(nakago): SchNetUpdate need `in_channels` kwargs, not supported. updates_2dim = [GINUpdate, RSGCNUpdate] -# TODO (nakago): Support MPNNUpdate. +# TODO(nakago): Support MPNNUpdate. updates_3dim = [GGNNUpdate, RelGATUpdate, RelGCNUpdate] updates = updates_2dim + updates_3dim @@ -229,7 +226,7 @@ def test_model_forward_general_weight_tying(update, readout, gwm): with_gwm=gwm) atom_array = data[0] adj = data[1] - super_node = data[2] + super_node = data[2] # NOQA y_actual = model(atom_array, adj) assert y_actual.shape == (batch_size, out_dim) diff --git a/tests/models_tests/test_cgcnn.py b/tests/models_tests/test_cgcnn.py index f586af90..bc1abce3 100644 --- a/tests/models_tests/test_cgcnn.py +++ b/tests/models_tests/test_cgcnn.py @@ -1,5 +1,4 @@ from chainer import cuda -from chainer import gradient_check import numpy import pytest diff --git a/tests/models_tests/test_ggnn.py b/tests/models_tests/test_ggnn.py index c4dedaa8..0b401312 100644 --- a/tests/models_tests/test_ggnn.py +++ b/tests/models_tests/test_ggnn.py @@ -6,7 +6,7 @@ from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.models.ggnn import GGNN from chainer_chemistry.models.ggnn import SparseGGNN -from chainer_chemistry.utils.extend import extend_node, extend_adj +from chainer_chemistry.utils.extend import extend_node, extend_adj # NOQA from chainer_chemistry.utils.permutation import permute_adj from chainer_chemistry.utils.permutation import permute_node from chainer_chemistry.utils.sparse_utils import _convert_to_sparse diff --git a/tests/models_tests/test_megnet.py b/tests/models_tests/test_megnet.py index d7769d74..faaf9c6a 100644 --- a/tests/models_tests/test_megnet.py +++ b/tests/models_tests/test_megnet.py @@ -1,5 +1,4 @@ from chainer import cuda -from chainer import gradient_check import numpy import pytest diff --git a/tests/models_tests/test_nfp.py b/tests/models_tests/test_nfp.py index b4752e63..6c72f807 100644 --- a/tests/models_tests/test_nfp.py +++ b/tests/models_tests/test_nfp.py @@ -5,7 +5,7 @@ from chainer_chemistry.config import MAX_ATOMIC_NUM from chainer_chemistry.models.nfp import NFP -from chainer_chemistry.utils.extend import extend_adj, extend_node +from chainer_chemistry.utils.extend import extend_adj, extend_node # NOQA from chainer_chemistry.utils.permutation import permute_adj from chainer_chemistry.utils.permutation import permute_node diff --git a/tests/models_tests/test_relgcn.py b/tests/models_tests/test_relgcn.py index a4068cbe..068200ff 100644 --- a/tests/models_tests/test_relgcn.py +++ b/tests/models_tests/test_relgcn.py @@ -4,8 +4,8 @@ import pytest from chainer_chemistry.config import MAX_ATOMIC_NUM +from chainer_chemistry.models.gwm.gwm_graph_conv_model import rescale_adj # NOQA from chainer_chemistry.models.relgcn import RelGCN -from chainer_chemistry.models.gwm.gwm_graph_conv_model import rescale_adj from chainer_chemistry.utils.permutation import permute_adj from chainer_chemistry.utils.permutation import permute_node diff --git a/tests/saliency_tests/calculator_tests/test_base_calculator.py b/tests/saliency_tests/calculator_tests/test_base_calculator.py index 64fd45bf..47b7c451 100644 --- a/tests/saliency_tests/calculator_tests/test_base_calculator.py +++ b/tests/saliency_tests/calculator_tests/test_base_calculator.py @@ -7,8 +7,8 @@ from chainer_chemistry.link_hooks import is_link_hooks_available if is_link_hooks_available: from chainer_chemistry.link_hooks import VariableMonitorLinkHook - from chainer_chemistry.saliency.calculator import GaussianNoiseSampler from chainer_chemistry.saliency.calculator.base_calculator import BaseCalculator # NOQA + from chainer_chemistry.saliency.calculator import GaussianNoiseSampler class DummyCalculator(BaseCalculator): """Dummy calculator which returns target_var""" diff --git a/tests/saliency_tests/visualizer_tests/test_image_visualizer.py b/tests/saliency_tests/visualizer_tests/test_image_visualizer.py index 096717b7..ec5ca1c9 100644 --- a/tests/saliency_tests/visualizer_tests/test_image_visualizer.py +++ b/tests/saliency_tests/visualizer_tests/test_image_visualizer.py @@ -1,7 +1,7 @@ import os import sys -import matplotlib.pyplot as plt +import matplotlib.pyplot as plt import numpy import pytest diff --git a/tests/saliency_tests/visualizer_tests/test_table_visualizer.py b/tests/saliency_tests/visualizer_tests/test_table_visualizer.py index 185a1c69..d72e5748 100644 --- a/tests/saliency_tests/visualizer_tests/test_table_visualizer.py +++ b/tests/saliency_tests/visualizer_tests/test_table_visualizer.py @@ -1,11 +1,10 @@ import os import sys -import matplotlib.pyplot as plt +import matplotlib.pyplot as plt import numpy import pytest - from chainer_chemistry.saliency.visualizer.table_visualizer import TableVisualizer # NOQA diff --git a/tests/training_tests/extensions_tests/test_auto_print_report.py b/tests/training_tests/extensions_tests/test_auto_print_report.py index 1df325e0..06932f5d 100644 --- a/tests/training_tests/extensions_tests/test_auto_print_report.py +++ b/tests/training_tests/extensions_tests/test_auto_print_report.py @@ -3,6 +3,7 @@ import pytest import mock + from chainer import testing from chainer.training import extensions diff --git a/tests/utils_tests/test_train_utils.py b/tests/utils_tests/test_train_utils.py index ed2be018..c3736ad2 100644 --- a/tests/utils_tests/test_train_utils.py +++ b/tests/utils_tests/test_train_utils.py @@ -1,9 +1,10 @@ import chainer import numpy import pytest + +from chainer.iterators import SerialIterator from chainer import links import chainerx -from chainer.iterators import SerialIterator from chainer_chemistry.datasets import NumpyTupleDataset from chainer_chemistry.models import Regressor