Skip to content

Commit 208589c

Browse files
authored
add Web API FAQ (#48)
add Web API FAQ
1 parent e4f7f89 commit 208589c

21 files changed

+682
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Td.simulationdata.from_file?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
The `SimulationData.from_file` method allows you to load a [SimulationData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.components.data.sim_data.SimulationData.html){: .color-primary-hover} object directly from a locally saved file. It is a good alternative to the [`web.load`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.load.html){: .color-primary-hover} to avoid the time of downloading the simulation from the cloud.
8+
9+
The file can be saved with the `SimulationData.to_file` method. For more details, check [this](https://docs.flexcompute.com/projects/tidy3d/en/latest/faq/docs/faq/how-do-i-save-and-load-the-simulationdata-object.html){: .color-primary-hover} tutorial.
10+
11+
## Example
12+
<div markdown class="code-snippet">
13+
{% highlight python %}
14+
python
15+
# Load a Simulation from an HDF5 file
16+
sim_data = SimulationData.from_file(fname="folder/sim.hdf5")
17+
{% endhighlight %}
18+
{% include copy-button.html %}</div>
19+

_faqs/web.Batch.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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>

_faqs/web.Job.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Web.job?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
[`web.Job`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.container.Job.html){: .color-primary-hover} is a lightweight container that represents a single simulation task on the Tidy3D cloud. It keeps track of the task ID, manages upload/start/monitor/download, and lets you save/load the job metadata without manually handling the original Simulation or task ID.
8+
9+
Use Job when working with one simulation and you want to track the task ID, conveniently manage simulations (upload/start/monitor/download), and have the ability to save/restore your job state cleanly across sessions.
10+
11+
Minimal Example
12+
13+
<div markdown class="code-snippet">
14+
{% highlight python %}
15+
from tidy3d.web.api.container import Job
16+
from tidy3d import web
17+
18+
# Create a Job from an existing simulation
19+
job = Job(simulation=simulation, task_name="my_task", folder_name="default")
20+
21+
# (Optional) Estimate cost before running
22+
est = job.estimate_cost()
23+
print(f"Estimated max cost (FC): {est:.2f}")
24+
25+
# Upload and start
26+
job.upload()
27+
job.start()
28+
job.monitor() # blocks until done
29+
30+
# Download and load results
31+
sim_data = job.load(path="out/simulation.hdf5")
32+
33+
# Persist the job metadata for later reuse
34+
job.to_file("data/job.json")
35+
36+
# Later (even in a new session), restore and load results:
37+
job2 = Job.from_file("data/job.json")
38+
sim_data2 = job2.load(path="data/simulation.hdf5")
39+
{% endhighlight %}
40+
{% include copy-button.html %}</div>
41+
42+
## Convenient methods
43+
44+
upload() – Upload the job (no run yet).
45+
46+
start() – Start running the job.
47+
48+
monitor() – Show progress until completion.
49+
50+
download(path) – Download results (.hdf5).
51+
52+
load(path) – Download and load as SimulationData.
53+
54+
estimate_cost(verbose=True) – Maximum FlexCredit estimate (assumes full run time).
55+
56+
real_cost(verbose=True) – Final billed cost.

_faqs/web.abort.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Web.abort?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
The [`web.abort`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.abort.html){: .color-primary-hover} function allows you to stop a running simulation on the server and abort any associated data processing. Note that simply stopping the Python script or killing the kernel **won’t** stop the simulation in the cloud.
8+
9+
When you call `abort`, the server cancels the specified simulation and returns a `TaskInfo` object. This object contains details about the aborted simulation, including its status, size, and credit usage. The input parameter for [`web.abort`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.abort.html){: .color-primary-hover} is the **task_id**, not the [`Simulation`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.Simulation.html){: .color-primary-hover} object. This ID is returned by the [`web.upload`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.upload.html){: .color-primary-hover} method when a simulation is created.
10+
11+
## Example
12+
<div markdown class="code-snippet">
13+
{% highlight python %}
14+
import tidy3d.web as web
15+
16+
# Abort the simulation
17+
task_info = web.abort(task_id)
18+
19+
print("Simulation status:", task_info.status)
20+
{% endhighlight %}
21+
{% include copy-button.html %}</div>

_faqs/web.account.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Web.account?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
8+
[`web.account`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.account.html){: .color-primary-hover} is a helper function that retrieves **account details** for the currently authenticated user. It shows your FlexCredit balance, expiration dates, and limits on daily free simulations.
9+
10+
## Example
11+
<div markdown class="code-snippet">
12+
{% highlight python %}
13+
from tidy3d import web
14+
15+
# Get account information
16+
account_info = web.account()
17+
{% endhighlight %}
18+
{% include copy-button.html %}</div>
19+
20+
Example output:
21+
22+
<div markdown class="code-snippet">
23+
{% highlight python %}
24+
Current FlexCredit balance: 10.00 and expiration date: 2024-12-31 23:59:59. Remaining daily free simulations: 3.
25+
26+
# available FlexCredit balance:
27+
available_flexcredits = account_info.credit
28+
29+
# expiration date
30+
expiration = account_info.credit_expiration
31+
{% endhighlight %}
32+
{% include copy-button.html %}</div>

_faqs/web.estimate_cost.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
title: Web.estimate_cost?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
[`web.estimate_cost`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.estimate_cost.html){: .color-primary-hover} returns the **maximum** possible FlexCredit cost of running a simulation before it starts. This helps prevent accidentally launching overly expensive simulations.
8+
9+
The real cost after running the simulation can be checked with the [`web.real_cost`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.real_cost.html){: .color-primary-hover} method.
10+
11+
Note that the input parameter for `web.estimate_cost` and `web.real_cost` is the **task_id**, not the `Simulation` object. This ID is returned by the [`web.upload`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.upload.html){: .color-primary-hover} method when a simulation is created.
12+
13+
## Example
14+
<div markdown class="code-snippet">
15+
{% highlight python %}
16+
from tidy3d import web
17+
18+
# Create a job and upload it
19+
job = web.Job(simulation=sim, task_name="job_example", verbose=True)
20+
21+
# Estimate its maximum cost before running
22+
estimated_cost = web.estimate_cost(job.task_id)
23+
print(f"Estimated maximum cost: {estimated_cost:.3f} FlexCredits")
24+
{% endhighlight %}
25+
{% include copy-button.html %}</div>
26+
27+
A minimum simulation cost may apply, depending on simulation details.
28+
29+
The estimate is conservative: it assumes the simulation runs its full allocated time. For more information on the real cost and how to correctly estimate the simulation time, refer to [this](https://www.flexcompute.com/tidy3d/learning-center/tidy3d-gui/Lecture-8-Run-Time-and-Shutoff/){: .color-primary-hover} tutorial.
30+

_faqs/web.get_tasks.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Web.get_tasks?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
[`web.get_tasks`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.get_tasks.html){: .color-primary-hover} is a function in `tidy3d.web.api.webapi` that **retrieves metadata about past simulation tasks** from your account. It’s useful for reviewing recent runs, checking their IDs, and organizing workflows.
8+
9+
## What does it do?
10+
- Returns a list of dictionaries with task metadata (e.g., ID, status, name).
11+
- Lets you specify how many tasks to fetch and in what order.
12+
- Can filter tasks by folder name.
13+
14+
## Example
15+
<div markdown class="code-snippet">
16+
{% highlight python %}
17+
python
18+
from tidy3d import web
19+
20+
# Get the 5 most recent tasks from the default folder
21+
tasks = web.get_tasks(num_tasks=5, order="new", folder="default")
22+
23+
for t in tasks:
24+
print(f"Task {t['name']} (ID: {t['id']}) - Status: {t['status']}")
25+
{% endhighlight %}
26+
{% include copy-button.html %}</div>

_faqs/web.load.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Web.load?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
The [`web.load`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.load.html){: .color-primary-hover} function is a convenient utility in Tidy3D that allows you to **download and load simulation results** directly into a [SimulationData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.components.data.sim_data.SimulationData.html){: .color-primary-hover}, [HeatChargeSimulationData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.HeatChargeSimulationData.html){: .color-primary-hover}, or [ModeSolverData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.plugins.mode.ModeSolverData.html){: .color-primary-hover}, depending on the simulation.
8+
9+
It is particularly useful for retrieving results from simulations created and run through the Tidy3D GUI or API.
10+
11+
12+
## Parameters
13+
- **task_id (str)**: Unique identifier for the simulation task (returned when uploading).
14+
- **path (str)**: Local path where the results file (`.hdf5`) will be saved. Default: `"simulation_data.hdf5"`.
15+
- **replace_existing (bool)**: If `True`, overwrites existing files at the same path.
16+
17+
## Notes
18+
19+
The *task_id* can be obtained in the GUI under the **Simulation Assets** tab, or from the **Action** menu on the [folder](https://tidy3d.simulation.cloud/home){: .color-primary-hover} page.
20+
21+
For more information and templates on loading and visualizing data using `web.load`, see [this example](None){: .color-primary-hover}.
22+
23+
---
24+
25+
## Example
26+
<div markdown class="code-snippet">
27+
{% highlight python %}
28+
from tidy3d import web
29+
30+
sim_data = web.load(task_id, path="out/sim.hdf5", verbose=True)
31+
32+
# Now you can postprocess or visualize your simulation data
33+
{% endhighlight %}
34+
{% include copy-button.html %}</div>

_faqs/web.run.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Web.run?
3+
date: 2025-09-16 13:50:36
4+
enabled: true
5+
category: "Web API"
6+
---
7+
The [`web.run`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.run.html){: .color-primary-hover} function is a high-level API method for submitting a simulation to Flexcompute’s cloud server. It automatically uploads the simulation, runs it remotely, monitors progress, downloads the results, and loads them as a data object.
8+
9+
It is the general method to submit a simulation to the cloud, and it works with the [Simulation](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.Simulation.html){: .color-primary-hover}, [HeatChargeSimulation](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.HeatChargeSimulation.html){: .color-primary-hover}, [web.Batch](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.container.Batch.html){: .color-primary-hover}, and [ModeSolver](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.plugins.mode.ModeSolver.html){: .color-primary-hover} objects.
10+
11+
12+
## Example
13+
<div markdown class="code-snippet">
14+
{% highlight python %}
15+
from tidy3d import web
16+
17+
# Submit and run the simulation
18+
sim_data = web.run(
19+
simulation,
20+
task_name="my_task",
21+
path="out/sim.hdf5"
22+
)
23+
{% endhighlight %}
24+
{% include copy-button.html %}</div>
25+
26+
The `web.run` function requires the `task_name` string.
27+
28+
Optional arguments:
29+
30+
`folder_name`: Where to store the simulation in the web UI (default: "default").
31+
32+
`path`: Local file path to save results (.hdf5).
33+
34+
`verbose`: If True, shows progress (default).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Td.simulationdata.from_file?
2+
3+
| Date | Category |
4+
|------------|-------------|
5+
| 2025-09-16 13:50:36 | Web API |
6+
7+
8+
The `SimulationData.from_file` method allows you to load a [SimulationData](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.components.data.sim_data.SimulationData.html) object directly from a locally saved file. It is a good alternative to the [`web.load`](https://docs.flexcompute.com/projects/tidy3d/en/latest/api/_autosummary/tidy3d.web.api.webapi.load.html) to avoid the time of downloading the simulation from the cloud.
9+
10+
The file can be saved with the `SimulationData.to_file` method. For more details, check [this](https://docs.flexcompute.com/projects/tidy3d/en/latest/faq/docs/faq/how-do-i-save-and-load-the-simulationdata-object.html) tutorial.
11+
12+
## Example
13+
14+
15+
```python
16+
python
17+
# Load a Simulation from an HDF5 file
18+
sim_data = SimulationData.from_file(fname="folder/sim.hdf5")
19+
```
20+
21+
22+

0 commit comments

Comments
 (0)