Skip to content

Commit fc9dcf9

Browse files
Ok creating tasks
1 parent 37af42e commit fc9dcf9

File tree

6 files changed

+113
-53
lines changed

6 files changed

+113
-53
lines changed

docs/notebooks

tidy3d/plugins/smatrix/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
)
1010
from tidy3d.plugins.smatrix.component_modelers.modal import ComponentModeler
1111
from tidy3d.plugins.smatrix.component_modelers.terminal import TerminalComponentModeler
12+
from tidy3d.plugins.smatrix.component_modelers.types import ComponentModelerType
1213
from tidy3d.plugins.smatrix.data.data_array import (
1314
ModalPortDataArray,
1415
PortDataArray,
1516
TerminalPortDataArray,
1617
)
1718
from tidy3d.plugins.smatrix.data.modal import ComponentModelerData, PortSimulationData
1819
from tidy3d.plugins.smatrix.data.terminal import MicrowaveSMatrixData, TerminalComponentModelerData
20+
from tidy3d.plugins.smatrix.data.types import ComponentModelerDataType
1921
from tidy3d.plugins.smatrix.ports.coaxial_lumped import CoaxialLumpedPort
2022
from tidy3d.plugins.smatrix.ports.modal import Port
2123
from tidy3d.plugins.smatrix.ports.rectangular_lumped import LumpedPort
@@ -36,6 +38,8 @@
3638
"ComponentModeler",
3739
"ComponentModelerData",
3840
"ComponentModelerDataLumpedPort",
41+
"ComponentModelerType",
42+
"ComponentModelerDataType",
3943
"LumpedPort",
4044
"MicrowaveSMatrixData",
4145
"ModalPortDataArray",

tidy3d/plugins/smatrix/web/api/tidy3d_stub.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
ComponentModelerData,
3232
TerminalComponentModeler,
3333
TerminalComponentModelerData,
34+
ComponentModelerType,
35+
ComponentModelerDataType
3436
)
3537
from tidy3d.plugins.smatrix.web.core.file_util import (
3638
read_simulation_from_hdf5,
@@ -48,8 +50,7 @@
4850
ModeSolver,
4951
ModeSimulation,
5052
VolumeMesher,
51-
ComponentModeler,
52-
TerminalComponentModeler,
53+
ComponentModelerType
5354
]
5455
SimulationDataType = Union[
5556
SimulationData,
@@ -58,8 +59,7 @@
5859
EMESimulationData,
5960
ModeSolverData,
6061
ModeSimulationData,
61-
ComponentModelerData,
62-
TerminalComponentModelerData,
62+
ComponentModelerDataType
6363
]
6464

6565

tidy3d/plugins/smatrix/web/api/webapi.py

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from tidy3d.components.medium import AbstractCustomMedium
1515
from tidy3d.components.mode.mode_solver import ModeSolver
1616
from tidy3d.components.mode.simulation import ModeSimulation
17+
from tidy3d.plugins.smatrix import ComponentModelerType
1718
from tidy3d.exceptions import WebError
1819
from tidy3d.log import get_logging_console, log
1920
from tidy3d.plugins.smatrix.web.core.account import Account
@@ -164,32 +165,60 @@ def run(
164165
:meth:`tidy3d.plugins.smatrix.web.api.container.Batch.monitor`
165166
Monitor progress of each of the running tasks.
166167
"""
167-
task_id = upload(
168-
simulation=simulation,
169-
task_name=task_name,
170-
folder_name=folder_name,
171-
callback_url=callback_url,
172-
verbose=verbose,
173-
progress_callback=progress_callback_upload,
174-
simulation_type=simulation_type,
175-
parent_tasks=parent_tasks,
176-
solver_version=solver_version,
177-
reduce_simulation=reduce_simulation,
178-
)
179-
start(
180-
task_id,
181-
solver_version=solver_version,
182-
worker_group=worker_group,
183-
pay_type=pay_type,
184-
priority=priority,
185-
)
186-
monitor(task_id, verbose=verbose)
187-
data = load(
188-
task_id=task_id, path=path, verbose=verbose, progress_callback=progress_callback_download
189-
)
190-
if isinstance(simulation, ModeSolver):
191-
simulation._patch_data(data=data)
192-
return data
168+
if isinstance(simulation, ComponentModelerType):
169+
task_id = upload(
170+
simulation=simulation,
171+
task_name=task_name,
172+
folder_name=folder_name,
173+
callback_url=callback_url,
174+
verbose=verbose,
175+
progress_callback=progress_callback_upload,
176+
simulation_type=simulation_type,
177+
parent_tasks=parent_tasks,
178+
solver_version=solver_version,
179+
reduce_simulation=reduce_simulation,
180+
)
181+
start(
182+
task_id,
183+
solver_version=solver_version,
184+
worker_group=worker_group,
185+
pay_type=pay_type,
186+
priority=priority,
187+
)
188+
monitor(task_id, verbose=verbose)
189+
data = load(
190+
task_id=task_id, path=path, verbose=verbose, progress_callback=progress_callback_download
191+
)
192+
if isinstance(simulation, ModeSolver):
193+
simulation._patch_data(data=data)
194+
return data
195+
else:
196+
task_id = upload(
197+
simulation=simulation,
198+
task_name=task_name,
199+
folder_name=folder_name,
200+
callback_url=callback_url,
201+
verbose=verbose,
202+
progress_callback=progress_callback_upload,
203+
simulation_type=simulation_type,
204+
parent_tasks=parent_tasks,
205+
solver_version=solver_version,
206+
reduce_simulation=reduce_simulation,
207+
)
208+
start(
209+
task_id,
210+
solver_version=solver_version,
211+
worker_group=worker_group,
212+
pay_type=pay_type,
213+
priority=priority,
214+
)
215+
monitor(task_id, verbose=verbose)
216+
data = load(
217+
task_id=task_id, path=path, verbose=verbose, progress_callback=progress_callback_download
218+
)
219+
if isinstance(simulation, ModeSolver):
220+
simulation._patch_data(data=data)
221+
return data
193222

194223

195224
@wait_for_connection
@@ -257,14 +286,21 @@ def upload(
257286
if isinstance(simulation, (ModeSolver, ModeSimulation)):
258287
simulation = get_reduced_simulation(simulation, reduce_simulation)
259288

289+
if isinstance(simulation, ComponentModelerType):
290+
port_name_list = [port.name for port in simulation.ports]
291+
else:
292+
port_name_list = []
293+
260294
stub = Tidy3dStub(simulation=simulation)
261295
stub.validate_pre_upload(source_required=source_required)
262296
log.debug("Creating task.")
263297

264298
task_type = stub.get_type()
299+
if (task_type == "COMPONENT_MODELER") or (task_type == "TERMINAL_COMPONENT_MODELER"): # TODO REMOVE
300+
task_type = "RF"
265301

266302
task = SimulationTask.create(
267-
task_type, task_name, folder_name, callback_url, simulation_type, parent_tasks, "Gz"
303+
task_type, task_name, folder_name, callback_url, simulation_type, parent_tasks, file_type="Gz", port_name_list=port_name_list
268304
)
269305
if verbose:
270306
console = get_logging_console()

tidy3d/plugins/smatrix/web/core/task_core.py

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from .s3utils import download_file, download_gz_file, upload_file
2727
from .stub import TaskStub
2828
from .types import PayType, Queryable, ResourceLifecycle, Submittable, Tidy3DResource
29-
29+
from tidy3d.plugins.smatrix.web.core.types import TaskType
3030

3131
class Folder(Tidy3DResource, Queryable, extra=Extra.allow):
3232
"""Tidy3D Folder."""
@@ -216,6 +216,7 @@ def create(
216216
parent_tasks: Optional[list[str]] = None,
217217
file_type: str = "Gz",
218218
projects_endpoint: str = "tidy3d/projects",
219+
port_name_list: Optional[list[str]] = None
219220
) -> SimulationTask:
220221
"""Create a new task on the server.
221222
@@ -243,24 +244,43 @@ def create(
243244
:class:`SimulationTask` object containing info about status, size,
244245
credits of task and others.
245246
"""
246-
247-
# handle backwards compatibility, "tidy3d" is the default simulation_type
248-
if simulation_type is None:
249-
simulation_type = "tidy3d"
250-
251-
folder = Folder.get(folder_name, create=True)
252-
resp = http.post(
253-
f"{projects_endpoint}/{folder.folder_id}/tasks",
254-
{
255-
"taskName": task_name,
256-
"taskType": task_type,
257-
"callbackUrl": callback_url,
258-
"simulationType": simulation_type,
259-
"parentTasks": parent_tasks,
260-
"fileType": file_type,
261-
},
262-
)
263-
return SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
247+
# if (task_type == TaskType.COMPONENT_MODELER.name) or (task_type == TaskType.TERMINAL_COMPONENT_MODELER.name):
248+
if task_type == "RF":
249+
if simulation_type is None:
250+
simulation_type = "tidy3d"
251+
252+
folder = Folder.get(folder_name, create=True)
253+
resp = http.post(
254+
f"{projects_endpoint}/{folder.folder_id}/tasks",
255+
{
256+
"taskName": task_name,
257+
"taskType": task_type,
258+
"portNames": port_name_list,
259+
"callbackUrl": callback_url,
260+
"simulationType": simulation_type,
261+
"parentTasks": parent_tasks,
262+
"fileType": file_type,
263+
},
264+
)
265+
return SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
266+
else:
267+
# handle backwards compatibility, "tidy3d" is the default simulation_type
268+
if simulation_type is None:
269+
simulation_type = "tidy3d"
270+
271+
folder = Folder.get(folder_name, create=True)
272+
resp = http.post(
273+
f"{projects_endpoint}/{folder.folder_id}/tasks",
274+
{
275+
"taskName": task_name,
276+
"taskType": task_type,
277+
"callbackUrl": callback_url,
278+
"simulationType": simulation_type,
279+
"parentTasks": parent_tasks,
280+
"fileType": file_type,
281+
},
282+
)
283+
return SimulationTask(**resp, taskType=task_type, folder_name=folder_name)
264284

265285
@classmethod
266286
def get(cls, task_id: str, verbose: bool = True) -> SimulationTask:

tidy3d/plugins/smatrix/web/core/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ class TaskType(str, Enum):
5555
EME = "EME"
5656
MODE = "MODE"
5757
VOLUME_MESH = "VOLUME_MESH"
58-
COMPONENT_MODELER = "COMPONENT_MODELER"
59-
TERMINAL_COMPONENT_MODELER = "TERMINAL_COMPONENT_MODELER"
58+
COMPONENT_MODELER = "RF"
59+
TERMINAL_COMPONENT_MODELER = "RF"
6060

6161

6262
class PayType(str, Enum):

0 commit comments

Comments
 (0)