Skip to content

Commit

Permalink
fix: make sure coordinates retain correct ordering after autograd interp
Browse files Browse the repository at this point in the history
  • Loading branch information
yaugenst-flex committed Aug 13, 2024
1 parent 61d1c53 commit eaf9bc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added value_and_grad function to the autograd plugin, importable via `from tidy3d.plugins.autograd import value_and_grad`. Supports differentiating functions with auxiliary data (`value_and_grad(f, has_aux=True)`).

### Fixed
- `DataArray` interpolation failure due to incorrect ordering of coordinates when interpolating with autograd tracers.

## [2.7.2] - 2024-08-07

### Added
Expand Down
6 changes: 4 additions & 2 deletions tidy3d/components/data/data_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ def interp(

obj = self if assume_sorted else self.sortby(list(coords.keys()))

out_coords = {k: coords.get(k, obj.coords[k]) for k in obj.dims}
points = tuple(obj.coords[k] for k in obj.dims)
xi = tuple(coords.get(k, obj.coords[k]) for k in obj.dims)
xi = tuple(out_coords.values())

vals = interpn(points, obj.tracers, xi, method=method)

da = DataArray(vals, dict(obj.coords) | coords) # tracers go into .attrs
da = DataArray(vals, out_coords) # tracers go into .attrs
if isbox(self.values.flat[0]): # if tracing .values instead of .attrs
da = da.copy(deep=False, data=vals) # copy over tracers

Expand Down

0 comments on commit eaf9bc6

Please sign in to comment.