Skip to content

Commit a56394c

Browse files
twhughestylerflex
authored andcommitted
webapi passes tests with containers, need to refine, document, add conversions
1 parent 4b82eae commit a56394c

File tree

7 files changed

+270
-99
lines changed

7 files changed

+270
-99
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ https://www.atlassian.com/git/tutorials/merging-vs-rebasing
154154
- [x] hook webapi to conversion.
155155
- [x] Test with simple run.
156156
- [x] Fix issue with converting to complex.
157-
- [ ] **Refactor some webapi internals.**
157+
- [x] **Refactor some webapi internals.**
158158
- [ ] **Add conversions for rest of objects.**
159-
- [ ] **Containers (job batch).**
160-
- [ ] Rich progressbars.
159+
- [x] **Containers (job batch).**
160+
- [ ] **Better handling for runtime status using rich.**
161161
- [ ] **Add example notebooks and make consistent.**
162162
- [ ] **Comments / documentations**
163163
- [ ] Get webAPI working without conversion.
@@ -295,7 +295,9 @@ https://github.com/crusaderky/python_project_template
295295
---
296296

297297
### Extensions
298-
- [ ] Store server-side log metadata inside SimulationData (credits billed etc)
298+
- [ ] Web
299+
- [ ] Nail down propper status messages.
300+
- [ ] Store server-side log metadata inside SimulationData (credits billed etc)
299301
- [ ] Geometry
300302
- [ ] Erosion / Dilation of polyslabs
301303
- [ ] Vectorize / automatic `inside` based on `intersections`

notebooks/StartHere.ipynb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

simulation_data.hdf5

66.3 KB
Binary file not shown.

tests/test_new_webapi.py

Lines changed: 159 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,210 @@
33

44
import tidy3d as td
55
import tidy3d.web as web
6+
67
from .utils import SIM_CONVERT as sim_original
78
from .utils import clear_tmp
89

910
PATH_JSON = "tests/tmp/simulation.json"
1011
PATH_SIM_DATA = "tests/tmp/sim_data.hdf5"
11-
# each tests works on same 'task'
12-
# store the task id in this list so it can be modified by tests
12+
PATH_DIR_SIM_DATA = "tests/tmp/"
13+
14+
15+
""" core webapi """
16+
1317
task_id_global = []
1418

1519

1620
def _get_gloabl_task_id():
1721
"""returns the task id from the list"""
1822
return task_id_global[0]
1923

24+
@clear_tmp
25+
def test_webapi_0_run():
26+
""" test complete run"""
27+
sim_data = web.run(simulation=sim_original, task_name="test_webapi")
2028

21-
def test_1_upload():
29+
def test_webapi_1_upload():
2230
"""test that task uploads ok"""
2331
task_id = web.upload(simulation=sim_original, task_name="test_webapi")
2432
task_id_global.append(task_id)
2533

2634

27-
def test_2_get_info():
35+
def test_webapi_2_get_info():
2836
"""test that we can grab information about task"""
2937
task_id = _get_gloabl_task_id()
30-
task_info = web.get_info(task_id)
38+
_ = web.get_info(task_id)
3139

3240

33-
def test_3_run():
41+
def test_webapi_3_start():
3442
"""test that we can start running task"""
3543
task_id = _get_gloabl_task_id()
36-
web.run(task_id)
44+
web.start(task_id)
3745

3846

39-
def test_4_monitor():
47+
def test_webapi_4_monitor():
4048
"""test that we can monitor task"""
4149
task_id = _get_gloabl_task_id()
4250
web.monitor(task_id)
4351

4452

4553
@clear_tmp
46-
def test_5_download():
54+
def test_webapi_5_download():
4755
"""download the simulation data"""
4856
task_id = _get_gloabl_task_id()
4957
web.download(task_id, simulation=sim_original, path=PATH_SIM_DATA)
5058

5159

5260
@clear_tmp
53-
def test_6_load():
61+
def test_webapi_6_load():
5462
"""load the results into sim_data"""
5563
task_id = _get_gloabl_task_id()
5664
sim_data = web.load(task_id, simulation=sim_original, path=PATH_SIM_DATA)
5765
first_monitor_name = list(sim_original.monitors.keys())[0]
58-
mon_data = sim_data[first_monitor_name]
66+
_ = sim_data[first_monitor_name]
5967

6068

61-
def _test_7_delete():
69+
def _test_webapi_7_delete():
6270
"""test that we can monitor task"""
6371
task_id = _get_gloabl_task_id()
6472
web.delete(task_id)
65-
try:
66-
task_info = web.get_info(task_id)
73+
task_info = web.get_info(task_id)
74+
assert task_info.status in ("deleted", "deleting")
75+
76+
77+
""" Jobs """
78+
79+
80+
jobs_global = []
81+
82+
def _get_gloabl_job():
83+
"""returns the task id from the list"""
84+
return jobs_global[0]
85+
86+
@clear_tmp
87+
def test_job_0_run():
88+
""" test complete run"""
89+
job = web.Job(simulation=sim_original, task_name="test_job")
90+
job.run()
91+
92+
93+
def test_job_1_upload():
94+
"""test that task uploads ok"""
95+
job = web.Job(simulation=sim_original, task_name="test_job")
96+
job.upload()
97+
jobs_global.append(job)
98+
99+
100+
def test_job_2_get_info():
101+
"""test that we can grab information about task"""
102+
job = _get_gloabl_job()
103+
_ = job.get_info()
104+
105+
106+
def test_job_3_start():
107+
"""test that we can start running task"""
108+
job = _get_gloabl_job()
109+
job.start()
110+
111+
112+
def test_job_4_monitor():
113+
"""test that we can monitor task"""
114+
job = _get_gloabl_job()
115+
job.monitor()
116+
117+
118+
@clear_tmp
119+
def test_job_5_download():
120+
"""download the simulation data"""
121+
job = _get_gloabl_job()
122+
job.download(path=PATH_SIM_DATA)
123+
124+
125+
@clear_tmp
126+
def test_job_6_load():
127+
"""load the results into sim_data"""
128+
job = _get_gloabl_job()
129+
sim_data = job.load_data(path=PATH_SIM_DATA)
130+
first_monitor_name = list(sim_original.monitors.keys())[0]
131+
_ = sim_data[first_monitor_name]
132+
133+
134+
def _test_job_7_delete():
135+
"""test that we can monitor task"""
136+
job = _get_gloabl_job()
137+
job.delete()
138+
task_info = job.get_info()
139+
assert task_info.status in ("deleted", "deleting")
140+
141+
142+
""" Batches """
143+
144+
145+
batches_global = []
146+
147+
def _get_gloabl_batch():
148+
"""returns the task id from the list"""
149+
return batches_global[0]
150+
151+
@clear_tmp
152+
def test_batch_0_run():
153+
""" test complete run"""
154+
sims = 2*[sim_original]
155+
simulations = {f'task_{i}': sims[i] for i in range(len(sims))}
156+
batch = web.Batch(simulations=simulations)
157+
batch.run()
158+
159+
160+
def test_batch_1_upload():
161+
"""test that task uploads ok"""
162+
sims = 2*[sim_original]
163+
simulations = {f'task_{i}': sims[i] for i in range(len(sims))}
164+
batch = web.Batch(simulations=simulations)
165+
batch.upload()
166+
batches_global.append(batch)
167+
168+
169+
def test_batch_2_get_info():
170+
"""test that we can grab information about task"""
171+
batch = _get_gloabl_batch()
172+
_ = batch.get_info()
173+
174+
175+
def test_batch_3_start():
176+
"""test that we can start running task"""
177+
batch = _get_gloabl_batch()
178+
batch.start()
179+
180+
181+
def test_batch_4_monitor():
182+
"""test that we can monitor task"""
183+
batch = _get_gloabl_batch()
184+
batch.monitor()
185+
186+
187+
@clear_tmp
188+
def test_batch_5_download():
189+
"""download the simulation data"""
190+
batch = _get_gloabl_batch()
191+
batch.download(path_dir=PATH_DIR_SIM_DATA)
192+
193+
194+
@clear_tmp
195+
def test_batch_6_load():
196+
"""load the results into sim_data"""
197+
batch = _get_gloabl_batch()
198+
sim_data_dict = batch.load_data(path_dir=PATH_DIR_SIM_DATA)
199+
first_monitor_name = list(sim_original.monitors.keys())[0]
200+
for sim_data in sim_data_dict:
201+
_ = sim_data[first_monitor_name]
202+
203+
def _test_batch_7_delete():
204+
"""test that we can monitor task"""
205+
batch = _get_gloabl_batch()
206+
batch.delete()
207+
for job in batch:
208+
task_info = job.get_info()
67209
assert task_info.status in ("deleted", "deleting")
68-
except Exception as e:
69-
pass
210+
211+
212+

tidy3d/web/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
""" imports interfaces for interacting with server """
2-
from .webapi import upload, get_info, run, monitor, delete, download, load
2+
from .webapi import run, upload, get_info, start, monitor, delete, download, load
33

4-
# from .container import Job, Batch
4+
from .container import Job, Batch

0 commit comments

Comments
 (0)