Skip to content

Commit 9095eb2

Browse files
fix(tidy3d): FXC-4026-parsing-error-in-klayout-drc-results-loader
1 parent 989e807 commit 9095eb2

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6767
- Improved type hints for `Tidy3dBaseModel`, so that all derived classes will have more accurate return types.
6868
- More robust method for suppressing RF license warnings during tests.
6969
- Fixed frequency sampling of `TransmissionLineDataset` within `MicrowaveModeData` when using group index calculation.
70+
- Fixed DRC parsing for quoted categories in klayout plugin.
7071

7172
### Removed
7273
- Removed deprecated `use_complex_fields` parameter from `TwoPhotonAbsorption` and `KerrNonlinearity`. Parameters `beta` and `n2` are now real-valued only, as is `n0` if specified.

tests/test_plugins/klayout/drc/drc_results_widthonly_clean.lyrdb renamed to tests/test_plugins/klayout/drc/drc_results_clean.lyrdb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
<categories>
1414
</categories>
1515
</category>
16+
<category>
17+
<name>'quoted category'</name>
18+
<description>test if quoted categories are parsed correctly</description>
19+
<categories>
20+
</categories>
21+
</category>
1622
</categories>
1723
<cells>
1824
<cell>

tests/test_plugins/klayout/drc/test_drc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ def drc_results(self):
326326
return DRCResults.load(filepath / "drc_results.lyrdb")
327327

328328
@pytest.fixture(scope="class")
329-
def drc_results_widthonly_clean(self):
329+
def drc_results_clean(self):
330330
"""Load the DRC results"""
331-
return DRCResults.load(filepath / "drc_results_widthonly_clean.lyrdb")
331+
return DRCResults.load(filepath / "drc_results_clean.lyrdb")
332332

333333
def test_result_file_load(self, tmp_path):
334334
"""Test that result file loading works"""
@@ -347,10 +347,10 @@ def test_result_file_load(self, tmp_path):
347347
with pytest.raises(ET.ParseError):
348348
DRCResults.load(tmp_path / "bad_resultsfile.lyrdb")
349349

350-
def test_is_drc_clean(self, drc_results, drc_results_widthonly_clean):
350+
def test_is_drc_clean(self, drc_results, drc_results_clean):
351351
"""Test DRCResults.is_clean"""
352352
assert not drc_results.is_clean
353-
assert drc_results_widthonly_clean.is_clean
353+
assert drc_results_clean.is_clean
354354

355355
def test_count_drc_violations(self, drc_results):
356356
"""Test that counting violations works"""

tidy3d/plugins/klayout/drc/results.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,22 @@ def violations_from_file(resultsfile: Union[str, Path]) -> dict[str, DRCViolatio
350350
# Initialize violations dict with all the categories
351351
violations = {}
352352
for category in xmltree.getroot().findall(".//categories/category/name"):
353-
violations[category.text] = DRCViolation(category=category.text, markers=())
353+
category_name = category.text
354+
if category_name is None:
355+
raise FileError("Encountered DRC category without a name in results file.")
356+
category_name = category_name.strip().strip("'\"")
357+
violations[category_name] = DRCViolation(category=category_name, markers=())
354358

355359
# Parse markers
356360
for item in xmltree.getroot().findall(".//item"):
357-
category = item.find("category").text
361+
category_el = item.find("category")
362+
if category_el is None or category_el.text is None:
363+
raise FileError("Encountered DRC item without a category in results file.")
364+
category = category_el.text.strip().strip("'\"")
358365
value = item.find("values/value").text
359366
marker = parse_violation_value(value)
367+
if category not in violations:
368+
violations[category] = DRCViolation(category=category, markers=())
360369
violations[category] = DRCViolation(
361370
category=category,
362371
markers=(*violations[category].markers, marker),

0 commit comments

Comments
 (0)