Skip to content

Commit fe719e3

Browse files
authored
Merge pull request #59 from dwhswenson/pylint-compiling
pylint/flake8: `paths_cli.compiling`
2 parents d2eca56 + acc6be2 commit fe719e3

13 files changed

Lines changed: 72 additions & 28 deletions

File tree

‎paths_cli/compiling/core.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import json
2-
import yaml
3-
4-
from collections import namedtuple
5-
62
import logging
73

8-
from .errors import InputError
94
from paths_cli.utils import import_thing
105
from paths_cli.plugin_management import OPSPlugin
6+
from paths_cli.compiling.errors import InputError
7+
118

129
def listify(obj):
1310
listified = False
@@ -16,16 +13,20 @@ def listify(obj):
1613
listified = True
1714
return obj, listified
1815

16+
1917
def unlistify(obj, listified):
2018
if listified:
2119
assert len(obj) == 1
2220
obj = obj[0]
2321
return obj
2422

23+
2524
REQUIRED_PARAMETER = object()
2625

26+
2727
class Parameter:
2828
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
29+
2930
def __init__(self, name, loader, *, json_type=None, description=None,
3031
default=REQUIRED_PARAMETER, aliases=None):
3132
if isinstance(json_type, str):
@@ -150,6 +151,7 @@ class InstanceCompilerPlugin(OPSPlugin):
150151
"""
151152
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
152153
category = None
154+
153155
def __init__(self, builder, parameters, name=None, aliases=None,
154156
requires_ops=(1, 0), requires_cli=(0, 3)):
155157
super().__init__(requires_ops, requires_cli)
@@ -239,7 +241,7 @@ def __call__(self, dct):
239241
ops_dct = self.compile_attrs(dct)
240242
self.logger.debug("Building...")
241243
self.logger.debug(ops_dct)
242-
obj = self.builder(**ops_dct)
244+
obj = self.builder(**ops_dct)
243245
self.logger.debug(obj)
244246
return obj
245247

@@ -260,7 +262,7 @@ def _compile_str(self, name):
260262
self.logger.debug(f"Looking for '{name}'")
261263
try:
262264
return self.named_objs[name]
263-
except KeyError as e:
265+
except KeyError:
264266
raise InputError.unknown_name(self.label, name)
265267

266268
def _compile_dict(self, dct):

‎paths_cli/compiling/cvs.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import os
2-
import importlib
3-
4-
from .core import Parameter, Builder
5-
from .tools import custom_eval
6-
from .topology import build_topology
7-
from .errors import InputError
1+
from paths_cli.compiling.core import Parameter, Builder
2+
from paths_cli.compiling.tools import custom_eval
3+
from paths_cli.compiling.topology import build_topology
4+
from paths_cli.compiling.errors import InputError
85
from paths_cli.utils import import_thing
96
from paths_cli.compiling.plugins import CVCompilerPlugin, CategoryPlugin
107

@@ -21,6 +18,7 @@ def __call__(self, source):
2118
# on ImportError, we leave the error unchanged
2219
return func
2320

21+
2422
def _cv_kwargs_remapper(dct):
2523
kwargs = dct.pop('kwargs', {})
2624
dct.update(kwargs)

‎paths_cli/compiling/engines.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from .topology import build_topology
2-
from .core import Builder
1+
from paths_cli.compiling.topology import build_topology
2+
from paths_cli.compiling.core import Builder
33
from paths_cli.compiling.core import Parameter
4-
from .tools import custom_eval_int_strict_pos
4+
from paths_cli.compiling.tools import custom_eval_int_strict_pos
55
from paths_cli.compiling.plugins import EngineCompilerPlugin, CategoryPlugin
66

7+
78
def load_openmm_xml(filename):
89
from paths_cli.compat.openmm import HAS_OPENMM, mm
910
if not HAS_OPENMM: # -no-cov-
@@ -14,6 +15,7 @@ def load_openmm_xml(filename):
1415

1516
return obj
1617

18+
1719
def _openmm_options(dct):
1820
n_steps_per_frame = dct.pop('n_steps_per_frame')
1921
n_frames_max = dct.pop('n_frames_max')

‎paths_cli/compiling/errors.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,3 @@ def invalid_input(cls, value, attr):
99
@classmethod
1010
def unknown_name(cls, type_name, name):
1111
return cls(f"Unable to find object named {name} in {type_name}")
12-

‎paths_cli/compiling/networks.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
parameters=[
1111
Parameter('cv', compiler_for('cv'), description="the collective "
1212
"variable for this interface set"),
13-
Parameter('minvals', custom_eval), # TODO fill in JSON types
14-
Parameter('maxvals', custom_eval), # TODO fill in JSON types
13+
Parameter('minvals', custom_eval), # TODO fill in JSON types
14+
Parameter('maxvals', custom_eval), # TODO fill in JSON types
1515
],
1616
name='interface-set'
1717
)
1818

19+
1920
def mistis_trans_info(dct):
2021
dct = dct.copy()
2122
transitions = dct.pop('transitions')
@@ -31,6 +32,7 @@ def mistis_trans_info(dct):
3132
dct['trans_info'] = trans_info
3233
return dct
3334

35+
3436
def tis_trans_info(dct):
3537
# remap TIS into MISTIS format
3638
dct = dct.copy()
@@ -42,6 +44,7 @@ def tis_trans_info(dct):
4244
'interfaces': interface_set}]
4345
return mistis_trans_info(dct)
4446

47+
4548
TPS_NETWORK_PLUGIN = NetworkCompilerPlugin(
4649
builder=Builder('openpathsampling.TPSNetwork'),
4750
parameters=[
@@ -60,6 +63,7 @@ def tis_trans_info(dct):
6063
name='mistis'
6164
)
6265

66+
6367
TIS_NETWORK_PLUGIN = NetworkCompilerPlugin(
6468
builder=Builder('openpathsampling.MISTISNetwork'),
6569
parameters=[Parameter('trans_info', tis_trans_info)],

‎paths_cli/compiling/plugins.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from paths_cli.compiling.core import InstanceCompilerPlugin
22
from paths_cli.plugin_management import OPSPlugin
33

4+
45
class CategoryPlugin(OPSPlugin):
56
"""
67
Category plugins only need to be made for top-level
78
"""
89
def __init__(self, plugin_class, aliases=None, requires_ops=(1, 0),
9-
requires_cli=(0,4)):
10+
requires_cli=(0, 3)):
1011
super().__init__(requires_ops, requires_cli)
1112
self.plugin_class = plugin_class
1213
if aliases is None:
@@ -25,17 +26,22 @@ def __repr__(self):
2526
class EngineCompilerPlugin(InstanceCompilerPlugin):
2627
category = 'engine'
2728

29+
2830
class CVCompilerPlugin(InstanceCompilerPlugin):
2931
category = 'cv'
3032

33+
3134
class VolumeCompilerPlugin(InstanceCompilerPlugin):
3235
category = 'volume'
3336

37+
3438
class NetworkCompilerPlugin(InstanceCompilerPlugin):
3539
category = 'network'
3640

41+
3742
class SchemeCompilerPlugin(InstanceCompilerPlugin):
3843
category = 'scheme'
3944

45+
4046
class StrategyCompilerPlugin(InstanceCompilerPlugin):
4147
category = 'strategy'

‎paths_cli/compiling/root_compiler.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
logger = logging.getLogger(__name__)
88

9+
910
class CategoryCompilerRegistrationError(Exception):
1011
pass
1112

@@ -22,6 +23,7 @@ class CategoryCompilerRegistrationError(Exception):
2223

2324
COMPILE_ORDER = _DEFAULT_COMPILE_ORDER.copy()
2425

26+
2527
def clean_input_key(key):
2628
# TODO: move this to core
2729
"""
@@ -34,12 +36,14 @@ def clean_input_key(key):
3436
key = key.replace("-", "_")
3537
return key
3638

39+
3740
### Managing known compilers and aliases to the known compilers ############
3841

3942
_COMPILERS = {} # mapping: {canonical_name: CategoryCompiler}
4043
_ALIASES = {} # mapping: {alias: canonical_name}
4144
# NOTE: _ALIASES does *not* include self-mapping of the canonical names
4245

46+
4347
def _canonical_name(alias):
4448
"""Take an alias or a compiler name and return the compiler name
4549
@@ -51,6 +55,7 @@ def _canonical_name(alias):
5155
alias_to_canonical.update({pname: pname for pname in _COMPILERS})
5256
return alias_to_canonical.get(alias, None)
5357

58+
5459
def _get_compiler(category):
5560
"""
5661
_get_compiler must only be used after the CategoryCompilers have been
@@ -69,6 +74,7 @@ def _get_compiler(category):
6974
_COMPILERS[category] = CategoryCompiler(None, category)
7075
return _COMPILERS[canonical_name]
7176

77+
7278
def _register_compiler_plugin(plugin):
7379
DUPLICATE_ERROR = CategoryCompilerRegistrationError(
7480
f"The category '{plugin.name}' has been reserved by another plugin"
@@ -87,7 +93,7 @@ def _register_compiler_plugin(plugin):
8793

8894

8995
### Handling delayed loading of compilers ##################################
90-
#
96+
9197
# Many objects need to use compilers to create their input parameters. In
9298
# order for them to be able to access dynamically-loaded plugins, we delay
9399
# the loading of the compiler by using a proxy object.
@@ -111,6 +117,7 @@ def named_objs(self):
111117
def __call__(self, dct):
112118
return self._proxy(dct)
113119

120+
114121
def compiler_for(category):
115122
"""Delayed compiler calling.
116123
@@ -142,11 +149,13 @@ def _get_registration_names(plugin):
142149
found_names.add(name)
143150
return ordered_names
144151

152+
145153
def _register_builder_plugin(plugin):
146154
compiler = _get_compiler(plugin.category)
147155
for name in _get_registration_names(plugin):
148156
compiler.register_builder(plugin, name)
149157

158+
150159
def register_plugins(plugins):
151160
builders = []
152161
compilers = []
@@ -162,6 +171,7 @@ def register_plugins(plugins):
162171
for plugin in builders:
163172
_register_builder_plugin(plugin)
164173

174+
165175
### Performing the compiling of user input #################################
166176

167177
def _sort_user_categories(user_categories):
@@ -179,6 +189,7 @@ def _sort_user_categories(user_categories):
179189
)
180190
return sorted_keys
181191

192+
182193
def do_compile(dct):
183194
"""Main function for compiling user input to objects.
184195
"""

‎paths_cli/compiling/schemes.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
name='spring-shooting',
2727
)
2828

29+
2930
class BuildSchemeStrategy:
3031
def __init__(self, scheme_class, default_global_strategy):
3132
self.scheme_class = scheme_class

‎paths_cli/compiling/shooting.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
from paths_cli.compiling.root_compiler import compiler_for
55
from paths_cli.compiling.tools import custom_eval
66

7+
78
build_uniform_selector = InstanceCompilerPlugin(
89
builder=Builder('openpathsampling.UniformSelector'),
910
parameters=[],
1011
name='uniform',
1112
)
1213

14+
1315
def _remapping_gaussian_stddev(dct):
1416
dct['alpha'] = 0.5 / dct.pop('stddev')**2
1517
dct['collectivevariable'] = dct.pop('cv')
1618
dct['l_0'] = dct.pop('mean')
1719
return dct
1820

21+
1922
build_gaussian_selector = InstanceCompilerPlugin(
2023
builder=Builder('openpathsampling.GaussianBiasSelector',
2124
remapper=_remapping_gaussian_stddev),
@@ -27,6 +30,7 @@ def _remapping_gaussian_stddev(dct):
2730
name='gaussian',
2831
)
2932

33+
3034
shooting_selector_compiler = CategoryCompiler(
3135
type_dispatch={
3236
'uniform': build_uniform_selector,

‎paths_cli/compiling/strategies.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
)
66
from paths_cli.compiling.root_compiler import compiler_for
77

8+
89
def _strategy_name(class_name):
910
return f"openpathsampling.strategies.{class_name}"
1011

12+
1113
def _group_parameter(group_name):
1214
return Parameter('group', str, default=group_name,
1315
description="the group name for these movers")
1416

17+
1518
# TODO: maybe this moves into shooting once we have the metadata?
1619
SP_SELECTOR_PARAMETER = Parameter('selector', shooting_selector_compiler,
1720
default=None)
18-
1921
ENGINE_PARAMETER = Parameter('engine', compiler_for('engine'),
2022
description="the engine for moves of this "
2123
"type")
@@ -39,6 +41,7 @@ def _group_parameter(group_name):
3941
name='one-way-shooting',
4042
)
4143
build_one_way_shooting_strategy = ONE_WAY_SHOOTING_STRATEGY_PLUGIN
44+
4245
# build_two_way_shooting_strategy = StrategyCompilerPlugin(
4346
# builder=Builder(_strategy_name("TwoWayShootingStrategy")),
4447
# parameters = [

0 commit comments

Comments
 (0)