Skip to content

Commit 257fbb1

Browse files
committed
merged develop into main for 1.0.1
2 parents 3164e6c + 8634bf5 commit 257fbb1

28 files changed

+4136
-435
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ tests/* linguist-vendored
44

55
*.ipynb linguist-detectable=false
66
*.ipynb linguist-generated=true
7+
8+
CHANGELOG.md merge=union

CHANGELOG.md

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
## [Unreleased]
77

88
### Added
9+
10+
### Changed
11+
12+
## [1.0.1] - 2021-2-16
13+
14+
### Added
15+
- `Selmeier.from_dispersion()` method to quickly make a single-pole fit for lossless weakly dispersive materials.
916
- Stable dispersive material fits via webservice.
17+
- Allow to load dispersive data directly by providing URL to txt or csv file
1018
- Validates simulation based on discretized size.
1119

1220
### Changed
13-
- Refined and updated documentation.
21+
- `Polyslab.from_gds` returns a list of `PolySlab` objects imported from all polygons in given layer and dtype, can optionally specify single dtype.
22+
- Warning about structure close to PML disabled if Absorber type.
23+
- Source dft now ignores insignificant time amplitudes for speed.
1424
- New color schemes for plots.
1525

26+
## [1.0.0] - 2021-1-31
27+
28+
### Added
29+
- Stable dispersive material fits via webservice.
30+
31+
### Changed
32+
- Refined and updated documentation.
33+
1634
## [0.2.0] - 2021-1-29
1735

1836
### Added
@@ -45,7 +63,99 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4563
### Added
4664
- Web API implemented by converting simulations to old tidy3D
4765

48-
[Unreleased]: https://github.com/flexcompute/Tidy3D-client-revamp/compare/v0.2.0...develop
66+
## Alpha Release Changes
67+
68+
### 22.1.1
69+
- Solver speed improvement (gain depending on simulation + hardware details).
70+
- Bringing the speed of the non-angled mode solver back to pre-21.4.2 levels.
71+
72+
### 21.4.4
73+
- Improvements to subpixel averaging for dispersive materials.
74+
- Enabled web login using environment variables ``TIDY3D_USER`` and ``TIDY3D_PASS``.
75+
76+
### 21.4.3
77+
- Bugfix when running simulation with zero ``run_time``.
78+
- More internal logging.
79+
- Fixed unstable ``'Li1993_293K'`` variant of ``cSi`` in the material library.
80+
81+
### 21.4.2.2
82+
- Bugfix when downloading data on Windows.
83+
- Bugfix in material fitting tool when target tolerance is not reached.
84+
85+
### 21.4.2
86+
- New Gaussian beam source and `example usage <examples/GratingCoupler.html>`__.
87+
- Modal sources and monitors in bent and in angled waveguides with `tutorial <examples/Modes_bent_angled.html>`__.
88+
- Nyquist-limit sampling in frequency-domain monitors (much faster without loss of accuracy).
89+
- Support for Drude model of material dispersion.
90+
- Small bugfixes to some of the other dispersion models.
91+
- PEC boundaries applied by default at the truncation of any boundary with PML, avoiding potential
92+
issues with using periodic boundaries under the PML instead.
93+
- Source normalization no longer adding a spurious frequency-dependent phase to the fields.
94+
- Fixed bug in unpacking monitor fields with symmetries and ``interpolate=False``.
95+
- Lots of streamlining on the backend side.
96+
97+
### 21.4.1
98+
- Fixed bug with zero-size monitor plotting.
99+
- Fixed bug with empty simulation run introduced in 21.4.0.
100+
101+
### 21.4.0
102+
- A few small fixes.
103+
104+
105+
### 21.3.1.6
106+
- Fixed nonlinear constraint in dispersive material fitting tool.
107+
- Fixed potential issue when a monitor stores neither `'E'` nor `'H'`.
108+
- Fixed some backwards compatibility issues introduced in 21.3.1.5.
109+
110+
111+
### 21.3.1.5
112+
- Frequency monitors can now optionally store the complex permittivity at the same locations where
113+
the E-fields are recorded, at the monitor frequencies.
114+
- Frequency monitors now also have an `'interpolate'` keyword, which defaults to `True` and
115+
reproduces the behavior of previous versions. If set to `False`, however, the raw fields
116+
evaluated at their corresponding Yee grid locations are returned, instead of the fields interpolated
117+
to the Yee cell centers. This also affects the returned permittivity, if requested.
118+
- Reorganized internal source time dependence handling, enabling more complicated functionality
119+
in the future, like custom source time.
120+
- Total field in the simulation now sampled at the time step of the peak of the source time dependence,
121+
for better estimation of the shutoff factor.
122+
- A number of bug fixes, especially in the new plotting introduced in 21.3.1.4.
123+
124+
### 21.3.1.4
125+
- Reorganized plotting:
126+
- Speeding up structure visualizations.
127+
- Structures now shown based on primitive definitions rather than grid discretization. This
128+
then shows the physical structures but not what the simulation "sees". Will add an option to
129+
display the grid lines in next version.
130+
- Bumped down matplotlib version requirement to 3.2 and python version requirement to 3.6.
131+
- Improved handling of PEC interfaces.- Reorganized and extended internal logging.
132+
- Added ``tidy3d.__version__``.
133+
- A number of fixes to the example notebooks and the colab integration.
134+
135+
### 21.3.1.3
136+
- Bumping back python version requirement from 3.8 to 3.7.
137+
138+
### 21.3.1.2
139+
- Hotfix to an internal bug in some simulation runs.
140+
141+
### 21.3.1.1
142+
- New dispersion fitting tool for material data and accompanying `tutorial <examples/Fitting.html>`__.
143+
- (`beta`) Non-uniform Cartesian meshing now supported. The grid coordinates are provided
144+
by hand to `Simulation`. Next step is implementing auto-meshing.
145+
- `DispersionModel` objects can now be directly used as materials.
146+
- Fixed bug to `Cylinder` subpixel averaging.
147+
- Small bugs fixes/added checks for some edge cases.
148+
149+
### 21.3.1.0
150+
- Rehash of symmetries and support for mode sources and monitors with symmetries.
151+
- Anisotropic materials (diagonal epsilon tensor).
152+
- Rehashed error handling to output more runtime errors to tidy3d.log.
153+
- Job and Batch classes for better simulation handling (eventually to fully replace webapi functions).
154+
- A large number of small improvements and bug fixes.
155+
156+
[Unreleased]: https://github.com/flexcompute/Tidy3D-client-revamp/compare/v1.0.1...develop
157+
[1.0.1]: https://github.com/flexcompute/Tidy3D-client-revamp/compare/v1.0.0...v1.0.1
158+
[1.0.0]: https://github.com/flexcompute/Tidy3D-client-revamp/compare/v0.2.0...v1.0.0
49159
[0.2.0]: https://github.com/flexcompute/Tidy3D-client-revamp/compare/0.1.1...v0.2.0
50160
[0.1.1]: https://github.com/flexcompute/Tidy3D-client-revamp/compare/0.1.0...0.1.1
51161
[0.1.0]: https://github.com/flexcompute/Tidy3D-client-revamp/releases/tag/0.1.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The easiest way to install this beta version of tidy3d is through [pip](https://
3939
pip install tidy3d-beta
4040
```
4141

42-
Note that whikle our old version is still currently pip installable as `tidy3d`, both versions are imoprted in python as `tidy3d`, eg. `import tidy3d as td`.
42+
Note that while our old version is still currently pip installable as `tidy3d`, both versions are imoprted in python as `tidy3d`, eg. `import tidy3d as td`.
4343

4444
### (Alternativelty) installing from source
4545

lint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import logging
44
from pylint.lint import Run
55

6+
# wont pass until score (out of 10.0) is greater than this
7+
DEFAULT_THRESHOLD = 10.0
8+
69

710
def main():
811
logging.getLogger().setLevel(logging.INFO)
@@ -23,7 +26,7 @@ def main():
2326
"-t",
2427
"--threshold",
2528
help="score threshold to fail pylint runner | " "Default: %(default)s | " "Type: %(type)s ",
26-
default=9.0,
29+
default=DEFAULT_THRESHOLD,
2730
type=float,
2831
)
2932

tests/_test_fit_web.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import numpy as np
2-
import sys
32

4-
sys.path.append("../tidy3d_client_revamp")
5-
from tidy3d.plugins import StableDispersionFitter
3+
from tidy3d.plugins import StableDispersionFitter, AdvancedFitterParam
64

75

86
def test_dispersion_load_list():
97
"""performs a fit on some random data"""
108
num_data = 10
119
n_data = np.random.random(num_data)
1210
wvls = np.linspace(1, 2, num_data)
13-
fitter = StableDispersionFitter(wvls, n_data)
11+
fitter = StableDispersionFitter(wvl_um=wvls, n_data=n_data)
1412

1513
num_poles = 3
1614
num_tries = 10
@@ -27,7 +25,7 @@ def test_dispersion_load_file():
2725
fitter = StableDispersionFitter.from_file("tests/data/nk_data.csv", skiprows=1, delimiter=",")
2826

2927
num_poles = 3
30-
num_tries = 30
28+
num_tries = 10
3129
tolerance_rms = 1e-3
3230
best_medium, best_rms = fitter.fit(
3331
num_tries=num_tries, num_poles=num_poles, tolerance_rms=tolerance_rms
@@ -36,5 +34,30 @@ def test_dispersion_load_file():
3634
print(best_medium.eps_model(1e12))
3735

3836

39-
if __name__ == "__main__":
40-
test_dispersion_load_file()
37+
def test_dispersion_load_url():
38+
39+
url_csv = "https://refractiveindex.info/data_csv.php?datafile=data/main/Ag/Johnson.yml"
40+
fitter = StableDispersionFitter.from_url(url_csv)
41+
42+
num_poles = 2
43+
num_tries = 10
44+
tolerance_rms = 1e-3
45+
best_medium, best_rms = fitter.fit(
46+
num_tries=num_tries,
47+
num_poles=num_poles,
48+
tolerance_rms=tolerance_rms,
49+
advanced_param=AdvancedFitterParam(constraint="hard", bound_eps_inf=10),
50+
)
51+
print(best_rms)
52+
print(best_medium.eps_inf)
53+
54+
fitter.wvl_range = [1.0, 1.3]
55+
print(len(fitter.freqs))
56+
best_medium, best_rms = fitter.fit(
57+
num_tries=num_tries,
58+
num_poles=num_poles,
59+
tolerance_rms=tolerance_rms,
60+
advanced_param=AdvancedFitterParam(constraint="hard", bound_eps_inf=10),
61+
)
62+
print(best_rms)
63+
print(best_medium.eps_inf)

tests/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# required for development
2-
black
2+
black==22.1.0
33
pylint
44
tox
5-
pytest
5+
pytest

tests/test_components.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,20 +173,37 @@ def _test_monitor_size():
173173
s.validate_contents()
174174

175175

176-
@pytest.mark.parametrize("fwidth,log_level", [(0.001, None), (3, 30)])
177-
def test_sim_frequency_range(caplog, fwidth, log_level):
178-
# small fwidth should be inside range, large one should throw warning
176+
@pytest.mark.parametrize("freq, log_level", [(1.5, 30), (2.5, None), (3.5, 30)])
177+
def test_monitor_medium_frequency_range(caplog, freq, log_level):
178+
# monitor frequency above or below a given medium's range should throw a warning
179179

180180
size = (1, 1, 1)
181181
medium = Medium(frequency_range=(2, 3))
182182
box = Structure(geometry=Box(size=(0.1, 0.1, 0.1)), medium=medium)
183+
mnt = FieldMonitor(size=(0, 0, 0), name="freq", freqs=[freq])
183184
src = VolumeSource(
184-
source_time=GaussianPulse(freq0=2.4, fwidth=fwidth),
185+
source_time=GaussianPulse(freq0=2.5, fwidth=0.5),
185186
size=(0, 0, 0),
186187
polarization="Ex",
187188
)
188-
_ = Simulation(size=(1, 1, 1), grid_size=(0.1, 0.1, 0.1), structures=[box], sources=[src])
189+
sim = Simulation(
190+
size=(1, 1, 1), grid_size=(0.1, 0.1, 0.1), structures=[box], monitors=[mnt], sources=[src]
191+
)
192+
assert_log_level(caplog, log_level)
193+
189194

195+
@pytest.mark.parametrize("fwidth, log_level", [(0.1, 30), (2, None)])
196+
def test_monitor_simulation_frequency_range(caplog, fwidth, log_level):
197+
# monitor frequency outside of the simulation's frequency range should throw a warning
198+
199+
size = (1, 1, 1)
200+
src = VolumeSource(
201+
source_time=GaussianPulse(freq0=2.0, fwidth=fwidth),
202+
size=(0, 0, 0),
203+
polarization="Ex",
204+
)
205+
mnt = FieldMonitor(size=(0, 0, 0), name="freq", freqs=[1.5])
206+
sim = Simulation(size=(1, 1, 1), grid_size=(0.1, 0.1, 0.1), monitors=[mnt], sources=[src])
190207
assert_log_level(caplog, log_level)
191208

192209

@@ -273,8 +290,13 @@ def test_sim_plane_wave_error():
273290
def test_sim_structure_extent(caplog, box_size, log_level):
274291
"""Make sure we warn if structure extends exactly to simulation edges."""
275292

293+
src = VolumeSource(
294+
source_time=GaussianPulse(freq0=3e14, fwidth=1e13),
295+
size=(0, 0, 0),
296+
polarization="Ex",
297+
)
276298
box = Structure(geometry=Box(size=box_size), medium=Medium(permittivity=2))
277-
sim = Simulation(size=(1, 1, 1), grid_size=(0.1, 0.1, 0.1), structures=[box])
299+
sim = Simulation(size=(1, 1, 1), grid_size=(0.1, 0.1, 0.1), structures=[box], sources=[src])
278300

279301
assert_log_level(caplog, log_level)
280302

@@ -449,6 +471,25 @@ def test_medium_dispersion_create():
449471
struct = Structure(geometry=Box(size=(1, 1, 1)), medium=medium)
450472

451473

474+
def test_sellmeier_from_dispersion():
475+
n = 3.5
476+
wvl = 0.5
477+
freq = C_0 / wvl
478+
dn_dwvl = -0.1
479+
with pytest.raises(ValidationError) as e:
480+
# Check that postivie dispersion raises an error
481+
medium = Sellmeier.from_dispersion(n=n, freq=freq, dn_dwvl=-dn_dwvl)
482+
483+
# Check that medium properties are as epected
484+
medium = Sellmeier.from_dispersion(n=n, freq=freq, dn_dwvl=dn_dwvl)
485+
epses = [medium.eps_model(f) for f in [0.99 * freq, freq, 1.01 * freq]]
486+
ns = np.sqrt(epses)
487+
dn_df = (ns[2] - ns[0]) / 0.02 / freq
488+
489+
assert np.allclose(ns[1], n)
490+
assert np.allclose(-dn_df * C_0 / wvl**2, dn_dwvl)
491+
492+
452493
def eps_compare(medium: Medium, expected: Dict, tol: float = 1e-5):
453494

454495
for freq, val in expected.items():
@@ -479,15 +520,15 @@ def test_epsilon_eval():
479520
eps_compare(material, expected)
480521

481522
# Constant and eps, zero sigma
482-
material = Medium(permittivity=1.5 ** 2)
523+
material = Medium(permittivity=1.5**2)
483524
expected = {
484525
2e14: 2.25,
485526
5e14: 2.25,
486527
}
487528
eps_compare(material, expected)
488529

489530
# Constant eps and sigma
490-
material = Medium(permittivity=1.5 ** 2, conductivity=0.1)
531+
material = Medium(permittivity=1.5**2, conductivity=0.1)
491532
expected = {
492533
2e14: 2.25 + 8.987552009401353j,
493534
5e14: 2.25 + 3.5950208037605416j,

tests/test_plugins.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import tidy3d as td
66

77
from tidy3d.plugins import DispersionFitter
8-
from tidy3d.plugins.dispersion.fit import _poles_to_coeffs, _coeffs_to_poles
9-
from tidy3d.plugins.dispersion.fit import _pack_coeffs, _unpack_coeffs
108

119
from tidy3d.plugins import ModeSolver
1210
from tidy3d.plugins import Near2Far
@@ -84,11 +82,14 @@ def test_dispersion():
8482
num_data = 10
8583
n_data = np.random.random(num_data)
8684
wvls = np.linspace(1, 2, num_data)
87-
fitter = DispersionFitter(wvls, n_data)
88-
medium, rms = fitter.fit_single()
85+
fitter = DispersionFitter(wvl_um=wvls, n_data=n_data)
86+
medium, rms = fitter._fit_single()
8987
medium, rms = fitter.fit(num_tries=2)
9088
medium.to_file("tests/tmp/medium_fit.json")
9189

90+
k_data = np.random.random(num_data)
91+
fitter = DispersionFitter(wvl_um=wvls, n_data=n_data, k_data=k_data)
92+
9293

9394
def test_dispersion_load():
9495
"""loads dispersion model from nk data file"""
@@ -101,3 +102,17 @@ def test_dispersion_plot():
101102
fitter = DispersionFitter.from_file("tests/data/nk_data.csv", skiprows=1, delimiter=",")
102103
medium, rms = fitter.fit(num_tries=20)
103104
fitter.plot(medium)
105+
106+
107+
def test_dispersion_set_wvg_range():
108+
"""set wavelength range function"""
109+
num_data = 50
110+
n_data = np.random.random(num_data)
111+
wvls = np.linspace(1, 2, num_data)
112+
fitter = DispersionFitter(wvl_um=wvls, n_data=n_data)
113+
114+
wvl_min = np.random.random(1)[0] * 0.5 + 1
115+
wvl_max = wvl_min + 0.5
116+
fitter.wvl_range = [wvl_min, wvl_max]
117+
assert len(fitter.freqs) < num_data
118+
medium, rms = fitter.fit(num_tries=2)

0 commit comments

Comments
 (0)