Skip to content

Commit

Permalink
add --initial-state-element-override/-e option
Browse files Browse the repository at this point in the history
  • Loading branch information
donn committed Nov 19, 2024
1 parent 0531281 commit e294b24
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
52 changes: 35 additions & 17 deletions openlane/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
from functools import partial
from typing import Any, Dict, Sequence, Tuple, Type, Optional, List, Union

from click import (
Parameter,
Context,
Path,
pass_context,
)
import click
from cloup import (
option,
option_group,
Expand All @@ -40,7 +35,7 @@


from .__version__ import __version__
from .state import State
from .state import State, DesignFormat
from .logging import (
debug,
err,
Expand All @@ -56,7 +51,7 @@


def run(
ctx: Context,
ctx: click.Context,
flow_name: Optional[str],
pdk_root: Optional[str],
pdk: str,
Expand All @@ -73,6 +68,7 @@ def run(
config_override_strings: List[str],
_force_run_dir: Optional[str],
design_dir: Optional[str],
initial_state_element_override: Sequence[str],
view_save_path: Optional[str] = None,
ef_view_save_path: Optional[str] = None,
):
Expand All @@ -97,6 +93,27 @@ def run(
if flow_description is None:
flow_description = "Classic"

if len(initial_state_element_override):
if with_initial_state is None:
with_initial_state = State()
overrides = {}
for element in initial_state_element_override:
element_split = element.split("=", maxsplit=1)
if len(element_split) < 2:
err(f"Invalid initial state element override: '{element}'.")
ctx.exit(1)
df_id, path = element_split
design_format = DesignFormat.by_id(df_id)
if design_format is None:
err(f"Invalid design format ID: '{df_id}'.")
ctx.exit(1)
overrides[design_format] = common.Path(path)

with_initial_state = with_initial_state.__class__(
with_initial_state,
overrides=overrides,
)

TargetFlow: Type[Flow]

if isinstance(flow_description, str):
Expand Down Expand Up @@ -170,7 +187,7 @@ def run(
flow._save_snapshot_ef(evsp)


def print_version(ctx: Context, param: Parameter, value: bool):
def print_version(ctx: click.Context, param: click.Parameter, value: bool):
if not value:
return

Expand Down Expand Up @@ -198,8 +215,8 @@ def print_version(ctx: Context, param: Parameter, value: bool):


def print_bare_version(
ctx: Context,
param: Parameter,
ctx: click.Context,
param: click.Parameter,
value: bool,
):
if not value:
Expand All @@ -209,7 +226,7 @@ def print_bare_version(


def run_included_example(
ctx: Context,
ctx: click.Context,
smoke_test: bool,
example: Optional[str],
**kwargs,
Expand Down Expand Up @@ -285,8 +302,8 @@ def run_included_example(


def cli_in_container(
ctx: Context,
param: Parameter,
ctx: click.Context,
param: click.Parameter,
value: bool,
):
if not value:
Expand Down Expand Up @@ -331,14 +348,14 @@ def cli_in_container(
o(
"--save-views-to",
"view_save_path",
type=Path(file_okay=False, dir_okay=True),
type=click.Path(file_okay=False, dir_okay=True),
default=None,
help="A directory to copy the final views to, where each format is saved under a directory named after the corner ID (much like the 'final' directory after running a flow.)",
),
o(
"--ef-save-views-to",
"ef_view_save_path",
type=Path(file_okay=False, dir_okay=True),
type=click.Path(file_okay=False, dir_okay=True),
default=None,
help="A directory to copy the final views to in the Efabless format, compatible with Caravel User Project.",
),
Expand Down Expand Up @@ -401,8 +418,9 @@ def cli_in_container(
_enable_debug_flags=True,
sequential_flow_reproducible=True,
enable_overwrite_flag=True,
enable_initial_state_element=True,
)
@pass_context
@click.pass_context
def cli(ctx, /, **kwargs):
"""
Runs an OpenLane flow via the commandline using a design configuration
Expand Down
12 changes: 11 additions & 1 deletion openlane/flows/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def cloup_flow_opts(
volare_pdk_override: Optional[str] = None,
_enable_debug_flags: bool = False,
enable_overwrite_flag: bool = False,
enable_initial_state_element: bool = False,
) -> Decorator:
"""
Creates a wrapper that appends a number of OpenLane flow-related flags to a
Expand Down Expand Up @@ -214,7 +215,7 @@ def decorate(f):
),
default=None,
callback=initial_state_cb,
help="Use this JSON file as an initial state. If this is not specified, the latest `state_out.json` of the run directory will be used if available.",
help="Use this JSON file as an initial state. If this is not specified, the latest `state_out.json` of the run directory will be used. If none exist, an empty initial state is created.",
)(f)
f = o(
"--design-dir",
Expand Down Expand Up @@ -381,6 +382,15 @@ def decorate(f):
callback=set_worker_count_cb,
expose_value=False,
)(f)
if enable_initial_state_element:
f = o(
"-e",
"--initial-state-element-override",
type=str,
multiple=True,
default=(),
help="Elements to override in the used initial state in the format DESIGN_FORMAT_ID=PATH",
)(f)
if accept_config_files:
f = argument(
"config_files",
Expand Down

0 comments on commit e294b24

Please sign in to comment.