Skip to content

Commit

Permalink
bug fix for IS, cosmo_arguments not ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Audren committed Nov 25, 2014
1 parent f947014 commit e92eeb9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
36 changes: 18 additions & 18 deletions montepython/importance_sampling.py
Expand Up @@ -77,26 +77,26 @@ def run(cosmo, data, command_line):
new_experiments = recover_new_experiments(
data, command_line, starting_folder)
if not new_experiments:
# it means that some experiments that were used before are no longer
# used. In this case, one should recompute all the likelihoods.
new_experiments = data.experiments
raise io_mp.ConfigurationError(
"You are using Importance Sampling without adding a new "
"experiment. This is not what this method is coded for.")

# resetting the needed cosmo arguments, and deleting the dictionary of
# likelihoods, only if new_experiments is smaller than the old ones.
ignore_likelihood = True
if set(new_experiments) < set(data.experiments):
data.cosmo_arguments = {}
data.initialise_likelihoods(new_experiments)
ignore_likelihood = False
elif set(new_experiments) == set(data.experiments):
warnings.warn(
"All likelihoods were found to be different than ones from the "
"starting folder, or some were not used any longer. The previous "
"value of the likelihood will be discarded.")
else:
io_mp.ConfigurationError(
"You probably tried to run Importance Sampling with less "
"experiments than what you started with. This is not supported.")
ignore_likelihood = False

# Wipe out the problematic information from previous likelihoods,
# namely their desired output
data.cosmo_arguments['output'] = ''

try:
del data.cosmo_arguments['l_max_scalars']
del data.cosmo_arguments['lensing']
except KeyError:
pass

# Initialise the requirements of the new likelihood
data.initialise_likelihoods(new_experiments)

# Multiprocessing part, to analyze all the chains in parallel. When not
# specifying any 'processes' keyword argument to the Pool call, the system
Expand Down Expand Up @@ -134,7 +134,7 @@ def recover_new_experiments(data, command_line, starting_folder):
if line.find('data.experiments') != -1:
_, experiments = line.split('=')
experiments = experiments.strip()
print 'The likelihood will be computed for:'
print 'The likelihood will be computed only for:'
new_experiments = [
elem for elem in data.experiments if elem not in experiments]
print ' ->',
Expand Down
1 change: 1 addition & 0 deletions test.param
Expand Up @@ -26,6 +26,7 @@ data.parameters['other'] = [0.1, -1., 1, 0.01, 1, 'nuisance']
# Derived parameter list
data.parameters['Omega_Lambda'] = [0, -1, -1, 0,1, 'derived']

data.cosmo_arguments['N_eff'] = 3.046

#------ Mcmc parameters ----
# Number of steps taken, by default (overwritten by the -N command)
Expand Down
1 change: 1 addition & 0 deletions test_is.param
Expand Up @@ -26,6 +26,7 @@ data.parameters['other'] = [0.1, -1., 1, 0.01, 1, 'nuisance']
# Derived parameter list
data.parameters['Omega_Lambda'] = [0, -1, -1, 0,1, 'derived']

data.cosmo_arguments['N_eff'] = 3.046

#------ Mcmc parameters ----
# Number of steps taken, by default (overwritten by the -N command)
Expand Down

0 comments on commit e92eeb9

Please sign in to comment.