Skip to content

Commit 43fec22

Browse files
committed
Renamings
* InstanceBuilder => InstanceCompilerPlugin * CompilerPlugin => CategoryPlugin * Compiler => CategoryCompiler
1 parent fdbd7a4 commit 43fec22

15 files changed

Lines changed: 87 additions & 88 deletions

File tree

‎paths_cli/commands/compile.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from paths_cli.parameters import OUTPUT_FILE
55
from paths_cli.errors import MissingIntegrationError
66
from paths_cli import OPSCommandPlugin
7-
from paths_cli.compiling.plugins import CompilerPlugin, InstanceBuilder
7+
from paths_cli.compiling.plugins import (
8+
CategoryPlugin, InstanceCompilerPlugin
9+
)
810
from paths_cli.plugin_management import (
911
NamespacePluginLoader, FilePluginLoader
1012
)
@@ -56,7 +58,7 @@ def select_loader(filename):
5658
raise RuntimeError(f"Unknown file extension: {ext}")
5759

5860
def load_plugins():
59-
plugin_types = (InstanceBuilder, CompilerPlugin)
61+
plugin_types = (InstanceCompilerPlugin, CategoryPlugin)
6062
plugin_loaders = [
6163
NamespacePluginLoader('paths_cli.compiling', plugin_types),
6264
FilePluginLoader(app_dir_plugins(posix=False), plugin_types),

‎paths_cli/compiling/core.py‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
import os
21
import json
3-
import importlib
42
import yaml
53

6-
from collections import namedtuple, abc
7-
import warnings
4+
from collections import namedtuple
85

96
import logging
107

118
from .errors import InputError
12-
from .tools import custom_eval
139
from paths_cli.utils import import_thing
1410
from paths_cli.plugin_management import OPSPlugin
1511

@@ -115,7 +111,7 @@ def __init__(self, builder, *, remapper=None, after_build=None):
115111
self.builder = builder
116112

117113
def __call__(self, **dct):
118-
# TODO: change this InstanceBuilder.build to make this better
114+
# TODO: change this InstanceCompilerPlugin.build to make this better
119115
if isinstance(self.builder, str):
120116
module, _, func = self.builder.rpartition('.')
121117
builder = import_thing(module, func)
@@ -128,7 +124,7 @@ def __call__(self, **dct):
128124
return after
129125

130126

131-
class InstanceBuilder(OPSPlugin):
127+
class InstanceCompilerPlugin(OPSPlugin):
132128
"""
133129
134130
Parameters
@@ -165,7 +161,8 @@ def __init__(self, builder, parameters, name=None, aliases=None,
165161
self.builder = builder
166162
self.builder_name = str(self.builder)
167163
self.parameters = parameters
168-
self.logger = logging.getLogger(f"compiler.InstanceBuilder.{builder}")
164+
logger_name = f"compiler.InstanceCompilerPlugin.{builder}"
165+
self.logger = logging.getLogger(logger_name)
169166

170167
@property
171168
def schema_name(self):
@@ -242,7 +239,7 @@ def __call__(self, dct):
242239
return obj
243240

244241

245-
class Compiler:
242+
class CategoryCompiler:
246243
"""Generic compile class; instances for each category"""
247244
# error_on_duplicate = False # TODO: temporary
248245
error_on_duplicate = True

‎paths_cli/compiling/cvs.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import os
22
import importlib
33

4-
from .core import Compiler, InstanceBuilder, custom_eval, Parameter, Builder
4+
from .core import Parameter, Builder
5+
from .tools import custom_eval
56
from .topology import build_topology
67
from .errors import InputError
78
from paths_cli.utils import import_thing
8-
from paths_cli.compiling.plugins import CVCompilerPlugin, CompilerPlugin
9+
from paths_cli.compiling.plugins import CVCompilerPlugin, CategoryPlugin
910

1011

1112
class AllowedPackageHandler:
@@ -57,4 +58,4 @@ def cv_kwargs_remapper(dct):
5758
'mdtraj': MDTRAJ_CV_PLUGIN,
5859
}
5960

60-
CV_COMPILER = CompilerPlugin(CVCompilerPlugin, aliases=['cvs'])
61+
CV_COMPILER = CategoryPlugin(CVCompilerPlugin, aliases=['cvs'])

‎paths_cli/compiling/engines.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from .topology import build_topology
2-
from .core import Compiler, custom_eval, Builder
2+
from .core import Builder
33
from paths_cli.compiling.core import Parameter
44
from .tools import custom_eval_int
5-
from paths_cli.compiling.plugins import EngineCompilerPlugin, CompilerPlugin
6-
7-
from paths_cli.errors import MissingIntegrationError
5+
from paths_cli.compiling.plugins import EngineCompilerPlugin, CategoryPlugin
86

97
try:
108
from simtk import openmm as mm
@@ -53,4 +51,4 @@ def openmm_options(dct):
5351
name='openmm',
5452
)
5553

56-
ENGINE_COMPILER = CompilerPlugin(EngineCompilerPlugin, aliases=['engines'])
54+
ENGINE_COMPILER = CategoryPlugin(EngineCompilerPlugin, aliases=['engines'])

‎paths_cli/compiling/networks.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from paths_cli.compiling.core import (
2-
InstanceBuilder, Compiler, Builder, Parameter
2+
InstanceCompilerPlugin, Builder, Parameter
33
)
44
from paths_cli.compiling.tools import custom_eval
5-
from paths_cli.compiling.plugins import NetworkCompilerPlugin, CompilerPlugin
5+
from paths_cli.compiling.plugins import NetworkCompilerPlugin, CategoryPlugin
66
from paths_cli.compiling.root_compiler import compiler_for
77

8-
build_interface_set = InstanceBuilder(
8+
build_interface_set = InstanceCompilerPlugin(
99
builder=Builder('openpathsampling.VolumeInterfaceSet'),
1010
parameters=[
1111
Parameter('cv', compiler_for('cv'), description="the collective "
@@ -73,4 +73,4 @@ def tis_trans_info(dct):
7373
build_tis_network = TIS_NETWORK_PLUGIN
7474

7575

76-
NETWORK_COMPILER = CompilerPlugin(NetworkCompilerPlugin, aliases=['networks'])
76+
NETWORK_COMPILER = CategoryPlugin(NetworkCompilerPlugin, aliases=['networks'])

‎paths_cli/compiling/plugins.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from paths_cli.compiling.core import InstanceBuilder
1+
from paths_cli.compiling.core import InstanceCompilerPlugin
22
from paths_cli.plugin_management import OPSPlugin
33

4-
class CompilerPlugin(OPSPlugin):
4+
class CategoryPlugin(OPSPlugin):
55
"""
6-
Compiler plugins only need to be made for top-level
6+
Category plugins only need to be made for top-level
77
"""
88
error_on_duplicate = False # TODO: temporary
99
def __init__(self, plugin_class, aliases=None, requires_ops=(1, 0),
@@ -23,20 +23,20 @@ def __repr__(self):
2323
f"{self.aliases})")
2424

2525

26-
class EngineCompilerPlugin(InstanceBuilder):
26+
class EngineCompilerPlugin(InstanceCompilerPlugin):
2727
compiler_name = 'engine'
2828

29-
class CVCompilerPlugin(InstanceBuilder):
29+
class CVCompilerPlugin(InstanceCompilerPlugin):
3030
compiler_name = 'cv'
3131

32-
class VolumeCompilerPlugin(InstanceBuilder):
32+
class VolumeCompilerPlugin(InstanceCompilerPlugin):
3333
compiler_name = 'volume'
3434

35-
class NetworkCompilerPlugin(InstanceBuilder):
35+
class NetworkCompilerPlugin(InstanceCompilerPlugin):
3636
compiler_name = 'network'
3737

38-
class SchemeCompilerPlugin(InstanceBuilder):
38+
class SchemeCompilerPlugin(InstanceCompilerPlugin):
3939
compiler_name = 'scheme'
4040

41-
class StrategyCompilerPlugin(InstanceBuilder):
41+
class StrategyCompilerPlugin(InstanceCompilerPlugin):
4242
compiler_name = 'strategy'

‎paths_cli/compiling/root_compiler.py‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from paths_cli.compiling.core import Compiler, InstanceBuilder
2-
from paths_cli.compiling.plugins import CompilerPlugin
1+
from paths_cli.compiling.core import (
2+
CategoryCompiler, InstanceCompilerPlugin
3+
)
4+
from paths_cli.compiling.plugins import CategoryPlugin
35

46
import logging
57
logger = logging.getLogger(__name__)
68

7-
class CompilerRegistrationError(Exception):
9+
class CategoryCompilerRegistrationError(Exception):
810
pass
911

1012

@@ -34,7 +36,7 @@ def clean_input_key(key):
3436

3537
### Managing known compilers and aliases to the known compilers ############
3638

37-
_COMPILERS = {} # mapping: {canonical_name: Compiler}
39+
_COMPILERS = {} # mapping: {canonical_name: CategoryCompiler}
3840
_ALIASES = {} # mapping: {alias: canonical_name}
3941
# NOTE: _ALIASES does *not* include self-mapping of the canonical names
4042

@@ -57,40 +59,40 @@ def _get_compiler(compiler_name):
5759
"""
5860
if compiler_name is None:
5961
if None not in _COMPILERS:
60-
_COMPILERS[None] = Compiler(None, None)
62+
_COMPILERS[None] = CategoryCompiler(None, None)
6163
return _COMPILERS[None]
6264

6365
canonical_name = _canonical_name(compiler_name)
6466
# create a new compiler if none exists
6567
if canonical_name is None:
6668
canonical_name = compiler_name
67-
_COMPILERS[compiler_name] = Compiler(None, compiler_name)
69+
_COMPILERS[compiler_name] = CategoryCompiler(None, compiler_name)
6870
return _COMPILERS[canonical_name]
6971

7072
def _register_compiler_plugin(plugin):
71-
DUPLICATE_ERROR = CompilerRegistrationError(
73+
DUPLICATE_ERROR = CategoryCompilerRegistrationError(
7274
f"The name {plugin.name} has been reserved by another compiler"
7375
)
7476
if plugin.name in _COMPILERS or plugin.name in _ALIASES:
7577
raise DUPLICATE_ERROR
7678

77-
compiler = _get_compiler(plugin.name)
78-
7979
# register aliases
8080
new_aliases = set(plugin.aliases) - set([plugin.name])
8181
for alias in new_aliases:
8282
if alias in _COMPILERS or alias in _ALIASES:
8383
raise DUPLICATE_ERROR
8484
_ALIASES[alias] = plugin.name
8585

86+
_ = _get_compiler(plugin.name)
87+
8688

8789
### Handling delayed loading of compilers ##################################
8890
#
8991
# Many objects need to use compilers to create their input parameters. In
9092
# order for them to be able to access dynamically-loaded plugins, we delay
9193
# the loading of the compiler by using a proxy object.
9294

93-
class _CompilerProxy:
95+
class _CategoryCompilerProxy:
9496
def __init__(self, compiler_name):
9597
self.compiler_name = compiler_name
9698

@@ -119,7 +121,7 @@ def compiler_for(compiler_name):
119121
compiler_name : str
120122
the name of the compiler to use
121123
"""
122-
return _CompilerProxy(compiler_name)
124+
return _CategoryCompilerProxy(compiler_name)
123125

124126

125127
### Registering builder plugins and user-facing register_plugins ###########
@@ -149,9 +151,9 @@ def register_plugins(plugins):
149151
builders = []
150152
compilers = []
151153
for plugin in plugins:
152-
if isinstance(plugin, InstanceBuilder):
154+
if isinstance(plugin, InstanceCompilerPlugin):
153155
builders.append(plugin)
154-
elif isinstance(plugin, CompilerPlugin):
156+
elif isinstance(plugin, CategoryPlugin):
155157
compilers.append(plugin)
156158

157159
for plugin in compilers:
@@ -166,7 +168,7 @@ def _sort_user_categories(user_categories):
166168
"""Organize user input categories into compile order.
167169
168170
"Cateogories" are the first-level keys in the user input file (e.g.,
169-
'engines', 'cvs', etc.) There must be one Compiler per category.
171+
'engines', 'cvs', etc.) There must be one CategoryCompiler per category.
170172
"""
171173
user_to_canonical = {user_key: _canonical_name(user_key)
172174
for user_key in user_categories}

‎paths_cli/compiling/schemes.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from paths_cli.compiling.core import (
2-
InstanceBuilder, Compiler, Builder, Parameter
2+
Builder, Parameter
33
)
44
from paths_cli.compiling.tools import custom_eval
5-
from paths_cli.compiling.shooting import shooting_selector_compiler
65
from paths_cli.compiling.strategies import SP_SELECTOR_PARAMETER
7-
from paths_cli.compiling.plugins import SchemeCompilerPlugin, CompilerPlugin
6+
from paths_cli.compiling.plugins import SchemeCompilerPlugin, CategoryPlugin
87
from paths_cli.compiling.root_compiler import compiler_for
98

109

@@ -70,4 +69,4 @@ def __call__(self, **dct):
7069
name='scheme'
7170
)
7271

73-
SCHEME_COMPILER = CompilerPlugin(SchemeCompilerPlugin, aliases=['schemes'])
72+
SCHEME_COMPILER = CategoryPlugin(SchemeCompilerPlugin, aliases=['schemes'])

‎paths_cli/compiling/shooting.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from paths_cli.compiling.core import (
2-
InstanceBuilder, Compiler, Builder, Parameter
2+
InstanceCompilerPlugin, CategoryCompiler, Builder, Parameter
33
)
44
from paths_cli.compiling.root_compiler import compiler_for
55
from paths_cli.compiling.tools import custom_eval
6-
import numpy as np
76

8-
build_uniform_selector = InstanceBuilder(
7+
build_uniform_selector = InstanceCompilerPlugin(
98
builder=Builder('openpathsampling.UniformSelector'),
109
parameters=[],
1110
name='uniform',
@@ -17,7 +16,7 @@ def remapping_gaussian_stddev(dct):
1716
dct['l_0'] = dct.pop('mean')
1817
return dct
1918

20-
build_gaussian_selector = InstanceBuilder(
19+
build_gaussian_selector = InstanceCompilerPlugin(
2120
builder=Builder('openpathsampling.GaussianBiasSelector',
2221
remapper=remapping_gaussian_stddev),
2322
parameters=[
@@ -28,7 +27,7 @@ def remapping_gaussian_stddev(dct):
2827
name='gaussian',
2928
)
3029

31-
shooting_selector_compiler = Compiler(
30+
shooting_selector_compiler = CategoryCompiler(
3231
type_dispatch={
3332
'uniform': build_uniform_selector,
3433
'gaussian': build_gaussian_selector,

‎paths_cli/compiling/strategies.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from paths_cli.compiling.core import (
2-
Compiler, Builder, Parameter
3-
)
1+
from paths_cli.compiling.core import Builder, Parameter
42
from paths_cli.compiling.shooting import shooting_selector_compiler
53
from paths_cli.compiling.plugins import (
6-
StrategyCompilerPlugin, CompilerPlugin
4+
StrategyCompilerPlugin, CategoryPlugin
75
)
86
from paths_cli.compiling.root_compiler import compiler_for
97

@@ -100,5 +98,5 @@ def _group_parameter(group_name):
10098
name='single-replica-minus',
10199
)
102100

103-
STRATEGY_COMPILER = CompilerPlugin(StrategyCompilerPlugin,
101+
STRATEGY_COMPILER = CategoryPlugin(StrategyCompilerPlugin,
104102
aliases=['strategies'])

0 commit comments

Comments
 (0)