Skip to content

Commit

Permalink
Merge pull request ucb-art#15 from hyunjaekwon/misc_fixes
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
ayan-biswas authored Jun 30, 2022
2 parents daccd43 + 2a45836 commit fdccd75
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/bag/simulation/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,20 +279,35 @@ async def _create_dut(self, impl_cell: str,
write_yaml(self._info_file, self._info_specs)
else:
dir_path = None
dirs_to_remove = []
for dir_name in dir_list:
cur_dir = self._root_dir / dir_name
if filecmp.cmp(cdl_netlist, cur_dir / 'netlist.cdl', shallow=False):
cur_netlist = cur_dir / 'netlist.cdl'
if not cur_netlist.exists(): # Cached netlist is missing, should ignore and remove from the cache
dirs_to_remove.append(dir_name)
continue
if filecmp.cmp(cdl_netlist, cur_netlist, shallow=False):
is_cached = await self.gds_check_cache(gds_file, cur_dir)
if is_cached:
self.log('Found existing design, reusing DUT netlist.')
dir_path = cur_dir
break

if dirs_to_remove:
for dir_name in dirs_to_remove:
dir_list.remove(dir_name)
if dir_list: # Remove entry from cache
del self._cache[hash_id]
else:
self._cache[hash_id] = dir_list
write_yaml(self._info_file, self._info_specs)

if dir_path is None:
dir_path = self._generate_cell(impl_cell, cdl_netlist, gds_file)
dir_list.append(dir_path.name)
write_yaml(self._info_file, self._info_specs)
shutil.rmtree(tmp_dir) # Remove temporary directory

shutil.rmtree(tmp_dir) # Remove temporary directory

if em:
ans = Path(cdl_netlist)
Expand Down
9 changes: 7 additions & 2 deletions src/bag/simulation/srr.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'td.pss': 'pss_td',
'fd.pss': 'pss_fd',
'timedomain.pnoise': 'pnoise',
'pac_timepoint': 'pac',
}


Expand Down Expand Up @@ -146,11 +147,15 @@ def get_sim_env(ds: pysrrDataSet) -> str:

ds_name = ds._name
ana_type = ds.getAnalysisType()
sim_env_fmt = rf'[a-zA-Z0-9]+_[a-zA-Z0-9]+'
if ana_type.endswith(('.pss', '.pnoise')):
ana_type_end = ana_type.split('.')[-1]
matched = re.search(rf'__+{ana_type_end}__+(.+)__+.*-{ana_type}', ds_name)
matched = re.search(rf'__+{ana_type_end}__+({sim_env_fmt})__+.*-', ds_name)
elif ana_type.startswith('pac_'):
ana_type_start = ana_type.split('_')[0]
matched = re.search(rf'__+{ana_type_start}__+({sim_env_fmt})__+.*-{ana_type}', ds_name)
else:
matched = re.search(rf'__+{ana_type}__+(.+)__+.*', ds_name)
matched = re.search(rf'__+{ana_type}__+({sim_env_fmt})__+.*', ds_name)
if not matched:
raise ValueError(f"Unmatched dataset name {ds_name} of analysis type {ana_type}")
return matched.group(1)
Expand Down
5 changes: 5 additions & 0 deletions src/bag/util/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ class Calculator(ast.NodeVisitor):
ast.Div: operator.truediv,
ast.Invert: operator.neg,
ast.FloorDiv: operator.floordiv,
ast.USub: operator.neg,
}

def __init__(self, namespace: Mapping[str, Any]) -> None:
Expand All @@ -357,6 +358,10 @@ def visit_BinOp(self, node):
right = self.visit(node.right)
return self._OP_MAP[type(node.op)](left, right)

def visit_UnaryOp(self, node):
operand = self.visit(node.operand)
return self._OP_MAP[type(node.op)](operand)

def visit_Num(self, node):
return node.n

Expand Down

0 comments on commit fdccd75

Please sign in to comment.