Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ultranest sampler (Sourcery refactored) #250

Merged
merged 1 commit into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dddm/samplers/multi_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def save_sub_configs(self, force_index=False):
if 'logging' not in c.config:
raise ValueError(f'{c} does not have logging in config ({list(c.config.keys())})')
save_as = os.path.join(f'{save_dir}', f'{c.config["detector"]}_')
with open(save_as + 'config.json', 'w') as file:
with open(f'{save_as}config.json', 'w') as file:
json.dump(convert_dic_to_savable(c.config), file, indent=4)
np.save(save_as + 'config.npy', convert_dic_to_savable(c.config))
np.save(f'{save_as}config.npy', convert_dic_to_savable(c.config))
Comment on lines -51 to +53
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _CombinedInference.save_sub_configs refactored with the following changes:

shutil.copy(c.config['logging'], save_as +
c.config['logging'].split('/')[-1])
self.log.info('save_sub_configs::\tdone_saving')
Expand Down
2 changes: 1 addition & 1 deletion dddm/samplers/ultranest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UltraNestSampler(MultiNestSampler):
"""

def run(self):
warnings.warn(f'Ultranest sampler is not completely implemented yet')
warnings.warn('Ultranest sampler is not completely implemented yet')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function UltraNestSampler.run refactored with the following changes:

self._fix_parameters()
self._print_before_run()

Expand Down
7 changes: 3 additions & 4 deletions tests/test_samplers/test_ultranest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ def test(self, halo_name='shm', max_sigma_off=5, **kwargs, ):
sampler_kwargs=dict(nlive=100, tol=0.9, verbose=1),
fit_parameters=('log_mass', 'log_cross_section',),
)
config = {**base_config, **kwargs}
config = base_config | kwargs
sampler = self.ct.get_sampler_for_detector(**config)

results, _ = sampler.run()

fails = []
for i, (thing, expected, avg, std) in enumerate(
zip(
for thing, expected, avg, std in zip(
base_config.get('fit_parameters'),
[getattr(sampler, f) for f in base_config.get('fit_parameters')],
results['posterior']['mean'],
results['posterior']['stdev']
)):
):
Comment on lines -23 to +34
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PymultinestTest.test refactored with the following changes:

nsigma_off = np.abs(expected - avg) / std
# assert False, dict(thing=thing, expected=expected, avg=avg, nsigma_off=nsigma_off)
message = (f'For {thing}: expected {expected:.2f} yielded '
Expand Down