Skip to content

Commit

Permalink
Add --hashes and --print-params debug flags
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmCyan committed Nov 16, 2023
1 parent 2356a57 commit f83d09e
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
paths and short-circuiting directly based on that path's existence (as opposed
to the `FileReferenceCacher` which saves a file containing the path), rather
than handling saving/loading itself.
* `--hashes` debugging flag, when specified it prints out the hash and name of
each parameter set passed into an experiment and then exits.
* `--print-params` debugging flag, when specified it prints out the full string
representation of each parameter set passed into an experiment, or, if at
least the first few characters of a hash are specified, it prints out the
corresponding parameter set hash from the `params_registry.json`. Note that
both this and the `--hashes` flag are temporary debugging tools until the CLI
gets broken out into subcommands, where they may become part of a separate
command.

### Fixed
* `--notebook` manager's not using modified experiment cache paths.
Expand Down
18 changes: 18 additions & 0 deletions curifactory/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def cmd_run(args):
ignore_lazy=args.ignore_lazy,
no_dag=args.no_dag,
map_only=args.map_only,
hashes_only=args.hashes_only,
print_params=args.print_params,
no_color=args.no_color,
quiet=args.quiet,
progress=args.progress,
Expand Down Expand Up @@ -397,6 +399,22 @@ def main():
action="store_true",
help="Specifying this _only_ runs the pre-execution record and stage mapping for the experiment, and prints out the resulting DAG information before immediately exiting. Specifying this implies --dry. You can use this flag to check which artifacts are found in cache.",
)
# TODO: (11/16/2023) this will need to be its own "hashes" command once we
# split out CLI subparsers
display_group.add_argument(
"--hashes",
dest="hashes_only",
action="store_true",
help="Specifying this _only_ runs the parameter set collection and prints the resulting parameter set hashes. Specifying this implies --dry. You can use this flag to check expected file paths.",
)
display_group.add_argument(
"--print-params",
nargs="?",
dest="print_params",
const=True,
default=False,
help="Specifying this _only_ runs the parameter set collection and prints the resulting parameter sets hashes. Specifying this implies --dry. You can use this flag to debug output parameter sets. If you provide an argument to this flag (either a parameter set name, or a parameter set hash) it will output only that parameter set. (A hash will search the parameter registry.)",
)
display_group.add_argument(
"--quiet",
dest="quiet",
Expand Down
66 changes: 65 additions & 1 deletion curifactory/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import re
import sys
from typing import Union

from curifactory import utils
from curifactory.manager import ArtifactManager
Expand Down Expand Up @@ -49,6 +50,8 @@ def run_experiment( # noqa: C901 -- TODO: this does need to be broken up at som
ignore_lazy: bool = False,
no_dag: bool = False,
map_only: bool = False,
hashes_only: bool = False,
print_params: Union[bool, str] = False,
no_color: bool = False,
quiet: bool = False,
progress: bool = False,
Expand Down Expand Up @@ -121,6 +124,10 @@ def run_experiment( # noqa: C901 -- TODO: this does need to be broken up at som
Mapping is done by running the experiment but skipping all stage execution.
map_only (bool): Runs the pre-execution mapping of an experiment and immediately exits, printing the
map to stdout. **Note that setting this to True automatically sets dry.**
hashes_only (bool): Runs only the parameter set collection from parameter files and then prints out
the corresponding hashes to stdout. **Note that setting this to True automatically sets dry.**
print_params (Union[bool, str]): Runs only the parameter set collection from parameter files and then prints out
the corresponding parameters to stdout. **Note that setting this to True automatically sets dry.**
no_color (bool): Suppress fancy colors in console output.
quiet (bool): Suppress all console log output.
progress (bool): Display fancy rich progress bars for each record.
Expand All @@ -144,6 +151,7 @@ def run_experiment( # noqa: C901 -- TODO: this does need to be broken up at som

# doing imports here to avoid needing such a long import list for tab completion functionality
import glob
import json
import shutil
import traceback

Expand All @@ -153,9 +161,13 @@ def run_experiment( # noqa: C901 -- TODO: this does need to be broken up at som

# if we request a map only run, make sure we don't impact any files, so
# automatically set "dry"
if map_only:
if map_only or hashes_only or print_params:
dry = True

# for certain debug commands, don't print logs to stdout
if hashes_only or print_params:
quiet = True

if run_string is None:
run_string = f"experiment {experiment_name}"
for param_file in param_files:
Expand Down Expand Up @@ -196,6 +208,10 @@ def run_experiment( # noqa: C901 -- TODO: this does need to be broken up at som
run_string += " --no-dag"
if map_only:
run_string += " --map"
if hashes_only:
run_string += " --hashes"
if print_params:
run_string += " --print-params"
if no_color:
run_string += " --no-color"
if quiet:
Expand Down Expand Up @@ -386,6 +402,54 @@ def run_experiment( # noqa: C901 -- TODO: this does need to be broken up at som
store_full,
parallel_mode,
)
# exit early if debugging flags
if hashes_only:
hashes = {}
for param_set in final_param_sets:
hashes[param_set.hash] = param_set.name
print(param_set.hash, param_set.name)
return hashes, mngr

if print_params:

def display_parameters(param_set):
print(param_set.hash, param_set.name)
print(
json.dumps(
hashing.param_set_string_hash_representations(param_set), indent=4
)
)

if type(print_params) == str:
# check names in final_param_sets
found = False
for param_set in final_param_sets:
if param_set.name == print_params:
display_parameters(param_set)
found = True
break
# if not found search params registry
if not found:
registry_path = os.path.join(
mngr.manager_cache_path, "params_registry.json"
)

if os.path.exists(registry_path):
with open(registry_path) as infile:
registry = json.load(infile)
for param_hash in registry:
if param_hash.startswith(print_params):
param_set = registry[param_hash]
print(param_hash, param_set["name"])
print(json.dumps(param_set, indent=4))
found = True
break
if not found:
print(f"ERROR: parameter set name or hash '{print_params}' not found")
else:
for param_set in final_param_sets:
display_parameters(param_set)
return final_param_sets, mngr

# check that there wasn't an invalid name and all requested parameterset names were found
if param_set_names is not None:
Expand Down

0 comments on commit f83d09e

Please sign in to comment.