|
| 1 | +"""Interface to run several jobs in batch using simplified syntax.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Literal, Optional, Union |
| 6 | + |
| 7 | +from tidy3d.log import log |
| 8 | +from tidy3d.web.core.types import PayType |
| 9 | + |
| 10 | +from .container import DEFAULT_DATA_DIR, Batch, BatchData |
| 11 | +from .tidy3d_stub import SimulationType |
| 12 | + |
| 13 | + |
| 14 | +def run_async( |
| 15 | + simulations: dict[str, SimulationType], |
| 16 | + folder_name: str = "default", |
| 17 | + path_dir: str = DEFAULT_DATA_DIR, |
| 18 | + callback_url: Optional[str] = None, |
| 19 | + num_workers: Optional[int] = None, |
| 20 | + verbose: bool = True, |
| 21 | + simulation_type: str = "tidy3d", |
| 22 | + parent_tasks: Optional[dict[str, list[str]]] = None, |
| 23 | + reduce_simulation: Literal["auto", True, False] = "auto", |
| 24 | + pay_type: Union[PayType, str] = PayType.AUTO, |
| 25 | +) -> BatchData: |
| 26 | + """Submits a set of Union[:class:`.Simulation`, :class:`.HeatSimulation`, :class:`.EMESimulation`] objects to server, |
| 27 | + starts running, monitors progress, downloads, and loads results as a :class:`.BatchData` object. |
| 28 | +
|
| 29 | + .. TODO add example and see also reference. |
| 30 | +
|
| 31 | + Parameters |
| 32 | + ---------- |
| 33 | + simulations : Dict[str, Union[:class:`.Simulation`, :class:`.HeatSimulation`, :class:`.EMESimulation`]] |
| 34 | + Mapping of task name to simulation. |
| 35 | + folder_name : str = "default" |
| 36 | + Name of folder to store each task on web UI. |
| 37 | + path_dir : str |
| 38 | + Base directory where data will be downloaded, by default current working directory. |
| 39 | + callback_url : str = None |
| 40 | + Http PUT url to receive simulation finish event. The body content is a json file with |
| 41 | + fields ``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``. |
| 42 | + num_workers: int = None |
| 43 | + Number of tasks to submit at once in a batch, if None, will run all at the same time. |
| 44 | + verbose : bool = True |
| 45 | + If ``True``, will print progressbars and status, otherwise, will run silently. |
| 46 | + reduce_simulation: Literal["auto", True, False] = "auto" |
| 47 | + Whether to reduce structures in the simulation to the simulation domain only. Note: currently only implemented for the mode solver. |
| 48 | + pay_type: Union[PayType, str] = PayType.AUTO |
| 49 | + Specify the payment method. |
| 50 | +
|
| 51 | + Returns |
| 52 | + ------ |
| 53 | + :class:`BatchData` |
| 54 | + Contains the Union[:class:`.SimulationData`, :class:`.HeatSimulationData`, :class:`.EMESimulationData`] for each |
| 55 | + Union[:class:`.Simulation`, :class:`.HeatSimulation`, :class:`.EMESimulation`] in :class:`Batch`. |
| 56 | +
|
| 57 | + See Also |
| 58 | + -------- |
| 59 | +
|
| 60 | + :class:`Job`: |
| 61 | + Interface for managing the running of a Simulation on server. |
| 62 | +
|
| 63 | + :class:`Batch` |
| 64 | + Interface for submitting several :class:`Simulation` objects to sever. |
| 65 | + """ |
| 66 | + if simulation_type is None: |
| 67 | + simulation_type = "tidy3d" |
| 68 | + |
| 69 | + # if number of workers not specified, just use the number of simulations |
| 70 | + if num_workers is not None: |
| 71 | + log.warning( |
| 72 | + "The 'num_workers' kwarg does not have an effect anymore as all " |
| 73 | + "simulations will now be uploaded in a single batch." |
| 74 | + ) |
| 75 | + |
| 76 | + batch = Batch( |
| 77 | + simulations=simulations, |
| 78 | + folder_name=folder_name, |
| 79 | + callback_url=callback_url, |
| 80 | + verbose=verbose, |
| 81 | + simulation_type=simulation_type, |
| 82 | + parent_tasks=parent_tasks, |
| 83 | + reduce_simulation=reduce_simulation, |
| 84 | + pay_type=pay_type, |
| 85 | + ) |
| 86 | + |
| 87 | + batch_data = batch.run(path_dir=path_dir) |
| 88 | + return batch_data |
0 commit comments