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 importing specific field from vtk #1394

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

dbochkov-flexcompute
Copy link
Contributor

A small PR that came out of working on the charge example flexcompute/tidy3d-notebooks#25 and it does two things:

  • allows importing data fields from .vtu files with specific names if such files contain multiple fields (e.g. "Electrons", "Holes", etc)
  • removes spurious warnings when reloading simulations containing PerturbationMedium with CustomChargePerturbation/CustomHeatPerturbation

Copy link
Collaborator

@tylerflex tylerflex left a comment

Choose a reason for hiding this comment

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

Thanks @dbochkov-flexcompute just a couple minor comments.

@@ -352,6 +374,14 @@ def test_tetrahedral_dataset(tmp_path, ds_name):
assert np.all(tet_grid._vtk_offsets == np.array([0, 4, 8]))
assert tet_grid.name == ds_name

# since vtk is attempted to be imported during a dependent function call
# let's call one of those so that vtk dict is properly populated
try:
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the reason behind using a try / except here? (when would vtk not be imported in the test?) maybe it could make sense to make this a pytest.mark.parameterized() where we run the function once with vtk and once without? maybe I'm just a bit confused about what this block of code is doing here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Revised this a bit. So, currently it works the following way:

  • This test is designed to work for both when vtk is present and when it is not.
  • Which branch to check is determined by parameter no_vtk.
  • I tried using pytest.mark.parameterized() to conveniently test both cases, but I couldn't make it work. it seems to be tricky to properly unload already loaded module. So, instead I just re-run the same tests in a separate pytest call here with a monkeypatch to skip loading vtk and no_vtk=True

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, I think the new implementation is fine.

btw I ran into something similar with wanting to test adjoint with and without jax installed, here's what I came up with in the end.

https://github.com/flexcompute/tidy3d/blob/pre/2.6/tests/test_plugins/test_adjoint.py#L1711-L1741

(I guess I also didn't use parameterize, maybe for similar reasons)

tidy3d/components/data/dataset.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@dbochkov-flexcompute dbochkov-flexcompute merged commit d0a4872 into pre/2.6 Jan 24, 2024
16 checks passed
@dbochkov-flexcompute dbochkov-flexcompute deleted the daniil/flexible-vtu-import branch January 24, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants