|
| 1 | +--- |
| 2 | +title: Web.batch? |
| 3 | +date: 2025-09-16 13:50:36 |
| 4 | +enabled: true |
| 5 | +category: "Web API" |
| 6 | +--- |
| 7 | +[`Batch`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.container.Batch.html){: .color-primary-hover} is a container for submitting, running, monitoring, and downloading **multiple simulations** on the Tidy3D cloud in one go. It’s similar to a [`web.Job`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.container.Job.html){: .color-primary-hover}, but for a whole set of simulations (FDTD, Heat/Charge, EME, Mode solver, etc.) that run in parallel. |
| 8 | + |
| 9 | +## Estimating cost |
| 10 | + |
| 11 | +It is possible to estimate the maximum cost of the whole batch with the `Batch.estimate_cost` method. For more information on simulation cost, check [this](https://docs.flexcompute.com/projects/tidy3d/en/v2.7.6/faq/docs/faq/how-do-i-see-the-cost-of-my-simulation.html){: .color-primary-hover} article. |
| 12 | + |
| 13 | +## Running a batch |
| 14 | + |
| 15 | +The batch is run with the `Batch.run(path_dir="path_dir")` method, which saves a batch file that can be loaded later and returns a [BatchData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.container.BatchData.html){: .color-primary-hover} object. |
| 16 | + |
| 17 | +## Loading a batch |
| 18 | + |
| 19 | +A batch can be loaded using the `Batch.from_file` method. If the `Batch.run` method was previously used, the `Batch` object will contain information about all executed tasks, and the [BatchData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.container.BatchData.html){: .color-primary-hover} object can be returned with the `Batch.load` method. For more information, refer to [this](https://docs.flexcompute.com/projects/tidy3d/en/stable/faq/docs/faq/how-do-i-save-or-load-a-tidy3d-web-batch-so-i-can-work-with-it-later.html){: .color-primary-hover} article. |
| 20 | + |
| 21 | +## When should I use it? |
| 22 | + |
| 23 | +- Parameter sweeps, design-of-experiments, or any workflow with many related runs in parallel. |
| 24 | + |
| 25 | +## Minimal example |
| 26 | + |
| 27 | +<div markdown class="code-snippet"> |
| 28 | +{% highlight python %} |
| 29 | +python |
| 30 | +import tidy3d as td |
| 31 | +from tidy3d.web.api.container import Batch |
| 32 | + |
| 33 | +# 1) Build your simulations (FDTD shown as example) |
| 34 | +sim_a = td.Simulation(...) # define as usual |
| 35 | +sim_b = td.Simulation(...) |
| 36 | +sims = {"run_a": sim_a, "run_b": sim_b} |
| 37 | + |
| 38 | +# 2) Create a Batch |
| 39 | +batch = Batch( |
| 40 | + simulations=sims, |
| 41 | + folder_name="my_sweep", |
| 42 | +) |
| 43 | + |
| 44 | +# (Optional) Quick cost estimate (max, assuming full run_time) |
| 45 | +est_fc = batch.estimate_cost(verbose=True) |
| 46 | + |
| 47 | +# 3) Run (upload+start+monitor+download as needed) |
| 48 | +data = batch.run(path_dir="results") |
| 49 | + |
| 50 | +# 4) Iterate over results (lazy-loaded from disk, downloads on demand) |
| 51 | +for name, sim_data in data.items(): |
| 52 | + print(name, sim_data) |
| 53 | + # ... analyze sim_data ... |
| 54 | + |
| 55 | +# 5) Access final billed cost later (after runs finish) |
| 56 | +billed_fc = batch.real_cost(verbose=True) |
| 57 | +print("Billed FlexCredits:", billed_fc) |
| 58 | +{% endhighlight %} |
| 59 | +{% include copy-button.html %}</div> |
0 commit comments