tidy3d.web.api.container.Batch#
- class Batch[source]#
Bases:
WebContainerInterface for submitting several
Simulationobjects to sever.- Parameters:
attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields,
attrsare mutable. For example, the following is allowed for setting anattrobj.attrs['foo'] = bar. Also note that Tidy3D will raise aTypeErrorifattrscontain objects that can not be serialized. One can check ifattrsare serializable by callingobj.json().simulations (Union[dict[str, Annotated[Union[tidy3d.components.simulation.Simulation, tidy3d.components.tcad.simulation.heat_charge.HeatChargeSimulation, tidy3d.components.tcad.simulation.heat.HeatSimulation, tidy3d.components.eme.simulation.EMESimulation, tidy3d.components.mode.mode_solver.ModeSolver, tidy3d.components.mode.simulation.ModeSimulation, tidy3d.components.tcad.mesher.VolumeMesher, tidy3d.plugins.smatrix.component_modelers.modal.ModalComponentModeler, tidy3d.plugins.smatrix.component_modelers.terminal.TerminalComponentModeler], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})]], tuple[Annotated[Union[tidy3d.components.simulation.Simulation, tidy3d.components.tcad.simulation.heat_charge.HeatChargeSimulation, tidy3d.components.tcad.simulation.heat.HeatSimulation, tidy3d.components.eme.simulation.EMESimulation, tidy3d.components.mode.mode_solver.ModeSolver, tidy3d.components.mode.simulation.ModeSimulation, tidy3d.components.tcad.mesher.VolumeMesher, tidy3d.plugins.smatrix.component_modelers.modal.ModalComponentModeler, tidy3d.plugins.smatrix.component_modelers.terminal.TerminalComponentModeler], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})], ...]]) – Mapping of task names to Simulations to run as a batch.
folder_name (str = default) – Name of folder to store member of each batch on web UI.
verbose (bool = True) – Whether to print info messages and progressbars.
solver_version (Optional[str] = None) – Custom solver version to use, otherwise uses default for the current front end version.
callback_url (Optional[str] = None) – Http PUT url to receive simulation finish event. The body content is a json file with fields
{'id', 'status', 'name', 'workUnit', 'solverVersion'}.simulation_type (Literal['tidy3d', 'microwave', 'tidy3d_design', 'tidy3d_autograd', 'tidy3d_autograd_async', 'autograd_fwd', 'autograd_bwd'] = tidy3d) – Type of each simulation in the batch, used internally only.
parent_tasks (Optional[Mapping[str, tuple[str, ...]]] = None) – Collection of parent task ids for each job in batch, used internally only.
num_workers (Optional[PositiveInt] = 10) – Number of workers for multi-threading upload and download of batch. Corresponds to
max_workersargument passed toconcurrent.futures.ThreadPoolExecutor. When leftNone, will pass the maximum number of threads available on the system.reduce_simulation (Literal['auto', True, False] = auto) – Whether to reduce structures in the simulation to the simulation domain only. Note: currently only implemented for the mode solver.
pay_type (PayType = AUTO) – Specify the payment method.
jobs_cached (Optional[Mapping[str, Job]] = None) – Optional field to specify
jobs. Only used as a workaround internally so thatjobsis written whenBatch.to_file()and then the proper task is loaded fromBatch.from_file(). We recommend leaving unset as setting this field along with fields that were not used to create the task will cause errors.lazy (bool = False) – Whether to load the actual data (lazy=False) or return a proxy that loads the data when accessed (lazy=True).
Notes
Commonly one needs to submit a batch of
Simulation. The built-inBatchobject is the best way to upload, start, monitor, and load a series of tasks. The batch object is like aJob, but stores task metadata for a series of simulations.See also
tidy3d.web.api.webapi.run_async()Submits a set of
Simulationobjects to server, starts running, monitors progress, downloads, and loads results as aBatchDataobject.Job:Interface for managing the running of a Simulation on server.
- Notebooks
Attributes
Create a series of tasks in the
Batchand upload them to server.Number of jobs in the batch.
Methods
delete()Delete server-side data associated with each task in the batch.
download([path_dir, replace_existing])Download results of each task.
estimate_cost([verbose])Compute the maximum FlexCredit charge for a given
Batch.get_info()Get information about each task in the
Batch.get information about a each of the tasks in the
Batch.load([path_dir, replace_existing, skip_download])Download results and load them into
BatchDataobject.monitor(*[, download_on_success, path_dir, ...])Monitor progress of each running task.
postprocess_start([worker_group, verbose])Start the postprocess phase for all applicable jobs in the batch.
real_cost([verbose])Get the sum of billed costs for each task associated with this batch.
run([path_dir, priority])Upload and run each simulation in
Batch.start([priority])Start running all tasks in the
Batch.to_file(fname)Exports
Tidy3dBaseModelinstance to .yaml, .json, or .hdf5 fileupload()Upload a series of tasks associated with this
Batchusing multi-threading.Inherited Common Usage
- simulations#
- folder_name#
- verbose#
- solver_version#
- callback_url#
- simulation_type#
- parent_tasks#
- num_workers#
- reduce_simulation#
- pay_type#
- jobs_cached#
- lazy#
- run(path_dir='.', priority=None)[source]#
Upload and run each simulation in
Batch.- Parameters:
path_dir (str) – Base directory where data will be downloaded, by default current working directory.
priority (int = None) – Priority of the simulation in the Virtual GPU (vGPU) queue (1 = lowest, 10 = highest). It affects only simulations from vGPU licenses and does not impact simulations using FlexCredits.
- Returns:
Contains Union[
SimulationData,HeatSimulationData,EMESimulationData] for each Union[:class:.Simulation`,HeatSimulation,EMESimulation] inBatch.- Return type:
Note
A typical usage might look like:
>>> from tidy3d.web.api.container import Batch >>> custom_batch = Batch() >>> batch_data = custom_batch.run() >>> for task_name, sim_data in batch_data.items(): ... # do something with data.
batch_datadoes not store all of the data objects in memory, rather it iterates over the task names and loads the corresponding data from file one by one. If no file exists for that task, it downloads it.
- property jobs#
Create a series of tasks in the
Batchand upload them to server.Note
To start the simulations running, must call
Batch.start()after uploaded.
- to_file(fname)[source]#
Exports
Tidy3dBaseModelinstance to .yaml, .json, or .hdf5 file- Parameters:
fname (str) – Full path to the .yaml or .json file to save the
Tidy3dBaseModelto.
Example
>>> simulation.to_file(fname='folder/sim.json')
- property num_jobs#
Number of jobs in the batch.
- get_info()[source]#
Get information about each task in the
Batch.- Returns:
Mapping of task name to data about task associated with each task.
- Return type:
Dict[str,
TaskInfo]
- start(priority=None)[source]#
Start running all tasks in the
Batch.- Parameters:
priority (int = None) – Priority of the simulation in the Virtual GPU (vGPU) queue (1 = lowest, 10 = highest). It affects only simulations from vGPU licenses and does not impact simulations using FlexCredits.
Note
To monitor the running simulations, can call
Batch.monitor().
- get_run_info()[source]#
get information about a each of the tasks in the
Batch.- Returns:
Dict[str – Maps task names to run info for each task in the
Batch.- Return type:
RunInfo]
- postprocess_start(worker_group=None, verbose=True)[source]#
Start the postprocess phase for all applicable jobs in the batch.
This simply forwards to each Job’s postprocess_start(…). The Job decides whether it’s a Component Modeler task and whether it can/should start now. This method does not wait for postprocessing to finish.
- monitor(*, download_on_success=False, path_dir='.', replace_existing=False, postprocess_worker_group=None)[source]#
Monitor progress of each running task.
For Component Modeler jobs, automatically triggers postprocessing once run finishes.
Optionally downloads results as soon as a job reaches final success.
Rich progress bars in verbose mode; quiet polling otherwise.
- Parameters:
download_on_success (bool = False) – If
True, automatically start downloading the results for a job as soon as it reachessuccess.path_dir (str = './') – Base directory where data will be downloaded, by default the current working directory. Only used when
download_on_successisTrue.replace_existing (bool = False) – Downloads the data even if path exists (overwriting the existing). Only used when
download_on_successisTrue.
- download(path_dir='.', replace_existing=False)[source]#
Download results of each task.
- Parameters:
path_dir (str = './') – Base directory where data will be downloaded, by default the current working directory.
replace_existing (bool = False) – Downloads the data even if path exists (overwriting the existing).
- load(path_dir='.', replace_existing=False, skip_download=False)[source]#
Download results and load them into
BatchDataobject.- Parameters:
path_dir (str = './') – Base directory where data will be downloaded, by default current working directory.
replace_existing (bool = False) – Downloads the data even if path exists (overwriting the existing).
skip_download (bool = False) – Does not trigger download. Should be True if already downloaded.
- Returns:
BatchData– Contains Union[SimulationData,HeatSimulationData,EMESimulationData] for each Union[Simulation,HeatSimulation,EMESimulation] inBatch.The
Batchhdf5 file will be automatically saved as{path_dir}/batch.hdf5,allowing one to load this
Batchlater usingbatch = Batch.from_file().
- real_cost(verbose=True)[source]#
Get the sum of billed costs for each task associated with this batch.
- Parameters:
verbose (bool = True) – Whether to log the cost and helpful messages.
- Returns:
Billed cost for the entire
Batch.- Return type:
float
- estimate_cost(verbose=True)[source]#
Compute the maximum FlexCredit charge for a given
Batch.- Parameters:
verbose (bool = True) – Whether to log the cost and helpful messages.
Note
Cost is calculated assuming the simulation runs for the full
run_time. If early shut-off is triggered, the cost is adjusted proportionately.- Returns:
Estimated total cost of the tasks in FlexCredits.
- Return type:
float
- __hash__()#
Hash method.