Skip to content

Commit 6132bf6

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 53dfa13 commit 6132bf6

File tree

14 files changed

+149
-151
lines changed

14 files changed

+149
-151
lines changed

openff/evaluator/_tests/test_full_workflows/test_equilibration.py

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
import os
22
import pathlib
3-
import pytest
43

4+
import pytest
55
from openff.units import unit
66
from openff.utilities.utilities import get_data_dir_path
77

8+
from openff.evaluator._tests.utils import (
9+
_copy_property_working_data,
10+
_write_force_field,
11+
)
12+
from openff.evaluator.backends import ComputeResources
13+
from openff.evaluator.backends.dask import DaskLocalCluster
14+
from openff.evaluator.client import BatchMode, EvaluatorClient, RequestOptions
815
from openff.evaluator.datasets import (
916
MeasurementSource,
1017
PhysicalPropertyDataSet,
1118
PropertyPhase,
1219
)
13-
from openff.evaluator.utils.observables import ObservableType
14-
from openff.evaluator.backends import ComputeResources
15-
from openff.evaluator.backends.dask import DaskLocalCluster
20+
from openff.evaluator.forcefield import SmirnoffForceFieldSource
21+
from openff.evaluator.layers.equilibration import EquilibrationProperty
1622
from openff.evaluator.properties import Density, EnthalpyOfMixing
1723
from openff.evaluator.server.server import Batch, EvaluatorServer
24+
from openff.evaluator.storage.query import EquilibrationDataQuery
1825
from openff.evaluator.substances import Substance
1926
from openff.evaluator.thermodynamics import ThermodynamicState
20-
from openff.evaluator.layers.equilibration import EquilibrationProperty
21-
from openff.evaluator.client import EvaluatorClient, RequestOptions, BatchMode
22-
from openff.evaluator.forcefield import SmirnoffForceFieldSource
23-
from openff.evaluator.workflow.attributes import ConditionAggregationBehavior
24-
from openff.evaluator.storage.query import EquilibrationDataQuery
25-
from openff.evaluator._tests.utils import _write_force_field, _copy_property_working_data
26-
27+
from openff.evaluator.utils.observables import ObservableType
2728
from openff.evaluator.workflow import Workflow
28-
29+
from openff.evaluator.workflow.attributes import ConditionAggregationBehavior
2930

3031

3132
def _get_equilibration_request_options(
3233
n_molecules: int = 256,
3334
error_tolerances: list = [],
34-
condition_aggregation_behavior = ConditionAggregationBehavior.All,
35+
condition_aggregation_behavior=ConditionAggregationBehavior.All,
3536
n_iterations: int = 0,
36-
3737
):
3838
dhmix_equilibration_schema = EnthalpyOfMixing.default_equilibration_schema(
3939
n_molecules=n_molecules,
4040
error_tolerances=error_tolerances,
4141
condition_aggregation_behavior=condition_aggregation_behavior,
42-
max_iterations=n_iterations
42+
max_iterations=n_iterations,
4343
)
4444
density_equilibration_schema = Density.default_equilibration_schema(
4545
n_molecules=n_molecules,
4646
error_tolerances=error_tolerances,
4747
condition_aggregation_behavior=condition_aggregation_behavior,
48-
max_iterations=n_iterations
48+
max_iterations=n_iterations,
4949
)
5050

5151
equilibration_options = RequestOptions()
@@ -74,7 +74,6 @@ def _create_equilibration_data_query(
7474
query.calculation_layer = "EquilibrationLayer"
7575
query.substance = substance
7676
return query
77-
7877

7978

8079
class TestEquilibrationLayer:
@@ -89,34 +88,35 @@ def dhmix_density_CCCO(self, tmp_path_factory):
8988
)
9089
return path
9190

92-
93-
@pytest.mark.parametrize("potential_error, density_error, aggregation_behavior, error_on_nonconvergence, success", [
94-
# passes because both conditions are met
95-
(200, 0.2, ConditionAggregationBehavior.All, True, True),
96-
# passes because at least one condition is met
97-
(200, 0.2, ConditionAggregationBehavior.Any, True, True),
98-
# fails because density error is too high
99-
(200, 0.00002, ConditionAggregationBehavior.All, True, False),
100-
# passes because at least one condition is met
101-
(200, 0.00002, ConditionAggregationBehavior.Any, True, True),
102-
# fails because one condition is not met
103-
(0.0001, 0.2, ConditionAggregationBehavior.All, True, False),
104-
# passes because at least one condition is met
105-
(0.0001, 0.2, ConditionAggregationBehavior.Any, True, True),
106-
# fails because both conditions are not met
107-
(0.0001, 0.00001, ConditionAggregationBehavior.All, True, False),
108-
(0.0001, 0.00001, ConditionAggregationBehavior.Any, True, False),
109-
110-
# all the above but they all pass because there is no error on nonconvergence
111-
(200, 0.2, ConditionAggregationBehavior.All, False, True),
112-
(200, 0.2, ConditionAggregationBehavior.Any, False, True),
113-
(200, 0.00002, ConditionAggregationBehavior.All, False, True),
114-
(200, 0.00002, ConditionAggregationBehavior.Any, False, True),
115-
(0.0001, 0.2, ConditionAggregationBehavior.All, False, True),
116-
(0.0001, 0.2, ConditionAggregationBehavior.Any, False, True),
117-
(0.0001, 0.00001, ConditionAggregationBehavior.All, False, True),
118-
(0.0001, 0.00001, ConditionAggregationBehavior.Any, False, True),
119-
])
91+
@pytest.mark.parametrize(
92+
"potential_error, density_error, aggregation_behavior, error_on_nonconvergence, success",
93+
[
94+
# passes because both conditions are met
95+
(200, 0.2, ConditionAggregationBehavior.All, True, True),
96+
# passes because at least one condition is met
97+
(200, 0.2, ConditionAggregationBehavior.Any, True, True),
98+
# fails because density error is too high
99+
(200, 0.00002, ConditionAggregationBehavior.All, True, False),
100+
# passes because at least one condition is met
101+
(200, 0.00002, ConditionAggregationBehavior.Any, True, True),
102+
# fails because one condition is not met
103+
(0.0001, 0.2, ConditionAggregationBehavior.All, True, False),
104+
# passes because at least one condition is met
105+
(0.0001, 0.2, ConditionAggregationBehavior.Any, True, True),
106+
# fails because both conditions are not met
107+
(0.0001, 0.00001, ConditionAggregationBehavior.All, True, False),
108+
(0.0001, 0.00001, ConditionAggregationBehavior.Any, True, False),
109+
# all the above but they all pass because there is no error on nonconvergence
110+
(200, 0.2, ConditionAggregationBehavior.All, False, True),
111+
(200, 0.2, ConditionAggregationBehavior.Any, False, True),
112+
(200, 0.00002, ConditionAggregationBehavior.All, False, True),
113+
(200, 0.00002, ConditionAggregationBehavior.Any, False, True),
114+
(0.0001, 0.2, ConditionAggregationBehavior.All, False, True),
115+
(0.0001, 0.2, ConditionAggregationBehavior.Any, False, True),
116+
(0.0001, 0.00001, ConditionAggregationBehavior.All, False, True),
117+
(0.0001, 0.00001, ConditionAggregationBehavior.Any, False, True),
118+
],
119+
)
120120
def test_execute_conditions(
121121
self,
122122
potential_error,
@@ -153,7 +153,6 @@ def test_execute_conditions(
153153
os.chdir(dhmix_density_CCCO)
154154
_write_force_field()
155155

156-
157156
metadata = Workflow.generate_default_metadata(
158157
dummy_enthalpy_of_mixing, "force-field.json"
159158
)
@@ -164,7 +163,7 @@ def test_execute_conditions(
164163
error_tolerances=errors,
165164
condition_aggregation_behavior=aggregation_behavior,
166165
error_on_failure=error_on_nonconvergence,
167-
max_iterations=0
166+
max_iterations=0,
168167
)
169168
workflow_schema = schema.workflow_schema
170169
workflow_schema.replace_protocol_types(
@@ -195,7 +194,6 @@ def test_execute_conditions(
195194
for file in pathlib.Path(".").rglob(pattern):
196195
file.unlink()
197196

198-
199197
for name, protocol in workflow_graph.protocols.items():
200198
if "conditional" in name:
201199
path = name.replace("|", "_")
@@ -217,18 +215,14 @@ def test_execute_conditions(
217215
raise e
218216
if not success:
219217
raise AssertionError("Equilibration should have failed")
220-
221218

222-
223219
def test_data_storage_and_retrieval(self, dummy_dataset, dhmix_density_CCCO):
224220
"""
225221
Test the storage and retrieval of equilibration data.
226222
"""
227223

228224
force_field_path = "openff-2.1.0.offxml"
229-
force_field_source = SmirnoffForceFieldSource.from_path(
230-
force_field_path
231-
)
225+
force_field_source = SmirnoffForceFieldSource.from_path(force_field_path)
232226

233227
error_tolerances = [
234228
EquilibrationProperty(
@@ -251,7 +245,7 @@ def test_data_storage_and_retrieval(self, dummy_dataset, dhmix_density_CCCO):
251245
server = EvaluatorServer(
252246
calculation_backend=calculation_backend,
253247
working_directory=".",
254-
delete_working_files=False
248+
delete_working_files=False,
255249
)
256250
with server:
257251
client = EvaluatorClient()
@@ -270,15 +264,17 @@ def test_data_storage_and_retrieval(self, dummy_dataset, dhmix_density_CCCO):
270264
storage_path = "stored_data"
271265
storage_path = pathlib.Path(storage_path)
272266
assert len(list(storage_path.rglob("*/output.pdb"))) == 0
273-
267+
274268
# test equilibration
275269
request, error = client.request_estimate(
276270
dummy_dataset,
277271
force_field_source,
278272
equilibration_options,
279273
)
280274
assert error is None
281-
results, exception = request.results(synchronous=True, polling_interval=30)
275+
results, exception = request.results(
276+
synchronous=True, polling_interval=30
277+
)
282278

283279
# check execution finished
284280
assert exception is None
@@ -311,4 +307,3 @@ def test_data_storage_and_retrieval(self, dummy_dataset, dhmix_density_CCCO):
311307
ccco_o_boxes = server._storage_backend.query(ccco_o_query)
312308
key = next(iter(ccco_o_boxes.keys()))
313309
assert len(ccco_o_boxes[key]) == 1
314-

openff/evaluator/data/test/workflows/equilibration/dhmix-density-CCCO/test-eq.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,29 @@
55

66

77
from openff.units import unit
8-
from openff.evaluator.utils.observables import ObservableType
8+
99
from openff.evaluator.backends import ComputeResources
1010
from openff.evaluator.backends.dask import DaskLocalCluster
11+
from openff.evaluator.client import EvaluatorClient, Request, RequestOptions
1112
from openff.evaluator.datasets import (
1213
MeasurementSource,
1314
PhysicalPropertyDataSet,
1415
PropertyPhase,
1516
)
16-
from openff.evaluator.client import EvaluatorClient, RequestOptions, Request
17-
from openff.evaluator.server.server import Batch, EvaluatorServer
18-
1917
from openff.evaluator.forcefield import (
2018
LigParGenForceFieldSource,
2119
SmirnoffForceFieldSource,
2220
TLeapForceFieldSource,
2321
)
24-
22+
from openff.evaluator.layers.equilibration import EquilibrationProperty
2523
from openff.evaluator.properties import Density, EnthalpyOfMixing
24+
from openff.evaluator.server.server import Batch, EvaluatorServer
2625
from openff.evaluator.substances import Substance
2726
from openff.evaluator.thermodynamics import ThermodynamicState
28-
from openff.evaluator.layers.equilibration import EquilibrationProperty
29-
27+
from openff.evaluator.utils.observables import ObservableType
3028

3129
# ## Create a toy dataset
32-
#
30+
#
3331
# Properties can be downloaded from the internet, loaded from a file, or created dynamically. Here we quickly create a small dataset.
3432

3533
# In[2]:
@@ -56,7 +54,7 @@
5654
uncertainty=1.0 * EnthalpyOfMixing.default_unit(),
5755
source=MeasurementSource(doi=" "),
5856
substance=Substance.from_components("CCCO", "O"),
59-
)
57+
),
6058
)
6159

6260
for i, prop in enumerate(dataset.properties):
@@ -78,14 +76,11 @@
7876
equilibration_options = RequestOptions()
7977
equilibration_options.calculation_layers = ["EquilibrationLayer"]
8078
density_equilibration_schema = Density.default_equilibration_schema(
81-
n_molecules=256,
82-
error_tolerances=[potential_energy, density]
79+
n_molecules=256, error_tolerances=[potential_energy, density]
8380
)
8481

8582
dhmix_equilibration_schema = EnthalpyOfMixing.default_equilibration_schema(
86-
n_molecules=256,
87-
error_tolerances=[potential_energy, density]
88-
83+
n_molecules=256, error_tolerances=[potential_energy, density]
8984
)
9085
equilibration_options.add_schema(
9186
"EquilibrationLayer",
@@ -105,9 +100,7 @@
105100

106101

107102
force_field_path = "openff-2.1.0.offxml"
108-
force_field_source = SmirnoffForceFieldSource.from_path(
109-
force_field_path
110-
)
103+
force_field_source = SmirnoffForceFieldSource.from_path(force_field_path)
111104

112105

113106
# In[ ]:
@@ -124,11 +117,11 @@
124117
server = EvaluatorServer(
125118
calculation_backend=calculation_backend,
126119
working_directory=".",
127-
delete_working_files=False
120+
delete_working_files=False,
128121
)
129122
with server:
130123
client = EvaluatorClient()
131-
124+
132125
# test equilibration
133126
request, error = client.request_estimate(
134127
dataset,
@@ -137,8 +130,3 @@
137130
)
138131

139132
results, exception = request.results(synchronous=True, polling_interval=30)
140-
141-
142-
143-
144-

0 commit comments

Comments
 (0)