Skip to content

Commit

Permalink
Fix string parameters being stored only for the first device type
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosavola committed May 30, 2024
1 parent 608e5d4 commit 81e5345
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions gplugins/klayout/netlist_spice_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def parse_element(self, s: str, element: str) -> kdb.ParseElementData:
def hash_str_to_int(s: str) -> int:
return int(hashlib.shake_128(s.encode()).hexdigest(4), 16)

def write_str_property_as_int(self, value: str) -> int:
"""Store string property in hash map and return integer hash value."""
hashed_value = CalibreSpiceReader.hash_str_to_int(value)
self.integer_to_string_map[hashed_value] = value
return hashed_value

@override
def element(
self,
Expand All @@ -94,15 +100,8 @@ def element(
if not clx:
clx = kdb.DeviceClass()
clx.name = model
for key, value in parameters.items():
for key in parameters.keys():
clx.add_parameter(kdb.DeviceParameterDefinition(key))
# map string variables to integers
if (
isinstance(value, str)
and value not in self.integer_to_string_map.values()
):
hashed_value = CalibreSpiceReader.hash_str_to_int(value)
self.integer_to_string_map[hashed_value] = value

for i in range(len(nets)):
clx.add_terminal(kdb.DeviceTerminalDefinition(str(i)))
Expand All @@ -113,12 +112,17 @@ def element(
device.connect_terminal(i, net)

for key, value in parameters.items():
# map string variables to integers
possibly_hashed_value = (
self.write_str_property_as_int(value)
if isinstance(value, str)
else value
)

device.set_parameter(
key,
(
CalibreSpiceReader.hash_str_to_int(value)
if isinstance(value, str)
else value
possibly_hashed_value
or 0 # default to 0 for None in order to still have the parameter field
),
)
Expand Down

0 comments on commit 81e5345

Please sign in to comment.