Skip to content

Commit ea6840c

Browse files
Merge branch 'dario/rf_endpoints_update' into yaugenst-flex/autograd-web-cm
2 parents 8d67a55 + c53bcaa commit ea6840c

33 files changed

+827
-489
lines changed

CHANGELOG.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Selective simulation capabilities to `TerminalComponentModeler` via `run_only` and `element_mappings` fields, allowing users to run fewer simulations and extract only needed scattering matrix elements.
1313
- Added KLayout plugin, with DRC functionality for running design rule checks in `plugins.klayout.drc`. Supports running DRC on GDS files as well as `Geometry`, `Structure`, and `Simulation` objects.
1414
- Added "mil" and "in" (inch) units to `plot_length_units`.
15-
- Objective functions that involve running `tidy3d.plugins.smatrix.ComponentModeler` can be differentiated with autograd.
15+
- Objective functions that involve running `tidy3d.plugins.smatrix.ModalComponentModeler` can be differentiated with autograd.
1616
- Access field decay values in `SimulationData` via `sim_data.field_decay` as `TimeDataArray`.
1717
- Added ability to set first-order absorbing boundary conditions on simulation domain boundaries using either `ABCBoundary` or `ModeABCBoundary` classes.
1818
- Added `frame` field to `ModeSource` (default: `None`) and `WavePort` (default: `PECFrame()`). Setting this to `PECFrame(length=...)` automatically places a thin PEC frame of specified length around the source/port. The automatically created frames can be inspected using `Simulation._finalized` property.
@@ -32,11 +32,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- Improved the robustness of batch jobs. The batch state, including all `task_ids`, is now saved to `batch.hdf5` immediately after upload. This fixes an issue where an interrupted batch (e.g., due to a kernel crash or network loss) would be unrecoverable.
3333
- Fixed warning for running symmetric adjoint simulations by port to not trigger when there is a single port.
3434
- Bug in `CoaxialLumpedPort` where source injection is off when the `normal_axis` is not `z`.
35-
- Validation of `freqs` in the `ComponentModeler` and `TerminalComponentModeler`.
35+
- Validation of `freqs` in the `ModalComponentModeler` and `TerminalComponentModeler`.
3636
- Calculation of voltage and current in the `WavePort`, when one type of path integral is supplied and the transmission line mode is lossy.
3737
- Polygon vertices cleanup in `ClipOperation.intersections_plane`.
3838
- Removed sources from `sim_inf_structure` simulation object in `postprocess_adj` to avoid source and background medium validation errors.
39-
- Revert overly restrictive validation of `freqs` in the `ComponentModeler` and `TerminalComponentModeler`.
39+
- Revert overly restrictive validation of `freqs` in the `ModalComponentModeler` and `TerminalComponentModeler`.
4040
- Fixed `ElectromagneticFieldData.to_zbf()` to support single frequency monitors and apply the correct flattening order.
4141
- Bug in `TerminalComponentModeler.get_antenna_metrics_data` when port amplitudes are set to zero.
4242
- Added missing `solver_version` keyword argument to `run_async`.
@@ -240,7 +240,7 @@ with fewer layers than recommended.
240240
- Added `WavePort` to the `TerminalComponentModeler` which is the suggested port type for exciting transmission lines.
241241
- Added plotting functionality to voltage and current path integrals in the `microwave` plugin.
242242
- Added convenience functions `from_terminal_positions` and `from_circular_path` to simplify setup of `VoltageIntegralAxisAligned` and `CustomCurrentIntegral2D`, respectively.
243-
`ComponentModeler.batch_data` convenience property to access the `BatchData` corresponding to the component modeler run.
243+
`ModalComponentModeler.batch_data` convenience property to access the `BatchData` corresponding to the component modeler run.
244244
- Added optimization methods to the Design plugin. The plugin has been expanded to include Bayesian optimization, genetic algorithms and particle swarm optimization. Explanations of these methods are available in new and updated notebooks.
245245
- Added new support functions for the Design plugin: automated batching of `Simulation` objects, and summary functions with `DesignSpace.estimate_cost` and `DesignSpace.summarize`.
246246
- Added validation and repair methods for `TriangleMesh` with inward-facing normals.
@@ -283,7 +283,7 @@ with fewer layers than recommended.
283283

284284
- Priority is given to `snapping_points` in `GridSpec` when close to structure boundaries, which reduces the chance of them being skipped.
285285
- Gradients for autograd are computed server-side by default. They can be computed locally (requiring more data download) by passing `local_gradient=True` to the `web.run()` and related functions.
286-
- Passing `path_dir` to `ComponentModeler` methods is deprecated in favor of setting `ComponentModeler.path_dir` and will result in an error if the two don't match.
286+
- Passing `path_dir` to `ModalComponentModeler` methods is deprecated in favor of setting `ModalComponentModeler.path_dir` and will result in an error if the two don't match.
287287
- `BatchData` is now a mapping and can be accessed and iterated over like a Python dictionary (`.keys()`, `.values()`, `.items()`).
288288
- `MethodRandom` and `MethodRandomCustom` have been removed from the Design plugin, and `DesignSpace.run_batch` has been superseded by `.run`.
289289
- Design plugin has been significantly reworked to improve ease of use and allow for new optimization methods.
@@ -341,7 +341,7 @@ with fewer layers than recommended.
341341
- Bug in `Batch`, where duplicate folders might be created in the Web UI if the folder did not already exist.
342342
- Make gauge selection for non-converged modes more robust.
343343
- Fixed extremely long runtime generated by `RunTimeSpec` in the presence of `LossyMetalMedium`.
344-
- Fixed `ComponentModeler.to_file` when its batch is empty.
344+
- Fixed `ModalComponentModeler.to_file` when its batch is empty.
345345
- In web api, mode solver is patched with remote data so that certain methods like `plot_field` show remote data.
346346
- Fixed common cross-referencing typo in docstrings.
347347
- Added `viz_spec` property to `AbstractStructure` to fix error when plotting structures that have no `medium`.
@@ -472,7 +472,7 @@ with fewer layers than recommended.
472472
- Improve accuracy in `Box` shifting boundary gradients.
473473
- Improve accuracy in `FieldData` operations involving H fields (like `.flux`).
474474
- Better error and warning handling in autograd pipeline.
475-
- Added the option to specify the `num_freqs` argument and `kwargs` to the `.to_source` method for both `ModeSolver` and `ComponentModeler`.
475+
- Added the option to specify the `num_freqs` argument and `kwargs` to the `.to_source` method for both `ModeSolver` and `ModalComponentModeler`.
476476
- Fixes to TFSF source in some 2D simulations, and in some cases when the injection plane is close to the simulation domain boundaries.
477477

478478
## [2.7.2] - 2024-08-07
@@ -494,7 +494,7 @@ with fewer layers than recommended.
494494
- Error if field projection monitors found in 2D simulations, except `FieldProjectionAngleMonitor` or `FieldProjectionCartesianMonitor` with `far_field_approx = True`. Support for other monitors and for exact field projection will be coming in a subsequent Tidy3D version.
495495

496496
### Fixed
497-
- Error when loading a previously run `Batch` or `ComponentModeler` containing custom data.
497+
- Error when loading a previously run `Batch` or `ModalComponentModeler` containing custom data.
498498
- Error when plotting mode plane PML and the simulation has symmetry.
499499
- Validators using `TriangleMesh.intersections_plane` will fall back on bounding box in case the method fails for a non-watertight mesh.
500500
- Bug when running the same `ModeSolver` first locally then remotely, or vice versa, in which case the cached data from the first run is always returned.
@@ -722,7 +722,7 @@ with fewer layers than recommended.
722722
- Support for an anisotropic medium containing PEC components.
723723
- `SimulationData.mnt_data_from_file()` method to load only a single monitor data object from a simulation data `.hdf5` file.
724724
- `_hash_self` to base model, uses `hashlib` to hash a Tidy3D component the same way every session.
725-
- `ComponentModeler.plot_sim_eps()` method to plot the simulation permittivity and ports.
725+
- `ModalComponentModeler.plot_sim_eps()` method to plot the simulation permittivity and ports.
726726
- Support for 2D PEC materials.
727727
- Ability to downsample recorded near fields to speed up server-side far field projections.
728728
- `FieldData.apply_phase(phase)` to multiply field data by a phase.
@@ -769,8 +769,8 @@ with fewer layers than recommended.
769769
- Improved error handling if file can not be downloaded from server.
770770
- Fix for detection of file extensions for file names with dots.
771771
- Restrict to `matplotlib` >= 3.5, avoiding bug in plotting `CustomMedium`.
772-
- Fixes `ComponentModeler` batch file being different in different sessions by use of deterministic hash function for computing batch filename.
773-
- Can pass `kwargs` to `ComponentModeler.plot_sim()` to use in `Simulation.plot()`.
772+
- Fixes `ModalComponentModeler` batch file being different in different sessions by use of deterministic hash function for computing batch filename.
773+
- Can pass `kwargs` to `ModalComponentModeler.plot_sim()` to use in `Simulation.plot()`.
774774
- Ensure that mode solver fields are returned in single precision if `ModeSolver.ModeSpec.precision == "single"`.
775775
- If there are no adjoint sources for a simulation involved in an objective function, make a mock source with zero amplitude and warn user.
776776

@@ -869,7 +869,7 @@ the difference that can be observed when slightly modifying the grid resolution.
869869
- Uses `ruff` for linting instead of `pylint`.
870870
- Added lower bound validator to `freqs` in mode solver.
871871
- Added lower bound validator to `group_index_step` in `ModeSpec`.
872-
- `ComponentModeler.freqs` now a `FreqArray`, so it can be initialized from numpy, list or tuple.
872+
- `ModalComponentModeler.freqs` now a `FreqArray`, so it can be initialized from numpy, list or tuple.
873873

874874
### Fixed
875875
- Handles `TIDY3D_ENV` properly when set to `prod`.
@@ -920,7 +920,7 @@ the difference that can be observed when slightly modifying the grid resolution.
920920
### Changed
921921
- Source validation happens before simulation upload and raises an error if no source is present.
922922
- Warning instead of error if structure out of simulation bounds.
923-
- Internal refactor of `ComponentModeler` to simplify logic.
923+
- Internal refactor of `ModalComponentModeler` to simplify logic.
924924
- (Changed effective 2.3.0) Backward-direction mode amplitudes from `ModeMonitors` have a flipped sign compared to previous versions.
925925
Previously, the amplitudes were computed directly through the dot product ``amp = (mode, field)``, while, since 2.3.0, we use ``amp = (mode, field) / (mode, mode)`` instead.
926926
The modes are already normalized to unit directed flux, such that ``(mode, mode) = 1`` for forward modes, and ``(mode, mode) = -1`` for backward modes
@@ -1441,7 +1441,7 @@ which fields are to be projected is now determined automatically based on the me
14411441
### Changed
14421442
- `Batch` objects automatically download their json file upon `download` and `load`.
14431443
- Uses `shapely` instead of `gdspy` to merge polygons from a gds cell.
1444-
- `ComponentModeler` (S matrix tool) stores the `Batch` rather than the `BatchData`.
1444+
- `ModalComponentModeler` (S matrix tool) stores the `Batch` rather than the `BatchData`.
14451445
- Custom caching of properties to speed up subsequent calculations.
14461446
- Tidy3D configuration now done through setting attributes of `tidy3d.config` object.
14471447

@@ -1578,7 +1578,7 @@ which fields are to be projected is now determined automatically based on the me
15781578

15791579
- `Simulation` symmetries now fully functional.
15801580
- Ability to perform near-to-far transformations from multiple surface monitors oriented along the x, y or z directions using `tidy3d.plugins.Near2Far`.
1581-
- `tidy3d.plugins.ComponentModeler` tool for scattering matrix calculations.
1581+
- `tidy3d.plugins.ModalComponentModeler` tool for scattering matrix calculations.
15821582

15831583
### Changed
15841584

docs/api/plugins/smatrix.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Scattering Matrix Calculator
77
:toctree: ../_autosummary/
88
:template: module.rst
99

10-
tidy3d.plugins.smatrix.ComponentModeler
10+
tidy3d.plugins.smatrix.ModalComponentModeler
1111
tidy3d.plugins.smatrix.Port
1212
tidy3d.plugins.smatrix.ModalPortDataArray
1313

tests/test_components/test_index.py

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/test_components/test_map.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from __future__ import annotations
2+
3+
import collections.abc
4+
5+
import pydantic.v1 as pydantic
6+
import pytest
7+
8+
from tidy3d import SimulationMap
9+
10+
from ..utils import SAMPLE_SIMULATIONS
11+
12+
# Reusable test constants
13+
SIM_MAP_DATA = {
14+
"sim_A": SAMPLE_SIMULATIONS["full_fdtd"],
15+
"sim_B": SAMPLE_SIMULATIONS["full_fdtd"].updated_copy(run_time=2e-12),
16+
}
17+
18+
19+
def make_simulation_map() -> SimulationMap:
20+
"""Factory function to create a standard SimulationMap instance."""
21+
return SimulationMap(keys=tuple(SIM_MAP_DATA.keys()), values=tuple(SIM_MAP_DATA.values()))
22+
23+
24+
def test_simulation_map_creation():
25+
"""Tests successful creation and basic properties of a SimulationMap."""
26+
s_map = make_simulation_map()
27+
assert isinstance(s_map, collections.abc.Mapping)
28+
assert len(s_map) == len(SIM_MAP_DATA)
29+
assert s_map["sim_A"] == SIM_MAP_DATA["sim_A"]
30+
assert list(s_map.keys()) == list(SIM_MAP_DATA.keys())
31+
32+
33+
def test_simulation_map_invalid_type_raises_error():
34+
"""Tests that a ValidationError is raised for incorrect value types."""
35+
invalid_data = {"sim_A": "not a simulation"}
36+
with pytest.raises(pydantic.ValidationError):
37+
SimulationMap(keys=tuple(invalid_data.keys()), values=tuple(invalid_data.values()))
38+
39+
40+
def test_simulation_map_getitem_success():
41+
"""Tests successful retrieval of a simulation by its string key."""
42+
s_map = make_simulation_map()
43+
assert s_map["sim_A"] == SIM_MAP_DATA["sim_A"]
44+
assert s_map["sim_B"] == SIM_MAP_DATA["sim_B"]
45+
46+
47+
def test_simulation_map_getitem_key_error():
48+
"""Tests that a KeyError is raised when retrieving a non-existent key."""
49+
s_map = make_simulation_map()
50+
with pytest.raises(KeyError):
51+
_ = s_map["not_a_real_key"]

tests/test_data/test_index.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)