Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
1850972
Add core & engines for yaml compiling
dwhswenson Mar 21, 2021
4392e41
Remove named_obj param in engines, topologies
dwhswenson Mar 21, 2021
2a81273
CVs and tests (without named_objs)
dwhswenson Mar 21, 2021
3be9450
volumes and partial tests for volumes
dwhswenson Mar 21, 2021
dfbf36c
Moved tests over to testing dir
dwhswenson Mar 21, 2021
e1a778f
remove named objs; still seems to work
dwhswenson Mar 24, 2021
b3edf04
Seems to work up to networks now!
dwhswenson Mar 24, 2021
2ed6990
Seems to work through TPS schemes!
dwhswenson Mar 25, 2021
3c45b87
steps toward parsing simulations
dwhswenson Mar 26, 2021
248cef0
Add compile command
dwhswenson Apr 8, 2021
10ce9d2
Merge branch 'main' into sim-setup
dwhswenson Apr 10, 2021
0657882
Merge branch 'wizard' into sim-setup
dwhswenson Jun 18, 2021
45e77d6
long forgotten stash with lots of useful stuff
dwhswenson Jul 24, 2021
728083c
add tests/parsing/__init__.py
dwhswenson Jul 24, 2021
87029dd
tests for volumes combinations
dwhswenson Jul 24, 2021
ef1f086
fix for location of MDTrajTopology
dwhswenson Jul 24, 2021
55c2dbd
improvements to testing
dwhswenson Jul 24, 2021
e3ecd1e
Add tests for shooting
dwhswenson Jul 25, 2021
b6254ec
fix shooting tests
dwhswenson Jul 25, 2021
3597dd6
first steps toward autodocumenting yaml structures
dwhswenson Jul 26, 2021
1b2bab0
add json schema support to MDTraj CV
dwhswenson Jul 26, 2021
28d37f7
start using new parameters in volumes
dwhswenson Jul 27, 2021
1181edc
Merge branch 'main' of github.com:openpathsampling/openpathsampling-c…
dwhswenson Jul 27, 2021
76da8bc
mock => unittest.mock
dwhswenson Jul 27, 2021
345b77c
Some more refactoring of sim-setup
dwhswenson Jul 27, 2021
f703605
switched everything over to parameter/builder
dwhswenson Jul 27, 2021
548b389
remove now-unused classes
dwhswenson Jul 27, 2021
8f9fe2e
Start switch to plugins
dwhswenson Jul 29, 2021
379e5f1
add plugins files
dwhswenson Jul 29, 2021
e513680
Start toward registering parsing via plugins
dwhswenson Aug 10, 2021
bdb1ab9
proof of principle for plugin registration
dwhswenson Aug 10, 2021
f31b1c9
more updates to use the new plugin model
dwhswenson Aug 10, 2021
d4b3f29
remove old parsing from engines, cvs, volumes
dwhswenson Aug 11, 2021
c8bf0c3
add tests/parsing/utils
dwhswenson Aug 11, 2021
8163cfe
Remove old parsers: networks, schemes, strategies
dwhswenson Aug 11, 2021
769d3f7
skeleton of root_parser tests
dwhswenson Aug 13, 2021
1cd4885
some root parser tests
dwhswenson Aug 13, 2021
eb78804
more tests for root_parser
dwhswenson Aug 13, 2021
59b890c
Some docstrings and tests for core
dwhswenson Sep 5, 2021
656a22e
Merge branch 'main' of github.com:openpathsampling/openpathsampling-c…
dwhswenson Sep 5, 2021
cb69db6
(most) tests for InstanceBuilder
dwhswenson Sep 5, 2021
eab9b4a
more tests in parsing core
dwhswenson Sep 5, 2021
2bd0eea
tests for helpers in compile command
dwhswenson Sep 5, 2021
f7cc88c
steps toward testing compile command
dwhswenson Sep 6, 2021
b64ea30
major refactor of root_paser
dwhswenson Sep 7, 2021
d77b8aa
Major rename: parsing => compiling
dwhswenson Sep 7, 2021
030679c
more tests for root_compiler
dwhswenson Sep 7, 2021
4b7dd7c
more cleanup to get tests running
dwhswenson Sep 7, 2021
ddc6a17
add test/commands/utils
dwhswenson Sep 7, 2021
ffbf6c5
cleanup; start to tests move scheme compiling
dwhswenson Sep 7, 2021
1b6f505
Fix the error_on_duplicate issue
dwhswenson Sep 8, 2021
ad714d9
fix other problem with duplication
dwhswenson Sep 8, 2021
1e531ba
more tests for compiling.schemes
dwhswenson Sep 8, 2021
71719d5
more testing/coverage
dwhswenson Sep 8, 2021
2f9dc3d
remove unneeded options for InputError
dwhswenson Sep 8, 2021
fdbd7a4
fix typo
dwhswenson Sep 8, 2021
43fec22
Renamings
dwhswenson Sep 8, 2021
4e74899
Rename: compiler_name => category
dwhswenson Sep 8, 2021
0318227
refactor for reusable get_installed_plugins
dwhswenson Sep 8, 2021
3daa542
add docs/compiling.rst
dwhswenson Sep 8, 2021
7fce8a5
compiling/__init__; and always error on duplicate
dwhswenson Sep 9, 2021
9d61206
Apply suggestions from code review
dwhswenson Sep 23, 2021
823ef0c
Update paths_cli/tests/compiling/test_volumes.py
dwhswenson Sep 23, 2021
454ff28
some fixes from review
dwhswenson Sep 23, 2021
571d283
redo reload modules after test
dwhswenson Sep 24, 2021
8904fd3
complete skipped tests in compiling/test_core
dwhswenson Sep 25, 2021
fb518ba
finish skipped tests in test_root_compiler
dwhswenson Sep 25, 2021
e463087
add compat.openmm to handle OpenMM imports
dwhswenson Sep 26, 2021
2dad4d8
fix name of unit when None
dwhswenson Sep 26, 2021
0b106e6
fix skiptest
dwhswenson Sep 26, 2021
ff4bc78
use custom_eval_int_strict_pos
dwhswenson Sep 26, 2021
63a0f33
bring coverage back to 100%
dwhswenson Sep 26, 2021
3fd2509
don't use endswith on possible None
dwhswenson Sep 26, 2021
854137c
cleanup per review comments
dwhswenson Sep 27, 2021
a43b2c0
Update paths_cli/compiling/core.py
dwhswenson Sep 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
first steps toward autodocumenting yaml structures
  • Loading branch information
dwhswenson committed Jul 26, 2021
commit 3597dd6ba69fc621bc2e835ebe825fe37df578ef
81 changes: 79 additions & 2 deletions paths_cli/parsing/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import json
import importlib
import yaml

Expand All @@ -22,14 +23,67 @@ def unlistify(obj, listified):
obj = obj[0]
return obj

class Parameter:
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
def __init__(self, name, loader, required=True, json_type=None,
description=None):
json_type = self._get_from_loader(loader, 'json_type', json_type)
description = self._get_from_loader(loader, 'description',
description)
if isinstance(json_type, str):
try:
json_type = json.loads(json_type)
except json.decoder.JSONDecodeError:
# TODO: maybe log this in case it represents an issue?
pass

self.name = name
self.loader = loader
self.json_type = json_type
self.description = description
self.required = required

@staticmethod
def _get_from_loader(loader, attr_name, attr):
if attr is None:
try:
attr = getattr(loader, attr_name)
except AttributeError:
pass
return attr


def __call__(self, *args, **kwargs):
# check correct call signature here
return self.loader(*args, **kwargs)

def to_json_schema(self, schema_context=None):
dct = {
'type': self.json_type,
'description': self.description,
}
return self.name, dct


class InstanceBuilder:
# TODO: add schema as an input so we can autogenerate our JSON schema!
SCHEMA = "http://openpathsampling.org/schemas/sim-setup/draft01.json"
def __init__(self, builder, attribute_table, optional_attributes=None,
defaults=None, module=None, remapper=None):
defaults=None, module=None, remapper=None, parameters=None,
object_type=None, name=None):
# temporary apporach to override attribute_table
if attribute_table is None and parameters is not None:
attribute_table = {p.name: p.loader for p in parameters
if p.required}
if optional_attributes is None and parameters is not None:
optional_attributes = {p.name: p.loader for p in parameters
if not p.required}
self.object_type = object_type
self.name = name
self.module = module
self.builder = builder
self.builder_name = str(self.builder)
self.attribute_table = attribute_table
self.parameters = parameters
if optional_attributes is None:
optional_attributes = {}
self.optional_attributes = optional_attributes
Expand All @@ -42,6 +96,29 @@ def __init__(self, builder, attribute_table, optional_attributes=None,
self.defaults = defaults
self.logger = logging.getLogger(f"parser.InstanceBuilder.{builder}")

@property
def schema_name(self):
if not self.name.endswith(self.object_type):
schema_name = f"{self.name}-{self.object_type}"
else:
schema_name = name
return schema_name

def to_json_schema(self, schema_context=None):
parameters = dict(p.to_json_schema() for p in self.parameters)
properties = {
'name': {'type': 'string'},
'type': {'type': 'string',
'enum': [self.name]},
}
properties.update(parameters)
required = [p.name for p in self.parameters if p.required]
dct = {
'properties': properties,
'required': required,
}
return self.schema_name, dct

def select_builder(self, dct):
if self.module is not None:
builder = getattr(importlib.import_module(self.module), self.builder)
Expand Down
44 changes: 21 additions & 23 deletions paths_cli/parsing/cvs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import importlib

from .core import Parser, InstanceBuilder, custom_eval
from .core import Parser, InstanceBuilder, custom_eval, Parameter
from .topology import build_topology
from .errors import InputError

Expand All @@ -27,33 +27,31 @@ def cv_prepare_dict(dct):
# MDTraj-specific

mdtraj_source = AllowedPackageHandler("mdtraj")
MDTRAJ_ATTRS = {
'topology': build_topology,
'func': mdtraj_source,
'kwargs': lambda kwargs: {key: custom_eval(arg)
for key, arg in kwargs.items()},
}
# MDTRAJ_ATTRS = {
# 'topology': build_topology,
# 'func': mdtraj_source,
# 'kwargs': lambda kwargs: {key: custom_eval(arg)
# for key, arg in kwargs.items()},
# }

MDTRAJ_SCHEMA = {
'topology': {
'type': 'string',
'description': 'topology from file or engine name',
},
'func': {
'type': 'string',
'description': 'MDTraj function, e.g., ``compute_distances``',
},
'kwargs': {
'type': 'object',
'description': 'keyword arguments for ``func``',
},
}
MDTRAJ_PARAMETERS = [
Parameter('topology', build_topology),
Parameter('func', mdtraj_source, json_type='string',
description="MDTraj function, e.g., ``compute_distances``"),
Parameter('kwargs', lambda kwargs: {key: custom_eval(arg)
for key, arg in kwargs.items()},
json_type='object',
description="keyword arguments for ``func``",
required=True), # TODO: bug in current: shoudl be req=False
]

build_mdtraj_function_cv = InstanceBuilder(
attribute_table=None, # temp
module='openpathsampling.experimental.storage.collective_variables',
builder='MDTrajFunctionCV',
attribute_table=MDTRAJ_ATTRS,
remapper = cv_prepare_dict,
# attribute_table=MDTRAJ_ATTRS,
parameters=MDTRAJ_PARAMETERS,
remapper=cv_prepare_dict,
)

# TODO: this should replace TYPE_MAPPING and cv_parser
Expand Down
13 changes: 9 additions & 4 deletions paths_cli/parsing/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def get_topology_from_file(dct):

class MultiStrategyBuilder:
# move to core
def __init__(self, strategies, label):
def __init__(self, strategies, label, description=None, json_type=None):
self.strategies = strategies
self.label = label
self.description = description
self.json_type = json_type

def __call__(self, dct):
for strategy in self.strategies:
Expand All @@ -37,6 +39,9 @@ def __call__(self, dct):
# only get here if we failed
raise InputError.invalid_input(dct, self.label)

build_topology = MultiStrategyBuilder([get_topology_from_file,
get_topology_from_engine],
label='topology')
build_topology = MultiStrategyBuilder(
[get_topology_from_file, get_topology_from_engine],
label='topology',
description="topology from file or engine name",
json_type='string'
)
20 changes: 16 additions & 4 deletions paths_cli/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ def cv_and_states():
state_B = paths.CVDefinedVolume(cv, 1, float("inf")).named("B")
return cv, state_A, state_B

@pytest.fixture
def transition_traj():
init_traj = make_1d_traj([-0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1],
[2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0])
return init_traj

@pytest.fixture
def tps_network_and_traj(cv_and_states):
def tps_network_and_traj(cv_and_states, transition_traj):
_, state_A, state_B = cv_and_states
network = paths.TPSNetwork(state_A, state_B)
init_traj = make_1d_traj([-0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1],
[2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0])
return (network, init_traj)
return network, transition_traj

@pytest.fixture
def tps_fixture(flat_engine, tps_network_and_traj):
Expand All @@ -38,3 +41,12 @@ def tps_fixture(flat_engine, tps_network_and_traj):
engine=flat_engine)
init_conds = scheme.initial_conditions_from_trajectories(traj)
return (scheme, network, flat_engine, init_conds)


@pytest.fixture
def tis_network(cv_and_states):
cv, state_A, state_B = cv_and_states
interfaces = paths.VolumeInterfaceSet(cv, float("-inf"),
[0.0, 0.1, 0.2])
network = paths.MISTISNetwork([(state_A, interfaces, state_B)])
return network