Skip to content

Commit

Permalink
Merge pull request #112 from mottodora/v2
Browse files Browse the repository at this point in the history
Apply autopep8 and flake8 to obey PEP8.
  • Loading branch information
corochann authored Mar 1, 2018
2 parents 34f34c9 + 2fb514d commit 81b18c6
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 39 deletions.
4 changes: 2 additions & 2 deletions chainer_chemistry/models/schnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ def __init__(self, out_dim):
super(AtomwiseLinear, self).__init__()
with self.init_scope():
self.out_dim = out_dim
self.l = links.Linear(self.out_dim)
self.linear = links.Linear(self.out_dim)

def __call__(self, embeded_atom_features):
# s0 is the minibatch axis
# s1 is the atom axis
# s2 is the channel (feature) axis
s0, s1, s2 = embeded_atom_features.shape
x = functions.reshape(embeded_atom_features, (s0 * s1, s2))
x = self.l(x)
x = self.linear(x)
x = functions.reshape(x, (s0, s1, self.out_dim))
return x

Expand Down
12 changes: 6 additions & 6 deletions chainer_chemistry/training/extensions/roc_auc_evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

def _get_1d_numpy_array(v):
"""Convert array or Variable to 1d numpy array
Args:
v (numpy.ndarray or cupy.ndarray or chainer.Variable): array to be
converted to 1d numpy array
converted to 1d numpy array
Returns (numpy.ndarray): Raveled 1d numpy array
Expand All @@ -27,7 +27,7 @@ def _get_1d_numpy_array(v):

def _to_list(a):
"""convert value `a` to list
Args:
a: value to be convert to `list`
Expand All @@ -49,7 +49,7 @@ class ROCAUCEvaluator(Evaluator):
Args:
iterator: Dataset iterator for the dataset to calculate ROC AUC score.
It can also be a dictionary of iterators. If this is just an
It can also be a dictionary of iterators. If this is just an
iterator, the iterator is registered by the name ``'main'``.
target: Link object or a dictionary of links to evaluate. If this is
just a link object, the link is registered by the name ``'main'``.
Expand All @@ -65,8 +65,8 @@ class ROCAUCEvaluator(Evaluator):
object is passed at each call.
eval_func: Evaluation function called at each iteration. The target
link to evaluate as a callable is used by default.
name (str): name of this extension. When `name` is None,
`default_name='validation'` which is defined in super class
name (str): name of this extension. When `name` is None,
`default_name='validation'` which is defined in super class
`Evaluator` is used as extension name. This name affects to the
reported key name.
pos_labels (int or list): labels of the positive class, other classes
Expand Down
23 changes: 11 additions & 12 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import os
import pkg_resources
import sys

import sphinx_rtd_theme
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

Expand All @@ -34,15 +36,15 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon']
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.viewcode',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon']

autosummary_generate = True

Expand Down Expand Up @@ -96,7 +98,6 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"

Expand Down Expand Up @@ -183,7 +184,5 @@
]




# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
5 changes: 3 additions & 2 deletions examples/qm9/train_qm9.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class GraphConvPredictor(chainer.Chain):

def __init__(self, graph_conv, mlp=None):
"""
Args:
graph_conv: graph convolution network to obtain molecule feature
graph_conv: graph convolution network to obtain molecule feature
representation
mlp: multi layer perceptron, used as final connected layer.
It can be `None` if no operation is necessary after
Expand Down Expand Up @@ -215,5 +215,6 @@ def scaled_abs_error(x0, x1):
trainer.extend(E.ProgressBar())
trainer.run()


if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion examples/tox21/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ def inference(self, X):
If the predictor is a graph convolution model
(e.g. :class:`chainer_chemistry.models.NFP`),
we can use the output of corresponding preprocessor
(e.g. :class:`chainer_chemistry.dataset.preprocessors.NFPPreprocessor`).
(e.g. :class:`chainer_chemistry.dataset.preprocessors\
.NFPPreprocessor`).
Returns:
numpy.ndarray: Prediction results
Expand Down
2 changes: 1 addition & 1 deletion examples/tox21/train_tox21.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import argparse
import chainer
from chainer import functions as F, reporter, cuda
from chainer import functions as F
from chainer import iterators as I
from chainer import links as L
from chainer import optimizers as O
Expand Down
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

here = os.path.abspath(os.path.dirname(__file__))
__version__ = imp.load_source(
'_version', os.path.join(here, 'chainer_chemistry', '_version.py')).__version__
'_version', os.path.join(here,
'chainer_chemistry', '_version.py')).__version__

setup(name='chainer-chemistry',
version=__version__,
description='Chainer Chemistry: A Library for Deep Learning in Biology and Chemistry',
description='Chainer Chemistry: A Library for Deep Learning in Biology\
and Chemistry',
author='Kosuke Nakago',
author_email='nakago@preferred.jp',
packages=find_packages(),
Expand Down
2 changes: 1 addition & 1 deletion tests/dataset_tests/parsers_tests/test_csv_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_csv_file_parser_not_return_smiles(csv_file, mols):
dataset = result['dataset']
smiles = result['smiles']
assert len(dataset) == 2
assert smiles == None
assert smiles is None

# As we want test CSVFileParser, we assume
# NFPPreprocessor works as documented.
Expand Down
2 changes: 1 addition & 1 deletion tests/dataset_tests/parsers_tests/test_sdf_file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_sdf_file_parser_not_return_smiles(sdf_file, mols):
dataset = result['dataset']
smiles = result['smiles']
assert len(dataset) == 2
assert smiles == None
assert smiles is None

# As we want test SDFFileParser, we assume
# NFPPreprocessor works as documented.
Expand Down
5 changes: 3 additions & 2 deletions tests/dataset_tests/preprocessor_tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def sample_molecule():


class TestGetAtomicNumbers(object):

def test_normal(self, sample_molecule):
actual = common.construct_atomic_number_array(sample_molecule)

Expand All @@ -29,7 +29,7 @@ def test_padding(self, sample_molecule):
def test_normal_truncated(self, sample_molecule):
with pytest.raises(ValueError):
adj = common.construct_atomic_number_array(sample_molecule, 3)


@pytest.fixture
def sample_molecule_2():
Expand Down Expand Up @@ -89,5 +89,6 @@ def test_normal_truncated(self, sample_molecule_2):
with pytest.raises(ValueError):
adj = common.construct_adj_matrix(sample_molecule_2, 6)


if __name__ == '__main__':
pytest.main([__file__, '-v', '-s'])
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_atomic_number_preprocessor_with_tox21():

# labels=None as default, and label information is not returned.
dataset = SDFFileParser(preprocessor)\
.parse(get_tox21_filepath('train'))['dataset']
.parse(get_tox21_filepath('train'))['dataset']
index = numpy.random.choice(len(dataset), None)
atoms, = dataset[index]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import numpy
import pytest

Expand Down Expand Up @@ -33,5 +32,6 @@ def test_nfp_preprocessor_assert_raises():
with pytest.raises(ValueError):
pp = GGNNPreprocessor(max_atoms=3, out_size=2)


if __name__ == '__main__':
pytest.main([__file__, '-v', '-s'])
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_schnet_preprocessor(mol, pp):
def test_schnet_preprocessor_with_tox21():
preprocessor = SchNetPreprocessor()


dataset = SDFFileParser(preprocessor, postprocess_label=None
).parse(get_tox21_filepath('train'))['dataset']

Expand Down
2 changes: 1 addition & 1 deletion tests/dataset_tests/test_numpy_tuple_feature_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestNumpyTupleDatasetFeatureIndexer(object):

def test_feature_length(self, indexer):
assert indexer.features_length() == 3

@pytest.mark.parametrize('slice_index', [0, 1, slice(0, 2, None)])
@pytest.mark.parametrize('j', [0, 1])
def test_extract_feature_by_slice(self, indexer, data, slice_index, j):
Expand Down
2 changes: 1 addition & 1 deletion tests/datasets_tests/test_tox21.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import numpy
import pytest
from chainer_chemistry.dataset.preprocessors.atomic_number_preprocessor import \
from chainer_chemistry.dataset.preprocessors.atomic_number_preprocessor import\
AtomicNumberPreprocessor

from chainer_chemistry.datasets import tox21
Expand Down
1 change: 1 addition & 0 deletions tests/links_tests/test_embed_atom_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
out_size = 4
batch_size = 2


@pytest.fixture
def model():
l = links.EmbedAtomID(in_size=in_size, out_size=out_size)
Expand Down
1 change: 1 addition & 0 deletions tests/models_tests/test_ggnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ def test_backward_gpu(model, data):
gradient_check.check_backward(model, (atom_data, adj_data), y_grad,
atol=1e-3, rtol=1e-3)


if __name__ == '__main__':
pytest.main([__file__, '-v'])
1 change: 1 addition & 0 deletions tests/models_tests/test_schnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ def test_backward_gpu(model, data):
gradient_check.check_backward(model, (atom_data, adj_data), y_grad,
atol=1e-1, rtol=1e-1)


if __name__ == '__main__':
pytest.main([__file__, '-v'])
11 changes: 7 additions & 4 deletions tests/models_tests/test_weavenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def test_backward_cpu(model, model_processed, data):
atom_data_processed, atom_data, adj_data, y_grad = data
gradient_check.check_backward(model, (atom_data, adj_data), y_grad,
atol=1e-1, rtol=1e-1)
gradient_check.check_backward(model_processed, (atom_data_processed, adj_data),
y_grad, atol=1e-1, rtol=1e-1)
gradient_check.check_backward(model_processed, (atom_data_processed,
adj_data), y_grad,
atol=1e-1, rtol=1e-1)


@pytest.mark.gpu
Expand All @@ -86,8 +87,10 @@ def test_backward_gpu(model, model_processed, data):
model_processed.to_gpu()
gradient_check.check_backward(model, (atom_data, adj_data), y_grad,
atol=1e-1, rtol=1e-1)
gradient_check.check_backward(model_processed, (atom_data_processed, adj_data),
y_grad, atol=1e-1, rtol=1e-1)
gradient_check.check_backward(model_processed, (atom_data_processed,
adj_data), y_grad,
atol=1e-1, rtol=1e-1)


if __name__ == '__main__':
pytest.main([__file__, '-v'])
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
ROCAUCEvaluator uses `sklearn.metrics.roc_auc_score` internally.
Refer: http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_auc_score.html
Refer: http://scikit-learn.org/stable/modules/generated/sklearn.metrics.\
roc_auc_score.html
"""
import numpy
import pytest
Expand Down

0 comments on commit 81b18c6

Please sign in to comment.