Skip to content

Commit 1379f16

Browse files
committed
feat: updating webapi for new modeler worfklow
unifying add not implemented errors introduce WebTask from which SimulationTask and BatchTask subclass fix to taskType Test fixes and fixture to clear TaskFactory registry Remove compose_modeler in favor of Tidy3dBaseModel.from_file Unifying detail and delete methods Passing taskType, cleanup and using MODAL_CM and TERMINAL_CM cleanup
1 parent 5882680 commit 1379f16

29 files changed

+664
-1244
lines changed

.github/workflows/tidy3d-python-client-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ jobs:
347347
BRANCH_NAME="${STEPS_EXTRACT_BRANCH_NAME_OUTPUTS_BRANCH_NAME}"
348348
echo $BRANCH_NAME
349349
# Allow only Jira keys from known projects, even if the branch has an author prefix
350-
ALLOWED_JIRA_PROJECTS=("FXC" "SCEM")
350+
ALLOWED_JIRA_PROJECTS=("FXC" "SCEM" "SCRF")
351351
JIRA_PROJECT_PATTERN=$(IFS='|'; echo "${ALLOWED_JIRA_PROJECTS[*]}")
352352
JIRA_PATTERN="(${JIRA_PROJECT_PATTERN})-[0-9]+"
353353

docs/api/submit_simulations.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ Information Containers
9494
:template: module.rst
9595

9696
tidy3d.web.core.task_info.TaskInfo
97-
tidy3d.web.core.task_info.TaskStatus
9897

9998

10099
Mode Solver Web API

tests/test_plugins/smatrix/test_run_functions.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json
43
from unittest.mock import MagicMock
54

65
import pydantic.v1 as pd
@@ -14,38 +13,15 @@
1413
make_component_modeler as make_modal_component_modeler,
1514
)
1615
from tidy3d import SimulationDataMap
17-
from tidy3d.components.base import Tidy3dBaseModel
1816
from tidy3d.components.data.sim_data import SimulationData
1917
from tidy3d.plugins.smatrix.data.terminal import TerminalComponentModelerData
2018
from tidy3d.plugins.smatrix.run import (
2119
_run_local,
22-
compose_modeler,
2320
compose_modeler_data,
2421
create_batch,
2522
)
2623

2724

28-
def test_compose_modeler_unsupported_type(tmp_path, monkeypatch):
29-
# Create a dummy HDF5 file path
30-
modeler_file = tmp_path / "dummy_modeler.hdf5"
31-
32-
# Prepare a dummy JSON string with an unsupported type
33-
dummy_json = {"type": "UnsupportedComponentModeler", "some_key": "some_value"}
34-
dummy_json_str = json.dumps(dummy_json)
35-
36-
# Mock Tidy3dBaseModel._json_string_from_hdf5 to return our dummy JSON string
37-
def mock_json_string_from_hdf5(filepath):
38-
if filepath == str(modeler_file):
39-
return dummy_json_str
40-
return ""
41-
42-
monkeypatch.setattr(Tidy3dBaseModel, "_json_string_from_hdf5", mock_json_string_from_hdf5)
43-
44-
# Expect a TypeError when calling compose_modeler with the unsupported type
45-
with pytest.raises(TypeError, match="Unsupported modeler type: str"):
46-
compose_modeler(modeler_file=str(modeler_file))
47-
48-
4925
def test_create_batch(monkeypatch, tmp_path):
5026
# Mock Batch and Batch.to_file
5127
mock_batch_instance = MagicMock()

tests/test_plugins/test_array_factor.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,15 @@ def make_antenna_sim():
363363
remove_dc_component=False, # Include DC component for more accuracy at low frequencies
364364
)
365365

366-
sim_unit = list(modeler.sim_dict.values())[0]
367-
368-
return sim_unit
366+
return modeler
369367

370368

371369
def test_rectangular_array_calculator_array_make_antenna_array():
372370
"""Test automatic antenna array creation."""
373371
freq0 = 10e9
374372
wavelength0 = td.C_0 / 10e9
375-
sim_unit = make_antenna_sim()
373+
modeler = make_antenna_sim()
374+
sim_unit = list(modeler.sim_dict.values())[0]
376375
array_calculator = mw.RectangularAntennaArrayCalculator(
377376
array_size=(1, 2, 3),
378377
spacings=(0.5 * wavelength0, 0.6 * wavelength0, 0.4 * wavelength0),
@@ -437,8 +436,9 @@ def test_rectangular_array_calculator_array_make_antenna_array():
437436
assert len(sim_array.sources) == 6
438437

439438
# check that override_structures are duplicated
440-
assert len(sim_unit.grid_spec.override_structures) == 2
441-
assert len(sim_array.grid_spec.override_structures) == 7
439+
# assert len(sim_unit.grid_spec.override_structures) == 2
440+
# assert len(sim_array.grid_spec.override_structures) == 7
441+
assert sim_unit.grid.boundaries == modeler.base_sim.grid.boundaries
442442

443443
# check that phase shifts are applied correctly
444444
phases_expected = array_calculator._antenna_phases
@@ -674,7 +674,8 @@ def test_rectangular_array_calculator_simulation_data_from_array_factor():
674674
phase_shifts=(np.pi / 3, np.pi / 4, np.pi / 5),
675675
)
676676

677-
sim_unit = make_antenna_sim()
677+
modeler = make_antenna_sim()
678+
sim_unit = list(modeler.sim_dict.values())[0]
678679

679680
monitor = sim_unit.monitors[0]
680681
monitor_directivity = sim_unit.monitors[2]

tests/test_web/test_local_cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
resolve_local_cache,
4444
)
4545
from tidy3d.web.cli.app import tidy3d_cli
46-
from tidy3d.web.core.task_core import BatchTask
46+
from tidy3d.web.core.task_core import BatchTask, SimulationTask
4747

4848
common.CONNECTION_RETRY_TIME = 0.1
4949

@@ -245,7 +245,9 @@ def _fake_field_map_from_file(*args, **kwargs):
245245
monkeypatch.setattr(
246246
io_utils, "load_simulation", lambda task_id, *args, **kwargs: TASK_TO_SIM[task_id]
247247
)
248-
monkeypatch.setattr(BatchTask, "is_batch", lambda *args, **kwargs: "success")
248+
monkeypatch.setattr(
249+
SimulationTask, "get", lambda *args, **kwargs: SimpleNamespace(taskType="FDTD")
250+
)
249251
monkeypatch.setattr(
250252
BatchTask, "detail", lambda *args, **kwargs: SimpleNamespace(status="success")
251253
)

tests/test_web/test_webapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def test_run_with_invalid_priority(mock_webapi, priority):
415415

416416

417417
@responses.activate
418-
def test_get_run_info(mock_get_run_info):
418+
def test_get_run_info(mock_get_run_info, mock_get_info):
419419
assert get_run_info(TASK_ID) == (100, 0)
420420

421421

tests/test_web/test_webapi_eme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_get_info(mock_get_info):
260260

261261

262262
@responses.activate
263-
def test_get_run_info(mock_get_run_info):
263+
def test_get_run_info(mock_get_run_info, mock_get_info):
264264
assert get_run_info(TASK_ID) == (100, 0)
265265

266266

tests/test_web/test_webapi_heat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def test_get_info(mock_get_info):
250250

251251

252252
@responses.activate
253-
def test_get_run_info(mock_get_run_info):
253+
def test_get_run_info(mock_get_run_info, mock_get_info):
254254
assert get_run_info(TASK_ID) == (100, 0)
255255

256256

tests/test_web/test_webapi_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def test_get_info(mock_get_info):
307307

308308

309309
@responses.activate
310-
def test_get_run_info(mock_get_run_info):
310+
def test_get_run_info(mock_get_run_info, mock_get_info):
311311
assert get_run_info(TASK_ID) == (100, 0)
312312

313313

tests/test_web/test_webapi_mode_sim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ def test_get_info(mock_get_info):
303303

304304

305305
@responses.activate
306-
def test_get_run_info(mock_get_run_info):
306+
def test_get_run_info(mock_get_run_info, mock_get_info):
307307
assert get_run_info(TASK_ID) == (100, 0)
308308

309309

0 commit comments

Comments
 (0)