Skip to content

Commit

Permalink
Merge 5bd4f01 into ca5e0d7
Browse files Browse the repository at this point in the history
  • Loading branch information
yk committed Feb 10, 2016
2 parents ca5e0d7 + 5bd4f01 commit c5d2c0d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
9 changes: 9 additions & 0 deletions sacred/commandline_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,12 @@ class UnobservedOption(CommandLineOption):
def apply(cls, args, run):
"""Set this run to unobserved mode."""
run.unobserved = True


class DisableSuspiciousChangesWarningsOption(CommandLineOption):
"""Disable warnings about suspicious changes for this run."""

@classmethod
def apply(cls, args, run):
"""Set this run to not warn about suspicous changes."""
run.disable_suspicious_changes_warnings = True
7 changes: 5 additions & 2 deletions sacred/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import OrderedDict

from sacred.arg_parser import get_config_updates, parse_args
from sacred.commandline_options import gather_command_line_options
from sacred.commandline_options import gather_command_line_options, DisableSuspiciousChangesWarningsOption
from sacred.commands import print_config, print_dependencies
from sacred.ingredient import Ingredient
from sacred.utils import print_filtered_stacktrace
Expand Down Expand Up @@ -125,8 +125,11 @@ def run_command(self, command_name, config_updates=None,
:returns: the Run object corresponding to the finished run
:rtype: sacred.run.Run
"""
disable_suspicious_changes_warnings_flag = '--' + DisableSuspiciousChangesWarningsOption.get_flag()[1]
disable_suspicious_changes_warnings = args[disable_suspicious_changes_warnings_flag] if disable_suspicious_changes_warnings_flag in args else False

run = self._create_run_for_command(command_name, config_updates,
named_configs)
named_configs, disable_suspicious_changes_warnings=disable_suspicious_changes_warnings)
self.current_run = run

for option in gather_command_line_options():
Expand Down
4 changes: 2 additions & 2 deletions sacred/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def traverse_ingredients(self):
# ======================== Private Helpers ================================

def _create_run_for_command(self, command_name, config_updates=None,
named_configs=()):
named_configs=(), disable_suspicious_changes_warnings=False):
run = create_run(self, command_name, config_updates,
named_configs=named_configs)
named_configs=named_configs, disable_suspicious_changes_warnings=disable_suspicious_changes_warnings)
return run
7 changes: 5 additions & 2 deletions sacred/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ def finalize_initialization(self, run):
cfunc.rnd = create_rnd(seed)
cfunc.run = run

self._warn_about_suspicious_changes()
if not run.disable_suspicious_changes_warnings:
self._warn_about_suspicious_changes()

def _warn_about_suspicious_changes(self):
for add in sorted(self.config_mods.added):
Expand Down Expand Up @@ -281,7 +282,7 @@ def get_command(scaffolding, command_path):


def create_run(experiment, command_name, config_updates=None,
named_configs=()):
named_configs=(), disable_suspicious_changes_warnings=False):

sorted_ingredients = gather_ingredients_topological(experiment)
scaffolding = create_scaffolding(experiment, sorted_ingredients)
Expand Down Expand Up @@ -326,6 +327,8 @@ def create_run(experiment, command_name, config_updates=None,
if hasattr(main_function, 'unobserved'):
run.unobserved = main_function.unobserved

run.disable_suspicious_changes_warnings = disable_suspicious_changes_warnings

for scaffold in scaffolding.values():
scaffold.finalize_initialization(run=run)

Expand Down
3 changes: 3 additions & 0 deletions sacred/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def __init__(self, config, config_modifications, main_function, observers,
self.unobserved = False
"""Indicates whether this run should be unobserved"""

self.disable_suspicious_changes_warnings = False
"""Indicates whether warnings about suspicious changes should be disabled"""

self._heartbeat = None
self._failed_observers = []

Expand Down
1 change: 1 addition & 0 deletions tests/test_arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
('--mongo_db=bar', {'--mongo_db': 'bar'}),
('-l 10', {'--loglevel': '10'}),
('--loglevel=30', {'--loglevel': '30'}),
('--disable_suspicious_changes_warnings', {'--disable_suspicious_changes_warnings': True}),
])
def test_parse_individual_arguments(argv, expected):
args = parse_args(['test_prog.py'] + argv.split(), print_help=False)
Expand Down

0 comments on commit c5d2c0d

Please sign in to comment.