Skip to content

Commit e7bc235

Browse files
committed
fix: expressions plugin doctests
1 parent 6da4072 commit e7bc235

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- Regression in local field projection leading to incorrect results for `far_field_approx=True`.
2424
- Bug when differentiating with respect to `Cylinder.center`.
2525
- `xarray` 2024.10.0 compatibility for autograd.
26+
- Some failing examples in the expressions plugin documentation.
2627

2728

2829
## [2.7.6] - 2024-10-30

tidy3d/plugins/expressions/metrics.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ class ModeAmp(Metric):
5454
5555
Examples
5656
--------
57-
>>> monitor = ModeMonitor(name="monitor1", f=[1.0])
57+
>>> import tidy3d as td
58+
>>> monitor = td.ModeMonitor(size=(1, 1, 0), freqs=[2e14], mode_spec=td.ModeSpec(), name="monitor1")
5859
>>> mode_coeff = ModeAmp.from_mode_monitor(monitor)
59-
>>> data = SimulationData() # Assume this is a valid SimulationData object
60-
>>> result = mode_coeff.evaluate(data)
60+
>>> expr = abs(mode_coeff) ** 2
61+
>>> print(expr)
62+
(abs(ModeAmp("monitor1")) ** 2)
6163
"""
6264

6365
monitor_name: str = pd.Field(
@@ -122,10 +124,9 @@ class ModePower(ModeAmp):
122124
123125
Examples
124126
--------
125-
>>> monitor = ModeMonitor(name="monitor1", f=[1.0])
127+
>>> import tidy3d as td
128+
>>> monitor = td.ModeMonitor(size=(1, 1, 0), freqs=[2e14], mode_spec=td.ModeSpec(), name="monitor1")
126129
>>> mode_power = ModePower.from_mode_monitor(monitor)
127-
>>> data = SimulationData() # Assume this is a valid SimulationData object
128-
>>> result = mode_power.evaluate(data)
129130
"""
130131

131132
def evaluate(self, *args: Any, **kwargs: Any) -> NumberType:

tidy3d/plugins/expressions/variables.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ class Variable(Expression):
2929
3030
Examples
3131
--------
32-
>>> x = Variable()
32+
>>> x = Variable() # unnamed
3333
>>> y = Variable(name='y')
34-
>>> expr = x + y
35-
>>> expr(5, y=3) # Returns 8
36-
>>> expr(5, 3) # Raises ValueError
34+
>>> z = Variable(name='z')
35+
>>> expr = x + y + z
36+
>>> expr(5, y=3, z=2)
37+
10
3738
"""
3839

3940
name: Optional[str] = pd.Field(
@@ -75,7 +76,8 @@ class Constant(Variable):
7576
Examples
7677
--------
7778
>>> c = Constant(5)
78-
>>> c.evaluate() # Returns 5
79+
>>> c.evaluate()
80+
5
7981
"""
8082

8183
value: NumberType = pd.Field(

0 commit comments

Comments
 (0)