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

Fix updater for hdf5 files with custom data, and add hdf5 files to automatic updater testing #1200

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Properly handle `.freqs` in `output_monitors` of adjoint plugin.
- Simulation updater for `.hdf5` files with custom data.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom source more specifically? I thought the existing one seemed to work with custom medium?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only tried custom source and custom medium and yeah for some reason custom medium seemed fine. However I haven't tried other custom data, so not sure. Also not sure if there's a way to create the custom medium in which it will error (e.g. passing an xarray object as opposed to one of our inherited ones?) So maybe safer to leave as is?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure sounds good


## [2.4.2] - 2023-9-28

Expand Down
Binary file added tests/sims/simulation_2_4_2.h5
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test_components/test_IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ def set_datasets_to_none(sim):
def test_simulation_load_export():
major, minor, patch = __version__.split(".")
path = os.path.join(SIM_DIR, f"simulation_{major}_{minor}_{patch}.json")
# saving as .h5 since *.hdf5 is git ignored
path_hdf5 = os.path.join(SIM_DIR, f"simulation_{major}_{minor}_{patch}.h5")
SIM.to_file(path)
SIM.to_hdf5(path_hdf5)
SIM2 = td.Simulation.from_file(path)
SIM_HDF5 = td.Simulation.from_hdf5(path_hdf5)
assert set_datasets_to_none(SIM) == SIM2, "original and loaded simulations are not the same"
assert SIM == SIM_HDF5, "original and loaded from hdf5 simulations are not the same"


def test_simulation_load_export_yaml(tmp_path):
Expand Down
6 changes: 4 additions & 2 deletions tidy3d/components/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def ndarray_encoder(val):
def _get_valid_extension(fname: str) -> str:
"""Return the file extension from fname, validated to accepted ones."""
extension = "".join(pathlib.Path(fname).suffixes).lower()
if extension not in {".json", ".yaml", ".hdf5", ".hdf5.gz"}:
valid_extensions = [".json", ".yaml", ".hdf5", ".hdf5.gz", ".h5"]
if extension not in valid_extensions:
raise FileError(
f"{fname}::File extension must be .json, .yaml, .hdf5, or .hdf5.gz, but '{extension}' given"
f"{fname}::File extension must be in {valid_extensions}, but '{extension}' given"
)
return extension

Expand Down Expand Up @@ -225,6 +226,7 @@ def dict_from_file(cls, fname: str, group_path: str = None) -> dict:
".yaml": cls.dict_from_yaml,
".hdf5": cls.dict_from_hdf5,
".hdf5.gz": cls.dict_from_hdf5_gz,
".h5": cls.dict_from_hdf5,
}[extension]
return converter(**kwargs)

Expand Down
2 changes: 1 addition & 1 deletion tidy3d/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def update_1_8(sim_dict: dict) -> dict:

def fix_missing_scalar_field(mnt_dict: dict) -> dict:
for key, val in mnt_dict["field_dataset"].items():
if val == "XR.DATAARRAY":
if isinstance(val, str) and val == "XR.DATAARRAY":
mnt_dict["field_dataset"][key] = "ScalarFieldDataArray"
return mnt_dict

Expand Down
Loading