Skip to content
Snippets Groups Projects
Commit 7c6127d1 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

Merge branch 'feat/non-reproducible-params' into 'master'

Require --not-reproducible for selected notebook parameters

See merge request !1116
parents 90db1d36 24085c44
No related branches found
No related tags found
1 merge request!1116Require --not-reproducible for selected notebook parameters
...@@ -1631,6 +1631,7 @@ ...@@ -1631,6 +1631,7 @@
} }
], ],
"metadata": { "metadata": {
"euxfel_not_reproducible_params": ["slopes_ff_from_path"],
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3",
"language": "python", "language": "python",
......
...@@ -411,32 +411,6 @@ def parse_argv_and_load_nb(argv) -> Tuple[Dict, NBDetails]: ...@@ -411,32 +411,6 @@ def parse_argv_and_load_nb(argv) -> Tuple[Dict, NBDetails]:
print("Not one of the known calibrations or detectors") print("Not one of the known calibrations or detectors")
sys.exit(1) sys.exit(1)
# Pick out any arguments that may prevent reproducibility from
# working, sorted alphabetically and converted back to their
# canonical representation.
not_reproducible_args = sorted(
('--' + x.replace('_', '-')
for x in ['skip_env_freeze']
if getattr(args, x))
)
# If any of these arguments are set, present a warning.
if not_reproducible_args:
print('WARNING: One or more command line arguments ({}) may prevent '
'this specific correction result from being reproducible based '
'on its metadata. It may not be possible to restore identical '
'output data files when they have been deleted or lost. Please '
'ensure that the data retention policy of the chosen storage '
'location is sufficient for your '
'needs.'.format(', '.join(not_reproducible_args)))
if not args.not_reproducible:
# If not explicitly specified that reproducibility may be
# broken, remind the user and exit.
print('To proceed, you can explicitly allow reproducibility to '
'be broken by adding --not-reproducible')
sys.exit(1)
if nb_info["notebook"]: if nb_info["notebook"]:
notebook = os.path.join(PKG_DIR, nb_info["notebook"]) notebook = os.path.join(PKG_DIR, nb_info["notebook"])
else: else:
...@@ -469,6 +443,7 @@ def parse_argv_and_load_nb(argv) -> Tuple[Dict, NBDetails]: ...@@ -469,6 +443,7 @@ def parse_argv_and_load_nb(argv) -> Tuple[Dict, NBDetails]:
extend_params(nb, ext_func, argv) extend_params(nb, ext_func, argv)
default_params = extract_parameters(nb, lang='python') default_params = extract_parameters(nb, lang='python')
default_values = {p.name: p.value for p in default_params}
parser = make_initial_parser() parser = make_initial_parser()
parser.description = make_epilog(nb) parser.description = make_epilog(nb)
...@@ -476,6 +451,35 @@ def parse_argv_and_load_nb(argv) -> Tuple[Dict, NBDetails]: ...@@ -476,6 +451,35 @@ def parse_argv_and_load_nb(argv) -> Tuple[Dict, NBDetails]:
arg_dict = deconsolize_args(vars(parser.parse_args(argv[1:]))) arg_dict = deconsolize_args(vars(parser.parse_args(argv[1:])))
# Pick out any arguments that may prevent reproducibility from
# working
not_reproducible_args = [
x for x in ['skip_env_freeze']
if getattr(args, x)
] + [
p for p in nb.metadata.get("euxfel_not_reproducible_params", [])
if p in arg_dict and arg_dict[p] != default_values[p]
]
# If any of these arguments are set, present a warning.
if not_reproducible_args:
fmted = ', '.join(sorted('--' + x.replace('_', '-')
for x in not_reproducible_args))
print(f'WARNING: One or more command line arguments ({fmted}) may prevent '
'this specific correction result from being reproducible based '
'on its metadata. It may not be possible to restore identical '
'output data files when they have been deleted or lost. Please '
'ensure that the data retention policy of the chosen storage '
'location is sufficient for your '
'needs.')
if not args.not_reproducible:
# If not explicitly specified that reproducibility may be
# broken, remind the user and exit.
print('To proceed, you can explicitly allow reproducibility to '
'be broken by adding --not-reproducible')
sys.exit(1)
user_venv = nb_info.get("user", {}).get("venv") user_venv = nb_info.get("user", {}).get("venv")
if user_venv is not None: if user_venv is not None:
user_venv = Path(user_venv.format(**arg_dict)) user_venv = Path(user_venv.format(**arg_dict))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment