Skip to content

Commit 917c3ad

Browse files
committed
add doctests
1 parent 2727e2f commit 917c3ad

File tree

8 files changed

+89
-22
lines changed

8 files changed

+89
-22
lines changed

tests/test_components/test_geometry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,10 +1202,10 @@ def test_snap_box_to_grid_strict_behaviors():
12021202
expanded_box = snap_box_to_grid(grid, box_coincident, snap_spec_strict_expand)
12031203

12041204
# StrictExpand should move bounds outwards even when already on grid
1205-
assert expanded_box.bounds[0][0] < 0.1 # Left bound moved left from 0.1
1206-
assert expanded_box.bounds[1][0] > 0.1 # Right bound moved right from 0.1
1207-
assert expanded_box.bounds[0][1] < 0.2 # Bottom bound moved down from 0.2
1208-
assert expanded_box.bounds[1][1] > 0.2 # Top bound moved up from 0.2
1205+
assert np.isclose(expanded_box.bounds[0][0], 0.0) # Left bound moved left from 0.1
1206+
assert np.isclose(expanded_box.bounds[1][0], 0.2) # Right bound moved right from 0.1
1207+
assert np.isclose(expanded_box.bounds[0][1], 0.1) # Bottom bound moved down from 0.2
1208+
assert np.isclose(expanded_box.bounds[1][1], 0.3) # Top bound moved up from 0.2
12091209

12101210
# Test StrictContract: should always move endpoints inwards, even if coincident
12111211
box_large = td.Box(center=(0.5, 0.5, 0.5), size=(0.4, 0.4, 0.4)) # Spans multiple grid cells

tidy3d/components/data/monitor_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ class ModeData(ModeSolverDataset, ElectromagneticFieldData):
16551655
None,
16561656
title="Microwave Mode Dataset",
16571657
description="Additional data relevant to RF and microwave applications, like characteristic impedance. "
1658-
"This field is populated when a :class:`MicrowaveModeSpec` has been provided to the :class:`ModeSpec`.",
1658+
"This field is populated when a :class:`MicrowaveModeSpec` has been used to set up the monitor or mode solver.",
16591659
)
16601660

16611661
@pd.validator("eps_spec", always=True)

tidy3d/components/microwave/data/dataset.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""Post-processing data and figures of merit for antennas, including radiation efficiency,
2-
reflection efficiency, gain, and realized gain.
3-
"""
1+
"""Dataset for microwave and RF transmission line mode data, including impedance, voltage, and current coefficients."""
42

53
from __future__ import annotations
64

@@ -24,7 +22,7 @@ class MicrowaveModeDataset(Dataset):
2422
title="Characteristic Impedance",
2523
description="Optional quantity calculated for transmission lines. "
2624
"The characteristic impedance is only calculated when a :class:`MicrowaveModeSpec` "
27-
"is provided to the :class:`ModeSpec` associated with this data.",
25+
"is provided to the :class:`ModeMonitor` or mode solver.",
2826
)
2927

3028
voltage_coeffs: Optional[VoltageFreqModeDataArray] = pd.Field(
@@ -33,7 +31,7 @@ class MicrowaveModeDataset(Dataset):
3331
description="Optional quantity calculated for transmission lines, which associates "
3432
"a voltage-like quantity with each mode profile that scales linearly with the "
3533
"complex-valued mode amplitude. The mode voltages are only calculated when a :class:`MicrowaveModeSpec` "
36-
"is provided to the :class:`ModeSpec` associated with this data.",
34+
"is provided to the :class:`ModeMonitor` or mode solver.",
3735
)
3836

3937
current_coeffs: Optional[CurrentFreqModeDataArray] = pd.Field(
@@ -42,5 +40,5 @@ class MicrowaveModeDataset(Dataset):
4240
description="Optional quantity calculated for transmission lines, which associates "
4341
"a current-like quantity with each mode profile that scales linearly with the "
4442
"complex-valued mode amplitude. The mode currents are only calculated when a :class:`MicrowaveModeSpec`"
45-
" is provided to the :class:`ModeSpec` associated with this data.",
43+
" is provided to the :class:`ModeMonitor` or mode solver.",
4644
)

tidy3d/components/microwave/microwave_mode_spec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ class MicrowaveModeSpec(ModeSpec):
2626
impedance_specs: tuple[Optional[annotate_type(ImpedanceSpecTypes)], ...] = pd.Field(
2727
...,
2828
title="Impedance Specifications",
29-
description="Field controls how the impedance is calculated for each mode calculated by the mode solver.",
29+
description="Field controls how the impedance is calculated for each mode calculated by the mode solver. "
30+
"The number of impedance specifications should match the number of modes field. "
31+
"When an impedance specification of ``None`` is used, the impedance calculation will be "
32+
"ignored for the associated mode.",
3033
)
3134

3235
@cached_property

tidy3d/components/microwave/path_integrals/base_spec.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,16 @@ def _warn_rf_license(cls, values):
6363

6464

6565
class AxisAlignedPathIntegralSpec(AbstractAxesRH, Box):
66-
"""Class for defining the simplest type of path integral, which is aligned with Cartesian axes."""
66+
"""Class for defining the simplest type of path integral, which is aligned with Cartesian axes.
67+
68+
Example
69+
-------
70+
>>> path_spec = AxisAlignedPathIntegralSpec( # doctest: +SKIP
71+
... center=(0, 0, 1),
72+
... size=(0, 0, 2),
73+
... extrapolate_to_endpoints=True
74+
... )
75+
"""
6776

6877
_line_validator = assert_line()
6978

@@ -104,6 +113,16 @@ def _vertices_2D(self, axis: Axis) -> tuple[Coordinate2D, Coordinate2D]:
104113
class Custom2DPathIntegralSpec(AbstractAxesRH):
105114
"""Class for specifying a custom path integral defined as a curve on an axis-aligned plane.
106115
116+
Example
117+
-------
118+
>>> import numpy as np
119+
>>> vertices = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
120+
>>> path_spec = Custom2DPathIntegralSpec( # doctest: +SKIP
121+
... axis=2,
122+
... position=0.5,
123+
... vertices=vertices
124+
... )
125+
107126
Notes
108127
-----
109128
@@ -116,7 +135,7 @@ class Custom2DPathIntegralSpec(AbstractAxesRH):
116135
"""
117136

118137
axis: Axis = pd.Field(
119-
2, title="Axis", description="Specifies dimension of the planar axis (0,1,2) -> (x,y,z)."
138+
..., title="Axis", description="Specifies dimension of the planar axis (0,1,2) -> (x,y,z)."
120139
)
121140

122141
position: float = pd.Field(

tidy3d/components/microwave/path_integrals/current_spec.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@
2424

2525

2626
class AxisAlignedCurrentIntegralSpec(AbstractAxesRH, Box):
27-
"""Class for specifying the computation of conduction current via Ampère's circuital law on an axis-aligned loop."""
27+
"""Class for specifying the computation of conduction current via Ampère's circuital law on an axis-aligned loop.
28+
29+
Example
30+
-------
31+
>>> current_spec = AxisAlignedCurrentIntegralSpec( # doctest: +SKIP
32+
... center=(0, 0, 0),
33+
... size=(1, 1, 0),
34+
... sign="+",
35+
... snap_contour_to_grid=True
36+
... )
37+
"""
2838

2939
_plane_validator = assert_plane()
3040

@@ -215,7 +225,18 @@ def plot(
215225
class Custom2DCurrentIntegralSpec(Custom2DPathIntegralSpec):
216226
"""Class for specifying the computation of conduction current via Ampère's circuital law on a custom path.
217227
To compute the current flowing in the positive ``axis`` direction, the vertices should be
218-
ordered in a counterclockwise direction."""
228+
ordered in a counterclockwise direction.
229+
230+
Example
231+
-------
232+
>>> import numpy as np
233+
>>> vertices = np.array([[0, 0], [2, 0], [2, 1], [0, 1], [0, 0]])
234+
>>> current_spec = Custom2DCurrentIntegralSpec( # doctest: +SKIP
235+
... axis=2,
236+
... position=0,
237+
... vertices=vertices
238+
... )
239+
"""
219240

220241
@add_ax_if_none
221242
def plot(
@@ -273,6 +294,19 @@ class CompositeCurrentIntegralSpec(Tidy3dBaseModel):
273294
274295
This class is used to set up a ``CompositeCurrentIntegral``, which combines
275296
multiple current integrals. It does not perform any integration itself.
297+
298+
Example
299+
-------
300+
>>> spec1 = AxisAlignedCurrentIntegralSpec( # doctest: +SKIP
301+
... center=(0, 0, 0), size=(1, 1, 0), sign="+"
302+
... )
303+
>>> spec2 = AxisAlignedCurrentIntegralSpec( # doctest: +SKIP
304+
... center=(2, 0, 0), size=(1, 1, 0), sign="+"
305+
... )
306+
>>> composite_spec = CompositeCurrentIntegralSpec( # doctest: +SKIP
307+
... path_specs=(spec1, spec2),
308+
... sum_spec="sum"
309+
... )
276310
"""
277311

278312
path_specs: tuple[Union[AxisAlignedCurrentIntegralSpec, Custom2DCurrentIntegralSpec], ...] = (

tidy3d/components/microwave/path_integrals/impedance_spec.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,33 @@ class CustomImpedanceSpec(Tidy3dBaseModel):
3232
3333
Users must supply at least one of voltage or current path specifications to control where these integrals
3434
are evaluated. Both voltage_spec and current_spec cannot be ``None`` simultaneously.
35+
36+
Example
37+
-------
38+
>>> from tidy3d.components.microwave.path_integrals.voltage_spec import AxisAlignedVoltageIntegralSpec
39+
>>> from tidy3d.components.microwave.path_integrals.current_spec import AxisAlignedCurrentIntegralSpec
40+
>>> voltage_spec = AxisAlignedVoltageIntegralSpec( # doctest: +SKIP
41+
... center=(0, 0, 0), size=(0, 0, 1), sign="+"
42+
... )
43+
>>> current_spec = AxisAlignedCurrentIntegralSpec( # doctest: +SKIP
44+
... center=(0, 0, 0), size=(2, 1, 0), sign="+"
45+
... )
46+
>>> impedance_spec = CustomImpedanceSpec( # doctest: +SKIP
47+
... voltage_spec=voltage_spec,
48+
... current_spec=current_spec
49+
... )
3550
"""
3651

3752
voltage_spec: Optional[VoltagePathSpecTypes] = pd.Field(
3853
None,
3954
title="Voltage Integration Path",
40-
description="Path specification for computing the voltage associated with each mode. "
41-
"The number of path specifications should equal the 'num_modes' field "
42-
"in the 'ModeSpec'.",
55+
description="Path specification for computing the voltage associated with a mode profile.",
4356
)
4457

4558
current_spec: Optional[CurrentPathSpecTypes] = pd.Field(
4659
None,
4760
title="Current Integration Path",
48-
description="Path specification for computing the current associated with each mode. "
49-
"The number of path specifications should equal the 'num_modes' field "
50-
"in the 'ModeSpec'.",
61+
description="Path specification for computing the current associated with a mode profile.",
5162
)
5263

5364
@pd.validator("current_spec", always=True)

tidy3d/components/microwave/path_integrals/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Common type definitions for path integral specifications."""
2+
13
from __future__ import annotations
24

35
from typing import Union

0 commit comments

Comments
 (0)