Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow complex materials and rely on tidy3d hash function #261

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions gplugins/tidy3d/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
plot_slice: Plots a cross section of the component at a specified position.
"""

import hashlib
import io
import pathlib
import time
from collections.abc import Awaitable
Expand Down Expand Up @@ -52,12 +50,6 @@
dirpath_default = home / ".gdsfactory" / "sparameters"


def hash_simulation(simulation) -> str:
bf = io.BytesIO()
simulation.to_hdf5(bf)
return hashlib.sha256(bf.getvalue()).hexdigest()


class Tidy3DComponent(LayeredComponentBase):
"""
Represents a 3D component in the Tidy3D simulation environment.
Expand Down Expand Up @@ -500,7 +492,6 @@ def write_sparameters(
pad_z_outer=pad_z_outer,
dilation=dilation,
)
path_dir = str(pathlib.Path(dirpath) / str(hash(c)))

modeler = c.get_component_modeler(
wavelength=wavelength,
Expand All @@ -518,9 +509,12 @@ def write_sparameters(
run_time=run_time,
shutoff=shutoff,
folder_name=folder_name,
path_dir=path_dir,
verbose=verbose,
)

path_dir = pathlib.Path(dirpath) / modeler._hash_self()
modeler = modeler.updated_copy(path_dir=str(path_dir))

sp = {}

if plot_simulation_layer_name or plot_simulation_z or plot_simulation_x:
Expand Down Expand Up @@ -571,7 +565,7 @@ def write_sparameters(

dirpath = pathlib.Path(dirpath)
dirpath.mkdir(parents=True, exist_ok=True)
filepath = filepath or dirpath / f"{hash_simulation(modeler)}.npz"
filepath = filepath or dirpath / f"{modeler._hash_self()}.npz"
filepath = pathlib.Path(filepath)

if filepath.exists() and not overwrite:
Expand Down