Skip to content

Commit

Permalink
fix ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
joamatab committed Nov 27, 2024
1 parent b5e314f commit 72b4369
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions gplugins/spice/spice_to_yaml.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# type: ignore
import os
import pathlib
import re
Expand Down Expand Up @@ -420,17 +421,15 @@ def get_instances(netlist: str, models: dict) -> list:
grouped_instances = group_instance_str(netlist)
instances = []
non_pdk = []
model_names = []
for model in models:
model_names.append(str(model))
model_names = [str(model) for model in models]
# Get params using regular expressions
pattern = r'(\w+|"[^"]*")\s*=\s*({.*?}|-[0-9.]+|[0-9.]+|f+|y+|x+|"[^"]*")'
for inst_line in grouped_instances:
instance = {}
# Get preamble before parameters (instance name, nets, model name)
fields = inst_line.split(" ")
instance["name"] = fields[0]

# Get params using regular expressions
pattern = r'(\w+|"[^"]*")\s*=\s*({.*?}|-[0-9.]+|[0-9.]+|f+|y+|x+|"[^"]*")'
matches = re.findall(pattern, inst_line)

# Get fields before params
Expand Down Expand Up @@ -459,7 +458,7 @@ def get_instances(netlist: str, models: dict) -> list:
match = re.match(r"([\d.]+)([un])", value)
if match:
instance["params"][param] = (
float(match.group(1)) * CONVERSION[match.group(2)]
float(match[1]) * CONVERSION[match.group(2)]
)
else:
try:
Expand All @@ -477,12 +476,10 @@ def get_instances(netlist: str, models: dict) -> list:
instances.append(instance)
except KeyError:
non_pdk.append(instance["name"])
pass

if len(non_pdk) > 0:
if non_pdk:
print(
"LOG: Non-PDK elements detected! Removing instances {"
+ ", ".join(x for x in non_pdk)
+ ", ".join(non_pdk)
+ "} from netlist."
)
return instances
Expand Down Expand Up @@ -540,6 +537,7 @@ def get_instances_info(
.
}
}
ignore_electrical: Flag to ignore electrical routes and bundles.
ignored_info: Ignored param names that will not be put into the 'settings' or 'info' fields (list of str)
Returns:
Expand Down Expand Up @@ -671,19 +669,13 @@ def group_instance_str(netlist: str) -> list:
i
].strip().startswith("+"):
instances.append(lines[i].strip())
i = i + 1
i += 1

while i < len(lines) and lines[i].strip().startswith("+") and instances:
instances[-1] = instances[-1] + lines[i].strip()[1:-1]
i = i + 1

# Check that each instance has params. If not, remove them
filtered_instances = []
for inst in instances:
if "=" in inst:
filtered_instances.append(inst)
i += 1

return filtered_instances
return [inst for inst in instances if "=" in inst]


def get_placements(instances: list, mapping: dict, ignore_electrical: bool) -> dict:
Expand Down Expand Up @@ -921,10 +913,10 @@ def get_routes(instances, mapping, layers, ignore_electrical):
"""Extract routing information from instances using provided mapping and layers.
Args:
- instances: list of instance dictionaries with port and net information.
- mapping: dictionary mapping model names to layout cells and their properties.
- layers: dictionary defining parameters for different routing layers.
- ignore_electrical: boolean indicating whether to ignore electrical routes.
instances: list of instance dictionaries with port and net information.
mapping: dictionary mapping model names to layout cells and their properties.
layers: dictionary defining parameters for different routing layers.
ignore_electrical: boolean indicating whether to ignore electrical routes.
Returns:
- A dictionary of routes organized by bundle types.
Expand Down

0 comments on commit 72b4369

Please sign in to comment.