Skip to content

Commit b95ec9c

Browse files
authored
Validating that simulation md5 stored in mesher task matches solver task (#2611)
1 parent 93966eb commit b95ec9c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

tidy3d/web/api/webapi.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ def upload(
295295
)
296296
estimate_cost(task_id=task.task_id, solver_version=solver_version, verbose=verbose)
297297

298+
task.validate_post_upload(parent_tasks=parent_tasks)
299+
298300
# log the url for the task in the web UI
299301
log.debug(f"{Env.current.website_endpoint}/folders/{task.folder_id}/tasks/{task.task_id}")
300302
return task.task_id

tidy3d/web/core/task_core.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pydantic.v1 import Extra, Field, parse_obj_as
1414

1515
import tidy3d as td
16+
from tidy3d.exceptions import ValidationError
1617

1718
from . import http_util
1819
from .cache import FOLDER_CACHE
@@ -675,3 +676,33 @@ def abort(self):
675676
return http.put(
676677
"tidy3d/tasks/abort", json={"taskType": self.task_type, "taskId": self.task_id}
677678
)
679+
680+
def validate_post_upload(self, parent_tasks: Optional[list[str]] = None):
681+
"""Perform checks after task is uploaded and metadata is processed."""
682+
if self.task_type == "HEAT_CHARGE" and parent_tasks:
683+
try:
684+
if len(parent_tasks) > 1:
685+
raise ValueError(
686+
"A single parent 'task_id' corresponding to the task in which the meshing "
687+
"was run must be provided."
688+
)
689+
try:
690+
# get mesh task info
691+
mesh_task = SimulationTask.get(parent_tasks[0], verbose=False)
692+
assert mesh_task.task_type == "VOLUME_MESH"
693+
assert mesh_task.status == "success"
694+
# get up-to-date task info
695+
task = SimulationTask.get(self.task_id, verbose=False)
696+
if task.fileMd5 != mesh_task.childFileMd5:
697+
raise ValidationError(
698+
"Simulation stored in parent task 'VolumeMesher' does not match the "
699+
"current simulation."
700+
)
701+
except Exception as e:
702+
raise ValidationError(
703+
"The parent task must be a 'VolumeMesher' task which has been successfully "
704+
"run and is associated to the same 'HeatChargeSimulation' as provided here."
705+
) from e
706+
707+
except Exception as e:
708+
raise WebError(f"Provided 'parent_tasks' failed validation: {e!s}") from e

0 commit comments

Comments
 (0)