11import os
22import pathlib
3- import pytest
43
4+ import pytest
55from openff .units import unit
66from 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
815from 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
1622from openff .evaluator .properties import Density , EnthalpyOfMixing
1723from openff .evaluator .server .server import Batch , EvaluatorServer
24+ from openff .evaluator .storage .query import EquilibrationDataQuery
1825from openff .evaluator .substances import Substance
1926from 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
2728from openff .evaluator .workflow import Workflow
28-
29+ from openff . evaluator . workflow . attributes import ConditionAggregationBehavior
2930
3031
3132def _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
8079class 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-
0 commit comments