Skip to content

Commit e320a18

Browse files
committed
revising PR
1 parent a3ac3b5 commit e320a18

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

tests/test_components/test_microwave.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def test_make_path_integrals_validation():
581581
microwave_spec = td.MicrowaveModeSpec(impedance_specs=(impedance_spec,))
582582

583583
# Test successful creation
584-
voltage_integrals, current_integrals = make_path_integrals(microwave_spec, mode_monitor)
584+
voltage_integrals, current_integrals = make_path_integrals(microwave_spec)
585585
assert len(voltage_integrals) == 1
586586
assert len(current_integrals) == 1
587587
assert voltage_integrals[0] is not None
@@ -590,7 +590,7 @@ def test_make_path_integrals_validation():
590590
# Test with None specs - when both are None, use_automatic_setup is True
591591
# This means current integrals will be auto-generated, not None
592592
microwave_spec_none = td.MicrowaveModeSpec(impedance_specs=(None,))
593-
voltage_integrals, current_integrals = make_path_integrals(microwave_spec_none, mode_monitor)
593+
voltage_integrals, current_integrals = make_path_integrals(microwave_spec_none)
594594
assert len(voltage_integrals) == mode_monitor.mode_spec.num_modes
595595
assert len(current_integrals) == mode_monitor.mode_spec.num_modes
596596
assert all(vi is None for vi in voltage_integrals)
@@ -600,9 +600,6 @@ def test_make_path_integrals_validation():
600600
def test_make_path_integrals_construction_errors(monkeypatch):
601601
"""Test that make_path_integrals handles construction errors properly."""
602602

603-
sim = make_mw_sim(False, False, "microstrip")
604-
mode_monitor = sim.monitors[0]
605-
606603
# Create a valid spec
607604
v_spec = td.AxisAlignedVoltageIntegralSpec(center=(1, 2, 3), size=(0, 0, 1), sign="-")
608605

@@ -620,7 +617,7 @@ def mock_make_voltage_integral(path_spec):
620617

621618
# This should raise a SetupError due to construction failure
622619
with pytest.raises(SetupError, match="Failed to construct path integrals"):
623-
make_path_integrals(microwave_spec, mode_monitor)
620+
make_path_integrals(microwave_spec)
624621

625622

626623
def test_path_integral_factory_composite_current():
@@ -658,9 +655,6 @@ def test_path_integral_factory_composite_current():
658655
def test_path_integral_factory_mixed_specs():
659656
"""Test make_path_integrals with mixed voltage and current specs (some None)."""
660657

661-
sim = make_mw_sim(False, False, "microstrip")
662-
mode_monitor = sim.monitors[0]
663-
664658
# Create specs where some are None
665659
v_spec = td.AxisAlignedVoltageIntegralSpec(center=(1, 2, 3), size=(0, 0, 1), sign="-")
666660
i_spec = td.AxisAlignedCurrentIntegralSpec(center=(1, 2, 3), size=(0, 1, 1), sign="-")
@@ -675,7 +669,7 @@ def test_path_integral_factory_mixed_specs():
675669
),
676670
)
677671

678-
voltage_integrals, current_integrals = make_path_integrals(microwave_spec, mode_monitor)
672+
voltage_integrals, current_integrals = make_path_integrals(microwave_spec)
679673

680674
assert len(voltage_integrals) == 2
681675
assert len(current_integrals) == 2

tidy3d/components/microwave/path_integrals/path_integral_factory.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22

33
from __future__ import annotations
44

5-
from typing import Optional, Union
5+
from typing import Optional
66

77
from tidy3d.components.microwave.microwave_mode_spec import MicrowaveModeSpec
88
from tidy3d.components.microwave.path_integrals.current_spec import (
99
AxisAlignedCurrentIntegralSpec,
1010
CompositeCurrentIntegralSpec,
1111
Custom2DCurrentIntegralSpec,
1212
)
13+
from tidy3d.components.microwave.path_integrals.impedance_spec import (
14+
AutoImpedanceSpec,
15+
CustomImpedanceSpec,
16+
)
1317
from tidy3d.components.microwave.path_integrals.types import (
1418
CurrentPathSpecTypes,
1519
VoltagePathSpecTypes,
@@ -18,7 +22,6 @@
1822
AxisAlignedVoltageIntegralSpec,
1923
Custom2DVoltageIntegralSpec,
2024
)
21-
from tidy3d.components.monitor import ModeMonitor, ModeSolverMonitor
2225
from tidy3d.exceptions import SetupError, ValidationError
2326
from tidy3d.plugins.microwave import (
2427
AxisAlignedCurrentIntegral,
@@ -82,8 +85,7 @@ def make_current_integral(path_spec: CurrentPathSpecTypes) -> CurrentIntegralTyp
8285

8386

8487
def make_path_integrals(
85-
microwave_mode_spec: MicrowaveModeSpec,
86-
monitor: Union[ModeMonitor, ModeSolverMonitor],
88+
microwave_mode_spec: MicrowaveModeSpec, auto_spec: Optional[CustomImpedanceSpec] = None
8789
) -> tuple[tuple[Optional[VoltageIntegralTypes]], tuple[Optional[CurrentIntegralTypes]]]:
8890
"""
8991
Given a microwave mode specification and monitor, create the voltage and
@@ -93,9 +95,8 @@ def make_path_integrals(
9395
----------
9496
microwave_mode_spec : MicrowaveModeSpec
9597
Microwave mode specification for creating voltage and current path specifications.
96-
monitor : Union[ModeMonitor, ModeSolverMonitor]
97-
The monitor for which the path integrals are being generated.
98-
98+
auto_spec: Optional[CustomImpedanceSpec]
99+
The automatically created impedance specification, if available.
99100
Returns
100101
-------
101102
tuple[tuple[Optional[VoltageIntegralTypes]], tuple[Optional[CurrentIntegralTypes]]]
@@ -107,7 +108,7 @@ def make_path_integrals(
107108
If path specifications cannot be auto-generated or path integrals cannot be constructed.
108109
"""
109110

110-
if microwave_mode_spec._using_auto_current_spec:
111+
if microwave_mode_spec._using_auto_current_spec and auto_spec is None:
111112
raise SetupError("Auto path specification is not available for the local mode solver.")
112113

113114
v_integrals = []
@@ -122,6 +123,9 @@ def make_path_integrals(
122123
v_integrals.append(None)
123124
i_integrals.append(None)
124125
continue
126+
elif isinstance(impedance_spec, AutoImpedanceSpec):
127+
v_spec = None
128+
i_spec = auto_spec.current_spec
125129
else:
126130
v_spec = impedance_spec.voltage_spec
127131
i_spec = impedance_spec.current_spec
@@ -137,7 +141,7 @@ def make_path_integrals(
137141
i_integrals.append(i_integral)
138142
except Exception as e:
139143
raise SetupError(
140-
f"Failed to construct path integrals for the mode index {idx} in monitor '{monitor.name}' "
144+
f"Failed to construct path integrals for the mode with index {idx} "
141145
"from the impedance specification. "
142146
"Please create a github issue so that the problem can be investigated."
143147
) from e

tidy3d/components/mode/mode_solver.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,10 +1380,7 @@ def _make_path_integrals(
13801380
raise ValueError(
13811381
"Cannot make path integrals for when 'mode_spec' is not a 'MicrowaveModeSpec'."
13821382
)
1383-
return make_path_integrals(
1384-
self.mode_spec.microwave_spec,
1385-
self.to_monitor(name=MODE_MONITOR_NAME),
1386-
)
1383+
return make_path_integrals(self.mode_spec.microwave_spec)
13871384

13881385
def _add_microwave_data(self, mode_solver_data: ModeSolverData) -> ModeSolverData:
13891386
"""Calculate and add microwave data to ``mode_solver_data`` which uses the path specifications."""

0 commit comments

Comments
 (0)