Coverage for tests/klayout/netlist_expander_test.py: 100%
38 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-17 19:08 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-17 19:08 +0000
1#
2# --------------------------------------------------------------------------------
3# SPDX-FileCopyrightText: 2024-2025 Martin Jan Köhler and Harald Pretl
4# Johannes Kepler University, Institute for Integrated Circuits.
5#
6# This file is part of KPEX
7# (see https://github.com/iic-jku/klayout-pex).
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21# SPDX-License-Identifier: GPL-3.0-or-later
22# --------------------------------------------------------------------------------
23#
24from __future__ import annotations
26import allure
27import os
28import tempfile
29import unittest
31import klayout.db as kdb
33from klayout_pex.fastercap.output_interpreter import FasterCapOutputInterpreter
34from klayout_pex.klayout.lvsdb_extractor import KLayoutExtractionContext
35from klayout_pex.klayout.netlist_expander import NetlistExpander
36from klayout_pex.log import (
37 debug,
38)
39from klayout_pex.common.capacitance_matrix import CapacitanceMatrix
40from klayout_pex.tech_info import TechInfo
43@allure.parent_suite("Unit Tests")
44@allure.tag("Netlist", "Netlist Expansion")
45class Test(unittest.TestCase):
46 @property
47 def klayout_testdata_dir(self) -> str:
48 return os.path.realpath(os.path.join(__file__, '..', '..', '..',
49 'testdata', 'fastercap'))
51 @property
52 def tech_info_json_path(self) -> str:
53 return os.path.realpath(os.path.join(__file__, '..', '..', '..',
54 'klayout_pex_protobuf', 'sky130A_tech.pb.json'))
56 def test_netlist_expansion(self):
57 exp = NetlistExpander()
59 cell_name = 'nmos_diode2'
61 lvsdb = kdb.LayoutVsSchematic()
62 lvsdb_path = os.path.join(self.klayout_testdata_dir, f"{cell_name}.lvsdb.gz")
63 lvsdb.read(lvsdb_path)
65 csv_path = os.path.join(self.klayout_testdata_dir, f"{cell_name}_FasterCap_Result_Matrix.csv")
67 cap_matrix = CapacitanceMatrix.parse_csv(csv_path, separator=';')
69 tech = TechInfo.from_json(self.tech_info_json_path,
70 dielectric_filter=None)
72 pex_context = KLayoutExtractionContext.prepare_extraction(top_cell=cell_name,
73 lvsdb=lvsdb,
74 tech=tech,
75 blackbox_devices=False)
76 expanded_netlist = exp.expand(extracted_netlist=pex_context.lvsdb.netlist(),
77 top_cell_name=pex_context.annotated_top_cell.name,
78 cap_matrix=cap_matrix,
79 cap_matrix_interpreter=FasterCapOutputInterpreter(),
80 blackbox_devices=False)
81 out_path = tempfile.mktemp(prefix=f"{cell_name}_expanded_netlist_", suffix=".cir")
82 spice_writer = kdb.NetlistSpiceWriter()
83 expanded_netlist.write(out_path, spice_writer)
84 debug(f"Wrote expanded netlist to: {out_path}")
86 allure.attach.file(csv_path, attachment_type=allure.attachment_type.CSV)
87 allure.attach.file(out_path, attachment_type=allure.attachment_type.TEXT)