import json


def load_exp_config(flags):
  """Load experiment config from JSON, and override tf.FLAGS."""
  exp_config = None

  if flags.experiment_def:
    with open(flags.experiment_def) as config_file:
      exp_config = json.load(config_file)

    # Override flags from file
    if 'experiment-options' in exp_config:
      for key, value in exp_config['experiment-options'].items():
        if not key.endswith('_sweep'):  # Don't override sweep parameters
          flags[key].value = value

  return exp_config