tidy3d.web.api.container.Batch#
- class Batch[source]#
Bases:
WebContainer
Interface for submitting several
Simulation
objects 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,
attrs
are mutable. For example, the following is allowed for setting anattr
obj.attrs['foo'] = bar
. Also note that Tidy3D` will raise aTypeError
ifattrs
contain objects that can not be serialized. One can check ifattrs
are serializable by callingobj.json()
.simulations (Mapping[str, Annotated[Union[tidy3d.components.simulation.Simulation, tidy3d.components.heat.simulation.HeatSimulation, tidy3d.components.eme.simulation.EMESimulation], 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) β 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 (str = 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_workers
argument passed toconcurrent.futures.ThreadPoolExecutor
. When leftNone
, will pass the maximum number of threads available on the system.jobs_cached (Optional[Mapping[str, Job]] = None) β Optional field to specify
jobs
. Only used as a workaround internally so thatjobs
is 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.
Notes
Commonly one needs to submit a batch of
Simulation
. The built-inBatch
object 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
Simulation
objects to server, starts running, monitors progress, downloads, and loads results as aBatchData
object.Job
:Interface for managing the running of a Simulation on server.
- Notebooks
Attributes
Create a series of tasks in the
Batch
and 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])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
.json
(**kwargs)Save
Batch
to dictionary.load
([path_dir])Download results and load them into
BatchData
object.monitor
()Monitor progress of each of the running tasks.
real_cost
([verbose])Get the sum of billed costs for each task associated with this batch.
run
([path_dir])Upload and run each simulation in
Batch
.start
()Start running all tasks in the
Batch
.upload
()Upload a series of tasks associated with this
Batch
using multi-threading.Inherited Common Usage
- simulations#
- folder_name#
- verbose#
- solver_version#
- callback_url#
- simulation_type#
- parent_tasks#
- num_workers#
- jobs_cached#
- run(path_dir='.')[source]#
Upload and run each simulation in
Batch
.- Parameters:
path_dir (str) β Base directory where data will be downloaded, by default current working directory.
- 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.
bach_data
does 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
Batch
and upload them to server.Note
To start the simulations running, must call
Batch.start()
after uploaded.
- 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()[source]#
Start running all tasks in the
Batch
.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
]
- monitor()[source]#
Monitor progress of each of the running tasks.
Note
To loop through the data of completed simulations, can call
Batch.items()
.
- download(path_dir='.')[source]#
Download results of each task.
- Parameters:
path_dir (str = './') β Base directory where data will be downloaded, by default the current working directory.
- load(path_dir='.')[source]#
Download results and load them into
BatchData
object.- Parameters:
path_dir (str = './') β Base directory where data will be downloaded, by default current working directory.
- Returns:
BatchData
β Contains Union[SimulationData
,HeatSimulationData
,EMESimulationData
] for each Union[Simulation
,HeatSimulation
,EMESimulation
] inBatch
.The
Batch
hdf5 file will be automatically saved as{path_dir}/batch.hdf5
,allowing one to load this
Batch
later 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.