Skip to content

Commit

Permalink
kpex CLI: dedicated LVS cache directory (allows Github Actions caching)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjankoehler committed Dec 13, 2024
1 parent c6ea305 commit 96b0f09
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions klayout_pex/kpex_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def parse_args(arg_list: List[str] = None) -> argparse.Namespace:
group_pex_input.add_argument("--cache-lvs", dest="cache_lvs",
type=true_or_false, default=True,
help="Used cached LVSDB (for given input GDS) (default is %(default)s)")
group_pex_input.add_argument("--cache-dir", dest="cache_dir_path", default=None,
help="Path for cached LVSDB (default is .kpex_cache within --out_dir)")

group_pex_options = main_parser.add_argument_group("Parasitic Extraction Options")
group_pex_options.add_argument("--blackbox", dest="blackbox_devices",
Expand Down Expand Up @@ -402,6 +404,9 @@ def input_file_stem(path: str):
subproc(f"\nPlease activate one or more engines using the arguments:\n{engine_help}")
found_errors = True

if args.cache_dir_path is None:
args.cache_dir_path = os.path.join(args.output_dir_base_path, '.kpex_cache')

if found_errors:
raise ArgumentValidationError("Argument validation failed")

Expand Down Expand Up @@ -683,13 +688,22 @@ def create_lvsdb(self, args: argparse.Namespace) -> kdb.LayoutVsSchematic:
case InputMode.GDS:
lvs_log_path = os.path.join(args.output_dir_path, f"{args.effective_cell_name}_lvs.log")
lvsdb_path = os.path.join(args.output_dir_path, f"{args.effective_cell_name}.lvsdb.gz")
lvsdb_cache_path = os.path.join(args.cache_dir_path, args.pdk,
os.path.splitroot(os.path.abspath(args.gds_path))[-1],
f"{args.effective_cell_name}.lvsdb.gz")

lvs_needed = True

if os.path.exists(lvsdb_path) and args.cache_lvs:
if self.modification_date(lvsdb_path) > self.modification_date(args.gds_path):
warning(f"Reusing cached LVSDB")
subproc(lvsdb_path)
if args.cache_lvs:
if not os.path.exists(lvsdb_cache_path):
info(f"Cache miss: extracted LVSDB does not exist")
subproc(lvsdb_cache_path)
elif self.modification_date(lvsdb_cache_path) <= self.modification_date(args.gds_path):
info(f"Cache miss: extracted LVSDB is older than the input GDS")
subproc(lvsdb_cache_path)
else:
warning(f"Cache hit: Reusing cached LVSDB")
subproc(lvsdb_cache_path)
lvs_needed = False

if lvs_needed:
Expand All @@ -700,6 +714,12 @@ def create_lvsdb(self, args: argparse.Namespace) -> kdb.LayoutVsSchematic:
schematic_path=args.effective_schematic_path,
log_path=lvs_log_path,
lvsdb_path=lvsdb_path)
if args.cache_lvs:
cache_dir_path = os.path.dirname(lvsdb_cache_path)
if not os.path.exists(cache_dir_path):
os.makedirs(cache_dir_path, exist_ok=True)
shutil.copy(lvsdb_path, lvsdb_cache_path)

lvsdb.read(lvsdb_path)
return lvsdb

Expand Down

0 comments on commit 96b0f09

Please sign in to comment.