Skip to content

Commit

Permalink
simulation_type default to "tidy3d" always
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflex committed Oct 31, 2024
1 parent b95a49e commit 68a6e5b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
21 changes: 15 additions & 6 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import math
import pathlib
from abc import ABC, abstractmethod
from typing import Dict, List, Set, Tuple, Union
from typing import Dict, List, Optional, Set, Tuple, Union

import autograd.numpy as np
import matplotlib as mpl
Expand Down Expand Up @@ -204,11 +204,13 @@ class AbstractYeeGridSimulation(AbstractSimulation, ABC):
", or ``False`` to apply staircasing.",
)

simulation_type: Literal["autograd_fwd", "autograd_bwd", None] = pydantic.Field(
None,
title="Simulation Type",
description="Tag used internally to distinguish types of simulations for "
"``autograd`` gradient processing.",
simulation_type: Optional[Literal["autograd_fwd", "autograd_bwd", "tidy3d", None]] = (
pydantic.Field(
"tidy3d",
title="Simulation Type",
description="Tag used internally to distinguish types of simulations for "
"``autograd`` gradient processing.",
)
)

post_norm: Union[float, FreqDataArray] = pydantic.Field(
Expand Down Expand Up @@ -262,6 +264,13 @@ class AbstractYeeGridSimulation(AbstractSimulation, ABC):
* `Dielectric constant assignment on Yee grids <https://www.flexcompute.com/fdtd101/Lecture-9-Dielectric-constant-assignment-on-Yee-grids/>`_
"""

@pydantic.validator("simulation_type", always=True)
def _validate_simulation_type_tidy3d(cls, val):
"""Enforce the simulation_type is 'tidy3d' if passed as None for bkwrds compatibility."""
if val is None:
return "tidy3d"
return val

@pydantic.validator("lumped_elements", always=True)
@skip_if_fields_missing(["structures"])
def _validate_num_lumped_elements(cls, val, values):
Expand Down
2 changes: 1 addition & 1 deletion tidy3d/plugins/adjoint/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class AdjointJob(Job):
"""Job that uploads a jax_info object and also includes new fields for adjoint tasks."""

simulation_type: AdjointSimulationType = pd.Field(
None,
"tidy3d",
title="Simulation Type",
description="Type of simulation, used internally only.",
)
Expand Down
5 changes: 5 additions & 0 deletions tidy3d/web/core/task_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ def create(
:class:`SimulationTask` object containing info about status, size,
credits of task and others.
"""

# handle backwards compatibility, "tidy3d" is the default simulation_type
if simulation_type is None:
simulation_type = "tidy3d"

folder = Folder.get(folder_name, create=True)
resp = http.post(
f"tidy3d/projects/{folder.folder_id}/tasks",
Expand Down

0 comments on commit 68a6e5b

Please sign in to comment.