Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make dumping history opt-out by default #709

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions doc/Hammer-Use/Hammer-Config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ Key History
-----------

With the ``ruamel.yaml`` package, Hammer can emit what files have modified any configuration keys in YAML format.
Turning on key history is accomplished with the ``--dump-history`` command-line flag.
The file is named ``{action}-output-history.yml`` and is located in the output folder of the given action.

Example with the file ``test-config.yml``:
Expand All @@ -254,7 +255,7 @@ Example with the file ``test-config.yml``:

synthesis_tool: "hammer.synthesis.nop"

``test/syn-rundir/syn-output-history.yml`` after executing the command ``hammer-vlsi -p test-config.yml --obj_dir test syn``:
``test/syn-rundir/syn-output-history.yml`` after executing the command ``hammer-vlsi --dump-history -p test-config.yml --obj_dir test syn``:

.. code-block:: yaml

Expand Down Expand Up @@ -294,7 +295,7 @@ Example with the files ``test-config.yml`` and ``test-config2.yml``, respectivel

foo.subst: "hammer.technology.nop2"

``test/syn-rundir/par-output-history.yml`` after executing the command ``hammer-vlsi -p test-config.yml -p test-config2.yml --obj_dir test syn-par``:
``test/syn-rundir/par-output-history.yml`` after executing the command ``hammer-vlsi --dump-history -p test-config.yml -p test-config2.yml --obj_dir test syn-par``:

.. code-block:: yaml

Expand Down
44 changes: 28 additions & 16 deletions hammer/vlsi/cli_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.syn_tool.run_dir, "syn-output.json"), output)
dump_config_to_json_file(os.path.join(driver.syn_tool.run_dir, "syn-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.syn_tool.run_dir, "syn-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.syn_tool.run_dir, "syn-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "par":
if not driver.load_par_tool(get_or_else(self.par_rundir, "")):
Expand All @@ -618,8 +619,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.par_tool.run_dir, "par-output.json"), output)
dump_config_to_json_file(os.path.join(driver.par_tool.run_dir, "par-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.par_tool.run_dir, "par-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.par_tool.run_dir, "par-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "drc":
if not driver.load_drc_tool(get_or_else(self.drc_rundir, "")):
Expand All @@ -637,8 +639,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.drc_tool.run_dir, "drc-output.json"), output)
dump_config_to_json_file(os.path.join(driver.drc_tool.run_dir, "drc-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.drc_tool.run_dir, "drc-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.drc_tool.run_dir, "drc-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "lvs":
if not driver.load_lvs_tool(get_or_else(self.lvs_rundir, "")):
Expand All @@ -656,8 +659,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.lvs_tool.run_dir, "lvs-output.json"), output)
dump_config_to_json_file(os.path.join(driver.lvs_tool.run_dir, "lvs-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.lvs_tool.run_dir, "lvs-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.lvs_tool.run_dir, "lvs-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "sram_generator":
if not driver.load_sram_generator_tool(get_or_else(self.sram_generator_rundir, "")):
Expand Down Expand Up @@ -689,8 +693,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.sim_tool.run_dir, "sim-output.json"), output)
dump_config_to_json_file(os.path.join(driver.sim_tool.run_dir, "sim-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.sim_tool.run_dir, "sim-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.sim_tool.run_dir, "sim-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "power":
if not driver.load_power_tool(get_or_else(self.power_rundir, "")):
Expand All @@ -705,8 +710,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.power_tool.run_dir, "power-output.json"), output)
dump_config_to_json_file(os.path.join(driver.power_tool.run_dir, "power-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.power_tool.run_dir, "power-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.power_tool.run_dir, "power-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "formal":
if not driver.load_formal_tool(get_or_else(self.formal_rundir, "")):
Expand All @@ -724,8 +730,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.formal_tool.run_dir, "formal-output.json"), output)
dump_config_to_json_file(os.path.join(driver.formal_tool.run_dir, "formal-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.formal_tool.run_dir, "formal-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.formal_tool.run_dir, "formal-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
elif action_type == "timing":
if not driver.load_timing_tool(get_or_else(self.timing_rundir, "")):
Expand Down Expand Up @@ -760,8 +767,9 @@ def action(driver: HammerDriver, append_error_func: Callable[[str], None]) -> Op
dump_config_to_json_file(os.path.join(driver.pcb_tool.run_dir, "pcb-output.json"), output)
dump_config_to_json_file(os.path.join(driver.pcb_tool.run_dir, "pcb-output-full.json"),
self.get_full_config(driver, output))
dump_config_to_yaml_file(os.path.join(driver.pcb_tool.run_dir, "pcb-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
if driver.dump_history:
dump_config_to_yaml_file(os.path.join(driver.pcb_tool.run_dir, "pcb-output-history.yml"),
add_key_history(self.get_full_config(driver, output), key_history))
post_run_func_checked(driver)
else:
raise ValueError("Invalid action_type = " + str(action_type))
Expand Down Expand Up @@ -1573,6 +1581,8 @@ def auto_action(driver: HammerDriver, append_error_func: Callable[[str], None])

self.hierarchical_auto_action = auto_action

driver.dump_history = args["dump_history"]

return driver, errors

@staticmethod
Expand Down Expand Up @@ -1695,6 +1705,8 @@ def main(self, args: Optional[List[str]] = None) -> None:
help='Top module. If not specified, hammer-vlsi will take it from synthesis.inputs.top_module.')
parser.add_argument("--cad-files", action='append', required=False,
help="CAD files.")
parser.add_argument("--dump-history", default=False, action=argparse.BooleanOptionalAction,
help='Option to dump the key history of all the project configurations.')

try:
output = subprocess.check_output(["hammer-shell-test"]).decode().strip()
Expand Down
8 changes: 4 additions & 4 deletions hammer/vlsi/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ def empty() -> "Margins":

def to_dict(self) -> dict:
return {
"left": self.left,
"bottom": self.bottom,
"right": self.right,
"top": self.top
"left": str(self.left),
"bottom": str(self.bottom),
"right": str(self.right),
"top": str(self.top)
}


Expand Down
10 changes: 10 additions & 0 deletions hammer/vlsi/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ def __init__(self, options: HammerDriverOptions, extra_project_config: dict = {}
self.post_custom_timing_tool_hooks = [] # type: List[HammerToolHookAction]
self.post_custom_pcb_tool_hooks = [] # type: List[HammerToolHookAction]

self._dump_history = False

@property
def project_config(self) -> dict:
return hammer_config.combine_configs(self.project_configs)
Expand Down Expand Up @@ -1804,3 +1806,11 @@ def visit_module(mod: str) -> None:
output.append((module, constraint_dict))

return (output, dependency_graph)

@property
def dump_history(self) -> bool:
return self._dump_history

@dump_history.setter
def dump_history(self, new_dump_history: bool) -> None:
self._dump_history = new_dump_history
15 changes: 13 additions & 2 deletions tests/test_cli_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,17 @@ def test_key_history(self, tmp_path) -> None:

set_up_run(tmp_path)
history_path = os.path.join(syn_rundir(tmp_path), "syn-output-history.yml")
run_syn_to_par_with_output(tmp_path)
with pytest.raises(SystemExit) as cm:
CLIDriver().main(args=[
"syn", # action
"-p", config_path(tmp_path),
"--output", syn_out_path(tmp_path),
"--syn_rundir", syn_rundir(tmp_path),
"--obj_dir", obj_dir_path(tmp_path),
"--log", log_path(tmp_path),
"--dump-history"
])
assert cm.value.code == 0

# History file should have comments
with open(config_path(tmp_path), 'r') as f:
Expand All @@ -484,7 +494,8 @@ def test_key_history_as_input(self, tmp_path) -> None:
"--output", syn_out_path(tmp_path),
"--syn_rundir", syn_rundir(tmp_path),
"--obj_dir", obj_dir_path(tmp_path),
"--log", log_path(tmp_path)
"--log", log_path(tmp_path),
"--dump-history"
])
assert cm.value.code == 0

Expand Down