Skip to content

Commit 23364ac

Browse files
committed
feat: updating webapi for new modeler worfklow
1 parent 2ce5542 commit 23364ac

File tree

17 files changed

+229
-793
lines changed

17 files changed

+229
-793
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ jobs:
262262
BRANCH_NAME="${STEPS_EXTRACT_BRANCH_NAME_OUTPUTS_BRANCH_NAME}"
263263
echo $BRANCH_NAME
264264
# Allow only Jira keys from known projects, even if the branch has an author prefix
265-
ALLOWED_JIRA_PROJECTS=("FXC" "SCEM")
265+
ALLOWED_JIRA_PROJECTS=("FXC" "SCEM" "SCRF")
266266
JIRA_PROJECT_PATTERN=$(IFS='|'; echo "${ALLOWED_JIRA_PROJECTS[*]}")
267267
JIRA_PATTERN="(${JIRA_PROJECT_PATTERN})-[0-9]+"
268268

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/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]

tidy3d/components/mode/mode_solver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2655,7 +2655,7 @@ def _validate_modes_size(self) -> None:
26552655
"frequencies or modes."
26562656
)
26572657

2658-
def validate_pre_upload(self, source_required: bool = True) -> None:
2658+
def validate_pre_upload(self) -> None:
26592659
"""Validate the fully initialized mode solver is ok for upload to our servers."""
26602660
self._validate_modes_size()
26612661

tidy3d/components/mode/simulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,8 @@ def plot_pml_mode_plane(
612612
"""
613613
return self._mode_solver.plot_pml(ax=ax)
614614

615-
def validate_pre_upload(self, source_required: bool = False) -> None:
615+
def validate_pre_upload(self) -> None:
616616
super().validate_pre_upload()
617-
self._mode_solver.validate_pre_upload(source_required=source_required)
617+
self._mode_solver.validate_pre_upload()
618618

619619
_boundaries_for_zero_dims = validate_boundaries_for_zero_dims(warn_on_change=False)

tidy3d/components/tcad/mesher.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ class VolumeMesher(Tidy3dBaseModel):
2424

2525
def _get_simulation_types(self) -> list[TCADAnalysisTypes]:
2626
return [TCADAnalysisTypes.MESH]
27+
28+
def validate_pre_upload(self):
29+
return

tidy3d/plugins/smatrix/component_modelers/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,5 +343,9 @@ def run(
343343
)
344344
return data.smatrix()
345345

346+
def validate_pre_upload(self):
347+
"""Validate the modeler before upload."""
348+
self.base_sim.validate_pre_upload(source_required=False)
349+
346350

347351
AbstractComponentModeler.update_forward_refs()

tidy3d/plugins/smatrix/component_modelers/modal.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class ModalComponentModeler(AbstractComponentModeler):
5959
"by ``element_mappings``, the simulation corresponding to this column is skipped automatically.",
6060
)
6161

62+
@property
63+
def base_sim(self):
64+
"""The base simulation."""
65+
return self.simulation
66+
6267
@cached_property
6368
def sim_dict(self) -> SimulationMap:
6469
"""Generates all :class:`.Simulation` objects for the S-matrix calculation.

tidy3d/plugins/smatrix/component_modelers/terminal.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,17 @@ def _warn_refactor_2_10(cls, values):
223223

224224
@property
225225
def _sim_with_sources(self) -> Simulation:
226-
"""Instance of :class:`.Simulation` with all sources and absorbers added for each port, for troubleshooting."""
226+
"""Instance of :class:`.Simulation` with all sources and absorbers added for each port, for plotting."""
227227

228228
sources = [port.to_source(self._source_time) for port in self.ports]
229229
absorbers = [
230230
port.to_absorber()
231231
for port in self.ports
232232
if isinstance(port, WavePort) and port.absorber
233233
]
234-
return self.simulation.updated_copy(sources=sources, internal_absorbers=absorbers)
234+
return self.simulation.updated_copy(
235+
sources=sources, internal_absorbers=absorbers, validate=False
236+
)
235237

236238
@equal_aspect
237239
@add_ax_if_none
@@ -382,18 +384,17 @@ def matrix_indices_run_sim(self) -> tuple[NetworkIndex, ...]:
382384
def sim_dict(self) -> SimulationMap:
383385
"""Generate all the :class:`.Simulation` objects for the port parameter calculation."""
384386

387+
# Check base simulation for grid size at ports
388+
TerminalComponentModeler._check_grid_size_at_ports(self.base_sim, self._lumped_ports)
389+
TerminalComponentModeler._check_grid_size_at_wave_ports(self.base_sim, self._wave_ports)
390+
385391
sim_dict = {}
386392
# Now, create simulations with wave port sources and mode solver monitors for computing port modes
387393
for network_index in self.matrix_indices_run_sim:
388394
task_name, sim_with_src = self._add_source_to_sim(network_index)
389395
# update simulation
390396
sim_dict[task_name] = sim_with_src
391397

392-
# Check final simulations for grid size at ports
393-
for _, sim in sim_dict.items():
394-
TerminalComponentModeler._check_grid_size_at_ports(sim, self._lumped_ports)
395-
TerminalComponentModeler._check_grid_size_at_wave_ports(sim, self._wave_ports)
396-
397398
return SimulationMap(keys=tuple(sim_dict.keys()), values=tuple(sim_dict.values()))
398399

399400
@cached_property
@@ -414,7 +415,10 @@ def _base_sim_no_radiation_monitors(self) -> Simulation:
414415

415416
# Make an initial simulation with new grid_spec to determine where LumpedPorts are snapped
416417
sim_wo_source = self.simulation.updated_copy(
417-
grid_spec=grid_spec, lumped_elements=lumped_resistors
418+
grid_spec=grid_spec,
419+
lumped_elements=lumped_resistors,
420+
validate=False,
421+
deep=False,
418422
)
419423
snap_centers = {}
420424
for port in self._lumped_ports:
@@ -480,7 +484,11 @@ def _base_sim_no_radiation_monitors(self) -> Simulation:
480484
)
481485

482486
# update base simulation with updated set of shared components
483-
sim_wo_source = sim_wo_source.copy(update=update_dict)
487+
sim_wo_source = sim_wo_source.updated_copy(
488+
**update_dict,
489+
validate=False,
490+
deep=False,
491+
)
484492

485493
# extrude port structures
486494
sim_wo_source = self._extrude_port_structures(sim=sim_wo_source)
@@ -527,7 +535,10 @@ def base_sim(self) -> Simulation:
527535
"""The base simulation with all components added, including radiation monitors."""
528536
base_sim_tmp = self._base_sim_no_radiation_monitors
529537
mnts_with_radiation = list(base_sim_tmp.monitors) + list(self._finalized_radiation_monitors)
530-
return base_sim_tmp.updated_copy(monitors=mnts_with_radiation)
538+
grid_spec = GridSpec.from_grid(base_sim_tmp.grid)
539+
grid_spec.attrs["from_grid_spec"] = base_sim_tmp.grid_spec
540+
# We skipped validations up to now, here we finally validate the base sim
541+
return base_sim_tmp.updated_copy(monitors=mnts_with_radiation, grid_spec=grid_spec)
531542

532543
def _generate_radiation_monitor(
533544
self, simulation: Simulation, auto_spec: DirectivityMonitorSpec
@@ -712,7 +723,10 @@ def _add_source_to_sim(self, source_index: NetworkIndex) -> tuple[str, Simulatio
712723
)
713724
task_name = self.get_task_name(port=port, mode_index=mode_index)
714725

715-
return (task_name, self.base_sim.updated_copy(sources=[port_source]))
726+
return (
727+
task_name,
728+
self.base_sim.updated_copy(sources=[port_source], validate=False, deep=False),
729+
)
716730

717731
@cached_property
718732
def _source_time(self):
@@ -958,6 +972,8 @@ def _extrude_port_structures(self, sim: Simulation) -> Simulation:
958972
sim = sim.updated_copy(
959973
grid_spec=GridSpec.from_grid(sim.grid),
960974
structures=[*sim.structures, *all_new_structures],
975+
validate=False,
976+
deep=False,
961977
)
962978

963979
return sim

tidy3d/web/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
load,
3131
load_simulation,
3232
monitor,
33-
postprocess_start,
3433
real_cost,
3534
start,
3635
test,
@@ -58,7 +57,6 @@
5857
"load",
5958
"load_simulation",
6059
"monitor",
61-
"postprocess_start",
6260
"real_cost",
6361
"run",
6462
"run_async",

0 commit comments

Comments
 (0)