|
2 | 2 | Units tests for the openff.evaluator.server module. |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import os |
5 | 6 | import tempfile |
6 | 7 | from time import sleep |
7 | 8 |
|
| 9 | +import pytest |
8 | 10 | from openff.units import unit |
9 | 11 |
|
10 | 12 | from openff.evaluator._tests.utils import create_dummy_property |
11 | 13 | from openff.evaluator.backends.dask import DaskLocalCluster |
12 | 14 | from openff.evaluator.client import EvaluatorClient, RequestOptions |
13 | 15 | from openff.evaluator.datasets import PhysicalPropertyDataSet |
| 16 | +from openff.evaluator.forcefield import SmirnoffForceFieldSource |
14 | 17 | from openff.evaluator.layers import ( |
15 | 18 | CalculationLayer, |
16 | 19 | CalculationLayerResult, |
17 | 20 | CalculationLayerSchema, |
18 | 21 | calculation_layer, |
19 | 22 | ) |
20 | 23 | from openff.evaluator.properties import Density, EnthalpyOfVaporization |
21 | | -from openff.evaluator.server.server import Batch, EvaluatorServer |
| 24 | +from openff.evaluator.server.server import Batch, BatchMode, EvaluatorServer |
22 | 25 | from openff.evaluator.substances import Substance |
23 | 26 | from openff.evaluator.thermodynamics import ThermodynamicState |
24 | 27 | from openff.evaluator.utils.utils import temporarily_change_directory |
@@ -106,7 +109,8 @@ def test_launch_batch(): |
106 | 109 | assert len(batch.unsuccessful_properties) == 1 |
107 | 110 |
|
108 | 111 |
|
109 | | -def test_same_component_batching(): |
| 112 | +@pytest.fixture |
| 113 | +def c_o_dataset(): |
110 | 114 | thermodynamic_state = ThermodynamicState( |
111 | 115 | temperature=1.0 * unit.kelvin, pressure=1.0 * unit.atmosphere |
112 | 116 | ) |
@@ -134,61 +138,66 @@ def test_same_component_batching(): |
134 | 138 | value=0.0 * unit.kilojoule / unit.mole, |
135 | 139 | ), |
136 | 140 | ) |
| 141 | + return data_set |
137 | 142 |
|
| 143 | + |
| 144 | +@pytest.fixture |
| 145 | +def dataset_submission(c_o_dataset): |
138 | 146 | options = RequestOptions() |
139 | 147 |
|
140 | 148 | submission = EvaluatorClient._Submission() |
141 | | - submission.dataset = data_set |
| 149 | + submission.dataset = c_o_dataset |
142 | 150 | submission.options = options |
| 151 | + submission.force_field_source = SmirnoffForceFieldSource.from_path( |
| 152 | + "openff-2.1.0.offxml" |
| 153 | + ) |
| 154 | + |
| 155 | + return submission |
143 | 156 |
|
| 157 | + |
| 158 | +def test_same_component_batching(dataset_submission, tmp_path): |
| 159 | + os.chdir(tmp_path) |
144 | 160 | with DaskLocalCluster() as calculation_backend: |
145 | 161 | server = EvaluatorServer(calculation_backend) |
146 | | - batches = server._batch_by_same_component(submission, "") |
| 162 | + batches = server._batch_by_same_component(dataset_submission, "") |
147 | 163 |
|
148 | 164 | assert len(batches) == 2 |
149 | 165 |
|
150 | 166 | assert len(batches[0].queued_properties) == 2 |
151 | 167 | assert len(batches[1].queued_properties) == 2 |
152 | 168 |
|
153 | 169 |
|
154 | | -def test_shared_component_batching(): |
155 | | - thermodynamic_state = ThermodynamicState( |
156 | | - temperature=1.0 * unit.kelvin, pressure=1.0 * unit.atmosphere |
157 | | - ) |
158 | | - |
159 | | - data_set = PhysicalPropertyDataSet() |
160 | | - data_set.add_properties( |
161 | | - Density( |
162 | | - thermodynamic_state=thermodynamic_state, |
163 | | - substance=Substance.from_components("O", "C"), |
164 | | - value=0.0 * unit.kilogram / unit.meter**3, |
165 | | - ), |
166 | | - EnthalpyOfVaporization( |
167 | | - thermodynamic_state=thermodynamic_state, |
168 | | - substance=Substance.from_components("O", "C"), |
169 | | - value=0.0 * unit.kilojoule / unit.mole, |
170 | | - ), |
171 | | - Density( |
172 | | - thermodynamic_state=thermodynamic_state, |
173 | | - substance=Substance.from_components("O", "CO"), |
174 | | - value=0.0 * unit.kilogram / unit.meter**3, |
175 | | - ), |
176 | | - EnthalpyOfVaporization( |
177 | | - thermodynamic_state=thermodynamic_state, |
178 | | - substance=Substance.from_components("O", "CO"), |
179 | | - value=0.0 * unit.kilojoule / unit.mole, |
180 | | - ), |
181 | | - ) |
| 170 | +def test_shared_component_batching(dataset_submission, tmp_path): |
| 171 | + os.chdir(tmp_path) |
| 172 | + with DaskLocalCluster() as calculation_backend: |
| 173 | + server = EvaluatorServer(calculation_backend) |
| 174 | + batches = server._batch_by_shared_component(dataset_submission, "") |
182 | 175 |
|
183 | | - options = RequestOptions() |
| 176 | + assert len(batches) == 1 |
| 177 | + assert len(batches[0].queued_properties) == 4 |
184 | 178 |
|
185 | | - submission = EvaluatorClient._Submission() |
186 | | - submission.dataset = data_set |
187 | | - submission.options = options |
188 | 179 |
|
| 180 | +def test_nobatching(dataset_submission, tmp_path): |
| 181 | + os.chdir(tmp_path) |
189 | 182 | with DaskLocalCluster() as calculation_backend: |
190 | 183 | server = EvaluatorServer(calculation_backend) |
191 | | - batches = server._batch_by_shared_component(submission, "") |
| 184 | + batches = server._no_batch(dataset_submission, "") |
192 | 185 |
|
193 | 186 | assert len(batches) == 1 |
194 | 187 | assert len(batches[0].queued_properties) == 4 |
| 188 | + assert batches[0].id == "batch_0000" |
| 189 | + |
| 190 | + |
| 191 | +def test_prepare_batches_nobatch(dataset_submission, tmp_path): |
| 192 | + os.chdir(tmp_path) |
| 193 | + dataset_submission.options.batch_mode = BatchMode.NoBatch |
| 194 | + with DaskLocalCluster() as calculation_backend: |
| 195 | + server = EvaluatorServer(calculation_backend) |
| 196 | + server._batch_ids_per_client_id["request_id"] = [] |
| 197 | + batches = server._prepare_batches(dataset_submission, "request_id") |
| 198 | + |
| 199 | + assert len(batches) == 1 |
| 200 | + assert len(batches[0].queued_properties) == 4 |
| 201 | + assert batches[0].id == "batch_0000" |
| 202 | + assert server._queued_batches["batch_0000"] is batches[0] |
| 203 | + assert server._batch_ids_per_client_id["request_id"] == ["batch_0000"] |
0 commit comments