Skip to content

Commit 3353070

Browse files
twhughestylerflex
authored andcommitted
webapi refined, need to finish conversion
1 parent a56394c commit 3353070

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3868
-35095
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ max-line-length=100
1010

1111
[pre-commit-hook]
1212
command=custom_pylint
13-
disable=pointless-string-statement, too-many-ancestors, too-few-public-methods, fixme, logging-not-lazy
13+
disable=pointless-string-statement, too-many-ancestors, too-few-public-methods, fixme, logging-not-lazy, logging-fstring-interpolation

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ https://www.atlassian.com/git/tutorials/merging-vs-rebasing
157157
- [x] **Refactor some webapi internals.**
158158
- [ ] **Add conversions for rest of objects.**
159159
- [x] **Containers (job batch).**
160-
- [ ] **Better handling for runtime status using rich.**
160+
- [x] **Better handling for runtime status using rich.**
161161
- [ ] **Add example notebooks and make consistent.**
162-
- [ ] **Comments / documentations**
162+
- [x] **Comments / documentations**
163163
- [ ] Get webAPI working without conversion.
164164
- [ ] Use native `Simulation.export()` or `Simulation.json()` for `upload()`.
165165
- [ ] Put the tidy3d log inside SimulationData on postprocess.

docs/StartHere.py

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,74 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4+
get_ipython().run_line_magic("load_ext", "autoreload")
5+
get_ipython().run_line_magic("autoreload", "2")
6+
7+
import matplotlib.pylab as plt
8+
49
import sys
510

611
sys.path.append("..")
712

813
import tidy3d as td
14+
import tidy3d.web as web
15+
916

1017
# set up parameters of simulation
11-
dl = 0.1
18+
dl = 0.01
1219
pml = td.PMLLayer(profile="standard", num_layers=10)
1320
sim_size = [4, 4, 4]
1421
freq0 = 3e14
1522
fwidth = 1e13
16-
run_time = 2 / fwidth
23+
run_time = 10 / fwidth
1724

1825
# create structure
1926
dielectric = td.nk_to_medium(n=2, k=0, freq=freq0)
2027
square = td.Structure(geometry=td.Box(center=[0, 0, 0], size=[1.5, 1.5, 1.5]), medium=dielectric)
2128

2229
# create source
23-
source = td.PlaneWave(
24-
center=(0, -1.5, 0),
25-
size=(td.inf, 0, td.inf),
30+
source = td.VolumeSource(
31+
center=(-1.5, 0, 0),
32+
size=(0, 0.4, 0.4),
2633
source_time=td.GaussianPulse(freq0=freq0, fwidth=fwidth),
2734
polarization="Jx",
28-
direction="+",
2935
)
3036

3137
# create monitor
32-
monitor = td.FieldMonitor(
33-
fields=["Ex", "Hy"], center=(0, 0, 0), size=(td.inf, 0, td.inf), freqs=[freq0]
34-
)
38+
monitor = td.FieldMonitor(fields=["Ex", "Hy"], center=(0, 0, 0), size=(4, 4, 0), freqs=[freq0])
3539

3640
# Initialize simulation
3741
sim = td.Simulation(
3842
size=sim_size,
3943
grid_size=(dl, dl, dl),
4044
structures=[square],
41-
sources={"plane_wave": source},
42-
monitors={"field_monitor": monitor},
45+
sources={"source": source},
46+
monitors={"monitor": monitor},
4347
run_time=run_time,
4448
pml_layers=(pml, pml, pml),
4549
)
4650

51+
task_id = web.upload(sim, task_name="quickstart")
52+
web.start(task_id)
53+
web.monitor(task_id)
4754

48-
# # run simulation
49-
# project = web.new_project(sim.export(), task_name='quickstart')
50-
# web.monitor_project(project['taskId'])
5155

52-
# # download results
53-
# web.download_results(project['taskId'], target_folder='out/')
54-
# sim.load_results('out/monitor_data.hdf5')
56+
web.download(task_id, simulation=sim, path="data/sim_data.hdf5")
57+
58+
59+
sim_data = web.load(task_id, simulation=sim, path="data/sim_data.hdf5")
60+
ax = (
61+
sim_data["monitor"]
62+
.Ex.isel(f=0, z=0)
63+
.imag.plot.pcolormesh(x="x", y="y", vmin=-5e-13, vmax=5e-13, cmap="RdBu")
64+
)
65+
66+
plt.show()
5567

56-
# # get field data as a numpy array
57-
# E = sim.data(freq_mnt)["E"]
5868

59-
# # plot results
60-
# clim = (1, 3)
61-
# fig, (ax_top, ax_bot) = plt.subplots(2, 2, figsize=(9, 7), tight_layout=True)
69+
from pprint import pprint as print
6270

63-
# sim.viz_eps_2D(normal='y', ax=ax_top[0], cbar=True, clim=clim, monitor_alpha=0)
64-
# im_re = sim.viz_field_2D(freq_mnt, ax=ax_top[1], cbar=True, comp='y', val='re')
71+
print(sim_data.task_info)
6572

66-
# im_ab = sim.viz_field_2D(freq_mnt, ax=ax_bot[0], cbar=True, comp='y', val='abs')
67-
# im_int = sim.viz_field_2D(freq_mnt, ax=ax_bot[1], cbar=True, comp='y', val='int')
6873

69-
# plt.show()
74+
sim_data.log

docs/api.rst

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ Simulation Output Data
8181
Submitting Simulations
8282
======================
8383

84+
.. currentmodule:: tidy3d
85+
8486
Web API
8587
-------
8688

@@ -93,7 +95,7 @@ Web API
9395
web.run
9496
web.monitor
9597
web.download
96-
web.load_results
98+
web.load_data
9799
web.delete
98100

99101
Job Interface
@@ -103,14 +105,6 @@ Job Interface
103105
:toctree: _autosummary/
104106

105107
web.Job
106-
web.Job.upload
107-
web.Job.get_info
108-
web.Job.get_run_info
109-
web.Job.run
110-
web.Job.monitor
111-
web.Job.download
112-
web.Job.load_results
113-
web.Job.delete
114108

115109
Batch Processing
116110
----------------
@@ -119,14 +113,6 @@ Batch Processing
119113
:toctree: _autosummary/
120114

121115
web.Batch
122-
web.Batch.upload
123-
web.Batch.get_info
124-
web.Batch.get_run_info
125-
web.Batch.run
126-
web.Batch.monitor
127-
web.Batch.download
128-
web.Batch.load_results
129-
web.Batch.delete
130116

131117
Info Containers
132118
---------------

docs/howdoi.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,29 @@ Plot Data
9797
- ``mon_data.plot()`` if data is 2D, otherwise one can use ``mon_data.plot.pcolormesh(x='x', y='y')`` to specify the ``x`` and ``y`` coordinates explicitly.
9898
* - Plot the simulation structure on top of my field plot?
9999
- ``sim_data.simulation.plot_structures_eps(z=0.0, ax=ax, alpha=.5, cbar=False, lw=0)`` will plot the ``z=0`` cross-section, where ``ax`` is the axis where your fields are plotted on.
100+
101+
Submit Jobs to Server
102+
---------------------
103+
104+
.. list-table::
105+
:header-rows: 1
106+
:widths: 40 60
107+
108+
* - How do I...
109+
- Solution
110+
* - Submit my simulations to run on Flexcompute's servers?
111+
- The simplest way is to create a :class:`Job` object from your :class:`Simulation` object and call the ``.run()`` method, which does all steps. For example: ``job = Job(simulation=simulation, task_name='my_sim'); job.run()``.
112+
* - Upload a job to the web without running it so I can inspect it first?
113+
- Once you've created a :class:`Job`, you can upload it to our servers with ``job.upload()`` and it will not run until you excplicitly tell it to with ``job.start()``.
114+
* - Monitor the progress of a simulation?
115+
- ``web.monitor(task_id)``, ``Job.monitor()``, or ``Batch.monitor()`` will display the progress of your simulation(s).
116+
* - Load the results of a simulation?
117+
- ``sim_data = job.load_results(path)`` will download the results to ``path`` and load them as :class:`SimulationData` object.
118+
* - See information about my :class:`Job`, such as how many credits it will take?
119+
- After uploading your job with ``job.upload()`` you can get a host of information about it through ``task_info = job.get_info()``.
120+
* - Submit multiple simulations?
121+
- The :class:`Batch` interface was created to manage multiple :class:`Job` instances and gives a similar interface with large number of jobs in mind.
122+
* - Loop through :class:`Batch` data without loading all of the data into memory?
123+
- ``for task_name, sim_data in batch.items():`` will ``yield`` the :class:`SimulationData` for each :class:`Job` in the batch one by one, so you can perform your postprocessing in the loop body without loading each of the simulations' data into memory at once.
124+
* - Save or load a :class:`Job` or :class:`Batch` so I can work with it later?
125+
- Like most other tidy3d objects, :class:`Job` and :class:`Batch` instances have ``.export(path)`` and ``.load()`` methods that will export and load thier metadata as .json files. This is especially useful for loading batches for analysis long after they have run.

0 commit comments

Comments
 (0)