|
13 | 13 | from pydantic.v1 import Extra, Field, parse_obj_as
|
14 | 14 |
|
15 | 15 | import tidy3d as td
|
| 16 | +from tidy3d.exceptions import ValidationError |
16 | 17 |
|
17 | 18 | from . import http_util
|
18 | 19 | from .cache import FOLDER_CACHE
|
@@ -675,3 +676,33 @@ def abort(self):
|
675 | 676 | return http.put(
|
676 | 677 | "tidy3d/tasks/abort", json={"taskType": self.task_type, "taskId": self.task_id}
|
677 | 678 | )
|
| 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