Skip to content

Commit d77b8aa

Browse files
committed
Major rename: parsing => compiling
1 parent b64ea30 commit d77b8aa

33 files changed

Lines changed: 490 additions & 478 deletions

‎paths_cli/commands/compile.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import click
22

3-
from paths_cli.parsing.root_parser import parse, register_plugins
3+
from paths_cli.compiling.root_compiler import do_compile, register_plugins
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.parsing.plugins import ParserPlugin, InstanceBuilder
7+
from paths_cli.compiling.plugins import CompilerPlugin, InstanceBuilder
88
from paths_cli.plugin_management import (
99
NamespacePluginLoader, FilePluginLoader
1010
)
@@ -18,7 +18,7 @@ def import_module(module_name, format_type=None, install=None):
1818
if format_type is None:
1919
format_type = module_name
2020

21-
msg = "Unable to find a parser for f{format_type} on your system."
21+
msg = "Unable to find a compiler for f{format_type} on your system."
2222
if install is not None:
2323
msg += " Please install f{install} to use this format."
2424

@@ -55,9 +55,9 @@ def select_loader(filename):
5555
raise RuntimeError(f"Unknown file extension: {ext}")
5656

5757
def load_plugins():
58-
plugin_types = (InstanceBuilder, ParserPlugin)
58+
plugin_types = (InstanceBuilder, CompilerPlugin)
5959
plugin_loaders = [
60-
NamespacePluginLoader('paths_cli.parsing', plugin_types),
60+
NamespacePluginLoader('paths_cli.compiling', plugin_types),
6161
FilePluginLoader(app_dir_plugins(posix=False), plugin_types),
6262
FilePluginLoader(app_dir_plugins(posix=True), plugin_types),
6363
NamespacePluginLoader('paths_cli_plugins', plugin_types)
@@ -78,7 +78,7 @@ def compile_(input_file, output_file):
7878
plugins = load_plugins()
7979
register_plugins(plugins)
8080

81-
objs = parse(dct)
81+
objs = do_compile(dct)
8282
print(objs)
8383
storage = OUTPUT_FILE.get(output_file)
8484
storage.save(objs)
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def to_json_schema(self, schema_context=None):
8383
class Builder:
8484
"""Builder is a wrapper class to simplify writing builder functions.
8585
86-
When the parsed parameters dictionary matches the kwargs for your class,
87-
you can create a valid delayed builder function with
86+
When the compiled parameters dictionary matches the kwargs for your
87+
class, you can create a valid delayed builder function with
8888
8989
.. code::
9090
@@ -149,7 +149,7 @@ class InstanceBuilder(OPSPlugin):
149149
version of the OPS CLI requires for this functionality
150150
"""
151151
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
152-
parser_name = None
152+
compiler_name = None
153153
error_on_duplicate = False # TODO: temporary
154154
def __init__(self, builder, parameters, name=None, aliases=None,
155155
requires_ops=(1, 0), requires_cli=(0, 3)):
@@ -165,14 +165,14 @@ def __init__(self, builder, parameters, name=None, aliases=None,
165165
self.builder = builder
166166
self.builder_name = str(self.builder)
167167
self.parameters = parameters
168-
self.logger = logging.getLogger(f"parser.InstanceBuilder.{builder}")
168+
self.logger = logging.getLogger(f"compiler.InstanceBuilder.{builder}")
169169

170170
@property
171171
def schema_name(self):
172-
if not self.name.endswith(self.parser_name):
172+
if not self.name.endswith(self.compiler_name):
173173
schema_name = f"{self.name}-{self.object_type}"
174174
else:
175-
schema_name = self.parser_name
175+
schema_name = self.compiler_name
176176
return schema_name
177177

178178
def to_json_schema(self, schema_context=None):
@@ -190,8 +190,8 @@ def to_json_schema(self, schema_context=None):
190190
}
191191
return self.schema_name, dct
192192

193-
def parse_attrs(self, dct):
194-
"""Parse the user input dictionary to mapping of name to object.
193+
def compile_attrs(self, dct):
194+
"""Compile the user input dictionary to mapping of name to object.
195195
196196
This changes the values in the key-value pairs we get from the file
197197
into objects that are suitable as input to a function. Further
@@ -234,16 +234,16 @@ def parse_attrs(self, dct):
234234
def __call__(self, dct):
235235
# TODO: convert this to taking **dct -- I think that makes more
236236
# sense
237-
ops_dct = self.parse_attrs(dct)
237+
ops_dct = self.compile_attrs(dct)
238238
self.logger.debug("Building...")
239239
self.logger.debug(ops_dct)
240240
obj = self.builder(**ops_dct)
241241
self.logger.debug(obj)
242242
return obj
243243

244244

245-
class Parser:
246-
"""Generic parse class; instances for each category"""
245+
class Compiler:
246+
"""Generic compile class; instances for each category"""
247247
error_on_duplicate = False # TODO: temporary
248248
def __init__(self, type_dispatch, label):
249249
if type_dispatch is None:
@@ -252,17 +252,17 @@ def __init__(self, type_dispatch, label):
252252
self.label = label
253253
self.named_objs = {}
254254
self.all_objs = []
255-
logger_name = f"parser.Parser[{label}]"
255+
logger_name = f"compiler.Compiler[{label}]"
256256
self.logger = logging.getLogger(logger_name)
257257

258-
def _parse_str(self, name):
258+
def _compile_str(self, name):
259259
self.logger.debug(f"Looking for '{name}'")
260260
try:
261261
return self.named_objs[name]
262262
except KeyError as e:
263263
raise InputError.unknown_name(self.label, name)
264264

265-
def _parse_dict(self, dct):
265+
def _compile_dict(self, dct):
266266
dct = dct.copy() # make a local copy
267267
name = dct.pop('name', None)
268268
type_name = dct.pop('type')
@@ -292,14 +292,14 @@ def register_builder(self, builder, name):
292292
else:
293293
self.type_dispatch[name] = builder
294294

295-
def parse(self, dct):
295+
def compile(self, dct):
296296
if isinstance(dct, str):
297-
return self._parse_str(dct)
297+
return self._compile_str(dct)
298298
else:
299-
return self._parse_dict(dct)
299+
return self._compile_dict(dct)
300300

301301
def __call__(self, dct):
302302
dcts, listified = listify(dct)
303-
objs = [self.parse(d) for d in dcts]
303+
objs = [self.compile(d) for d in dcts]
304304
results = unlistify(objs, listified)
305305
return results
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import os
22
import importlib
33

4-
from .core import Parser, InstanceBuilder, custom_eval, Parameter, Builder
4+
from .core import Compiler, InstanceBuilder, custom_eval, Parameter, Builder
55
from .topology import build_topology
66
from .errors import InputError
77
from paths_cli.utils import import_thing
8-
from paths_cli.parsing.plugins import CVParserPlugin, ParserPlugin
8+
from paths_cli.compiling.plugins import CVCompilerPlugin, CompilerPlugin
99

1010

1111
class AllowedPackageHandler:
@@ -27,7 +27,7 @@ def cv_kwargs_remapper(dct):
2727

2828

2929
# MDTraj-specific
30-
MDTRAJ_CV_PLUGIN = CVParserPlugin(
30+
MDTRAJ_CV_PLUGIN = CVCompilerPlugin(
3131
builder=Builder('openpathsampling.experimental.storage.'
3232
'collective_variables.MDTrajFunctionCV',
3333
remapper=cv_kwargs_remapper),
@@ -51,10 +51,10 @@ def cv_kwargs_remapper(dct):
5151
name="mdtraj"
5252
)
5353

54-
# Main CV parser
54+
# Main CV compiler
5555

5656
TYPE_MAPPING = {
5757
'mdtraj': MDTRAJ_CV_PLUGIN,
5858
}
5959

60-
CV_PARSER = ParserPlugin(CVParserPlugin, aliases=['cvs'])
60+
CV_COMPILER = CompilerPlugin(CVCompilerPlugin, aliases=['cvs'])
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from .topology import build_topology
2-
from .core import Parser, custom_eval, Builder
3-
from paths_cli.parsing.core import Parameter
2+
from .core import Compiler, custom_eval, Builder
3+
from paths_cli.compiling.core import Parameter
44
from .tools import custom_eval_int
5-
from paths_cli.parsing.plugins import EngineParserPlugin, ParserPlugin
5+
from paths_cli.compiling.plugins import EngineCompilerPlugin, CompilerPlugin
66

77
from paths_cli.errors import MissingIntegrationError
88

@@ -46,11 +46,11 @@ def openmm_options(dct):
4646
"trajectory")),
4747
]
4848

49-
OPENMM_PLUGIN = EngineParserPlugin(
49+
OPENMM_PLUGIN = EngineCompilerPlugin(
5050
builder=Builder('openpathsampling.engines.openmm.Engine',
5151
remapper=openmm_options),
5252
parameters=OPENMM_PARAMETERS,
5353
name='openmm',
5454
)
5555

56-
ENGINE_PARSER = ParserPlugin(EngineParserPlugin, aliases=['engines'])
56+
ENGINE_COMPILER = CompilerPlugin(EngineCompilerPlugin, aliases=['engines'])
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from paths_cli.parsing.core import (
2-
InstanceBuilder, Parser, Builder, Parameter
1+
from paths_cli.compiling.core import (
2+
InstanceBuilder, Compiler, Builder, Parameter
33
)
4-
from paths_cli.parsing.tools import custom_eval
5-
from paths_cli.parsing.plugins import NetworkParserPlugin, ParserPlugin
6-
from paths_cli.parsing.root_parser import parser_for
4+
from paths_cli.compiling.tools import custom_eval
5+
from paths_cli.compiling.plugins import NetworkCompilerPlugin, CompilerPlugin
6+
from paths_cli.compiling.root_compiler import compiler_for
77

88
build_interface_set = InstanceBuilder(
99
builder=Builder('openpathsampling.VolumeInterfaceSet'),
1010
parameters=[
11-
Parameter('cv', parser_for('cv'), description="the collective "
11+
Parameter('cv', compiler_for('cv'), description="the collective "
1212
"variable for this interface set"),
1313
Parameter('minvals', custom_eval), # TODO fill in JSON types
1414
Parameter('maxvals', custom_eval), # TODO fill in JSON types
@@ -19,12 +19,12 @@
1919
def mistis_trans_info(dct):
2020
dct = dct.copy()
2121
transitions = dct.pop('transitions')
22-
volume_parser = parser_for('volume')
22+
volume_compiler = compiler_for('volume')
2323
trans_info = [
2424
(
25-
volume_parser(trans['initial_state']),
25+
volume_compiler(trans['initial_state']),
2626
build_interface_set(trans['interfaces']),
27-
volume_parser(trans['final_state'])
27+
volume_compiler(trans['final_state'])
2828
)
2929
for trans in transitions
3030
]
@@ -42,32 +42,32 @@ def tis_trans_info(dct):
4242
'interfaces': interface_set}]
4343
return mistis_trans_info(dct)
4444

45-
TPS_NETWORK_PLUGIN = NetworkParserPlugin(
45+
TPS_NETWORK_PLUGIN = NetworkCompilerPlugin(
4646
builder=Builder('openpathsampling.TPSNetwork'),
4747
parameters=[
48-
Parameter('initial_states', parser_for('volume'),
48+
Parameter('initial_states', compiler_for('volume'),
4949
description="initial states for this transition"),
50-
Parameter('final_states', parser_for('volume'),
50+
Parameter('final_states', compiler_for('volume'),
5151
description="final states for this transition")
5252
],
5353
name='tps'
5454
)
5555

5656
build_tps_network = TPS_NETWORK_PLUGIN
5757

58-
MISTIS_NETWORK_PLUGIN = NetworkParserPlugin(
58+
MISTIS_NETWORK_PLUGIN = NetworkCompilerPlugin(
5959
parameters=[Parameter('trans_info', mistis_trans_info)],
6060
builder=Builder('openpathsampling.MISTISNetwork'),
6161
name='mistis'
6262
)
6363
build_mistis_network = MISTIS_NETWORK_PLUGIN
6464

65-
TIS_NETWORK_PLUGIN = NetworkParserPlugin(
65+
TIS_NETWORK_PLUGIN = NetworkCompilerPlugin(
6666
builder=Builder('openpathsampling.MISTISNetwork'),
6767
parameters=[Parameter('trans_info', tis_trans_info)],
6868
name='tis'
6969
)
7070
build_tis_network = TIS_NETWORK_PLUGIN
7171

7272

73-
NETWORK_PARSER = ParserPlugin(NetworkParserPlugin, aliases=['networks'])
73+
NETWORK_COMPILER = CompilerPlugin(NetworkCompilerPlugin, aliases=['networks'])

‎paths_cli/compiling/plugins.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from paths_cli.compiling.core import InstanceBuilder
2+
from paths_cli.plugin_management import OPSPlugin
3+
4+
class CompilerPlugin(OPSPlugin):
5+
"""
6+
Compiler plugins only need to be made for top-level
7+
"""
8+
error_on_duplicate = False # TODO: temporary
9+
def __init__(self, plugin_class, aliases=None, requires_ops=(1, 0),
10+
requires_cli=(0,4)):
11+
super().__init__(requires_ops, requires_cli)
12+
self.plugin_class = plugin_class
13+
if aliases is None:
14+
aliases = []
15+
self.aliases = aliases
16+
17+
@property
18+
def name(self):
19+
return self.plugin_class.compiler_name
20+
21+
22+
class EngineCompilerPlugin(InstanceBuilder):
23+
compiler_name = 'engine'
24+
25+
class CVCompilerPlugin(InstanceBuilder):
26+
compiler_name = 'cv'
27+
28+
class VolumeCompilerPlugin(InstanceBuilder):
29+
compiler_name = 'volume'
30+
31+
class NetworkCompilerPlugin(InstanceBuilder):
32+
compiler_name = 'network'
33+
34+
class SchemeCompilerPlugin(InstanceBuilder):
35+
compiler_name = 'scheme'
36+
37+
class StrategyCompilerPlugin(InstanceBuilder):
38+
compiler_name = 'strategy'

0 commit comments

Comments
 (0)