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

Profile Sampler #342

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
f0f3c84
Create profile sampler (minimize as template)
ggalloni Nov 22, 2023
aaf7b90
Add parameters to yaml
ggalloni Nov 27, 2023
f52f9dd
Treat profile as minimize in run functions
ggalloni Nov 27, 2023
a1951e1
docs profile
ggalloni Nov 27, 2023
ef9e6be
Modify initialize to generate initial points for each profiled point
ggalloni Nov 27, 2023
b50ee92
Modify run to loop over profiled points and store results
ggalloni Nov 27, 2023
3d0a3e7
Modify process_results to keep previous points
ggalloni Nov 27, 2023
414e8c3
Modify products to give complete set of results
ggalloni Nov 27, 2023
d7c4082
Add test of profile on Gaussian likelihood
ggalloni Nov 27, 2023
4582211
Trigger travis
ggalloni Nov 27, 2023
326d949
Trigger travis
ggalloni Nov 27, 2023
0b44de9
Remove if in travis (just to trigger)
ggalloni Nov 28, 2023
04b88a1
flake and bug fix
ggalloni Nov 28, 2023
92a7a65
bug fix
ggalloni Nov 28, 2023
55fe202
bug fix
ggalloni Nov 28, 2023
37e743e
Pass to mpi
ggalloni Nov 28, 2023
a083f50
Bug fix and flake
ggalloni Nov 28, 2023
5115771
Change naming
ggalloni Nov 28, 2023
98792bf
debug
ggalloni Nov 28, 2023
8c4e5a5
revert changes
ggalloni Nov 28, 2023
eda2009
treat profiler as minimizer in sampler
ggalloni Nov 28, 2023
3b84f2f
avoid preparing collection
ggalloni Nov 28, 2023
81400c7
fix filename
ggalloni Nov 28, 2023
94e26d0
bug fix
ggalloni Nov 28, 2023
99e0769
test
ggalloni Nov 28, 2023
4f644a3
Moved save to file
ggalloni Nov 28, 2023
eb4a7ee
ops
ggalloni Nov 28, 2023
8b799b8
Restore test on output
ggalloni Nov 28, 2023
9006311
Save results to file separately
ggalloni Nov 28, 2023
89d0624
ops
ggalloni Nov 28, 2023
4866845
Test
ggalloni Nov 28, 2023
9583e91
Custom dump_txt
ggalloni Nov 29, 2023
24383a5
Recover filename
ggalloni Nov 29, 2023
0720301
Avoid output with Dummy Output
ggalloni Nov 29, 2023
ed80d65
Test mpi
ggalloni Nov 29, 2023
ea0cd29
Restrict to main_process
ggalloni Nov 29, 2023
bd2edab
test mpi
ggalloni Nov 29, 2023
276fe31
test
ggalloni Nov 29, 2023
1813c6c
main_process in test
ggalloni Nov 29, 2023
7775379
move save
ggalloni Nov 29, 2023
5c2cae2
Avoid output in test
ggalloni Nov 29, 2023
1b4c3b5
Try to revert moving save
ggalloni Nov 29, 2023
25bac62
Pass through MPI
ggalloni Nov 29, 2023
fe7ae9b
Add TODO
ggalloni Nov 29, 2023
757f5e3
Revert travis change
ggalloni Nov 29, 2023
68b8ad9
docs
ggalloni Nov 30, 2023
47b828c
Merge branch 'master' into profile_sampler
ggalloni Nov 30, 2023
6b090f8
First test to make Profiler inherit from Minimizer
ggalloni Feb 7, 2024
2d6e078
Clean code and avoid iminuit in test_profile
ggalloni Feb 7, 2024
c6119de
Fully inherit from Minimize
ggalloni Feb 27, 2024
6621c4c
Merge branch 'profile_sampler' of https://github.com/ggalloni/cobaya …
ggalloni Feb 27, 2024
6bebe0a
flake + bug fix
ggalloni Feb 27, 2024
eb25042
docs
ggalloni Feb 27, 2024
d81c501
Merge branch 'master' into profile_sampler
ggalloni Feb 27, 2024
84bc19d
Merge branch 'master' into profile_sampler
cmbant Aug 9, 2024
9893f9b
Missing parenthesis
ggalloni Aug 11, 2024
b821861
Merge branch 'master' into profile_sampler
ggalloni Aug 14, 2024
27e1e4e
Test remove MPI safeguard for Minuit
ggalloni Aug 16, 2024
0379353
Merge branch 'master' into profile_sampler
ggalloni Aug 16, 2024
8a313a8
Clean
ggalloni Aug 16, 2024
5fc20e2
Merge branch 'master' into profile_sampler
ggalloni Sep 6, 2024
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
12 changes: 11 additions & 1 deletion cobaya/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def run(info_or_yaml_or_file: Union[InputDict, str, os.PathLike],
stop_at_error: Optional[bool] = None,
resume: Optional[bool] = None, force: Optional[bool] = None,
minimize: Optional[bool] = None,
profile: Optional[bool] = None,
no_mpi: bool = False, test: Optional[bool] = None,
override: Optional[InputDict] = None,
allow_changes: bool = False
Expand All @@ -48,6 +49,7 @@ def run(info_or_yaml_or_file: Union[InputDict, str, os.PathLike],
:param resume: continue an existing run
:param force: overwrite existing output if it exists
:param minimize: if true, ignores the sampler and runs default minimizer
:param profile: if true, ignores the sampler and runs the profiler
:param no_mpi: run without MPI
:param test: only test initialization rather than actually running
:param override: option dictionary to merge into the input one, overriding settings
Expand All @@ -64,7 +66,7 @@ def run(info_or_yaml_or_file: Union[InputDict, str, os.PathLike],
with mpi.ProcessState("run"):
flags = {packages_path_input: packages_path, "debug": debug,
"stop_at_error": stop_at_error, "resume": resume, "force": force,
"minimize": minimize, "test": test}
"minimize": minimize, "profile": profile, "test": test}
info: InputDict = load_info_overrides(
info_or_yaml_or_file, override or {}, **flags)
logger_setup(info.get("debug"))
Expand All @@ -76,6 +78,11 @@ def run(info_or_yaml_or_file: Union[InputDict, str, os.PathLike],
if which_sampler.lower() != "minimize":
info["sampler"] = {"minimize": None}
which_sampler = "minimize"
if info.get("profile"): # type: ignore
# Preserve options if "profile" was already the sampler
if which_sampler.lower() != "profile":
info["sampler"] = {"profile": None}
which_sampler = "profile"
except (KeyError, TypeError) as excpt:
if not info.get("post"):
raise LoggedError(
Expand Down Expand Up @@ -180,6 +187,9 @@ def run_script(args=None):
help=("Replaces the sampler in the input and runs a minimization "
"process (incompatible with post-processing)."),
**trueNone_kwargs)
parser.add_argument("-P", "--profile",
help=("Replaces the sampler in the input and runs a profiling "
"process (incompatible with post-processing).")),
parser.add_argument("--allow-changes",
help="Allow changing input parameters when resuming "
"or minimizing, skipping consistency checks",
Expand Down
2 changes: 1 addition & 1 deletion cobaya/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def check_sampler_info(info_old: Optional[SamplersDict],
# info_new.update({"minimize": aux})
# info_old = {}
# keep_old = {}
if list(info_old) != list(info_new) and list(info_new) == ["minimize"]:
if list(info_old) != list(info_new) and (list(info_new) == ["minimize"] or list(info_new) == ["profile"]):
return
if list(info_old) == list(info_new):
# Restore some selected old values for some classes
Expand Down
2 changes: 0 additions & 2 deletions cobaya/samplers/minimize/minimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ def minuslogp_transf(x):
result = iminuit.minimize(**self.kwargs, method="migrad")
if not (success := result.success):
self.log.error(result.message)
if mpi.get_mpi_size() > 1:
result.pop("minuit") # problem with pickle/mpi?
else:
self.kwargs = {
"fun": minuslogp_transf,
Expand Down
1 change: 1 addition & 0 deletions cobaya/samplers/profile/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .profile import Profile
85 changes: 85 additions & 0 deletions cobaya/samplers/profile/profile.bibtex
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
### If using Py-BOBYQA ###

@ARTICLE{BOBYQA,
author = {J. D. Powell, M},
year = {2009},
month = {01},
pages = {},
title = {The BOBYQA Algorithm for Bound Constrained Optimization without Derivatives},
journal = {Technical Report, Department of Applied Mathematics and Theoretical Physics}
}

@ARTICLE{2018arXiv180400154C,
author = {{Cartis}, Coralia and {Fiala}, Jan and {Marteau}, Benjamin and {Roberts}, Lindon},
title = "{Improving the Flexibility and Robustness of Model-Based Derivative-Free Optimization Solvers}",
journal = {arXiv e-prints},
keywords = {Mathematics - Optimization and Control},
year = "2018",
month = "Mar",
eid = {arXiv:1804.00154},
pages = {arXiv:1804.00154},
archivePrefix = {arXiv},
eprint = {1804.00154},
primaryClass = {math.OC},
adsurl = {https://ui.adsabs.harvard.edu/abs/2018arXiv180400154C},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}


@ARTICLE{2018arXiv181211343C,
author = {{Cartis}, Coralia and {Roberts}, Lindon and {Sheridan-Methven}, Oliver},
title = "{Escaping local minima with derivative-free methods: a numerical investigation}",
journal = {arXiv e-prints},
keywords = {Mathematics - Optimization and Control},
year = "2018",
month = "Dec",
eid = {arXiv:1812.11343},
pages = {arXiv:1812.11343},
archivePrefix = {arXiv},
eprint = {1812.11343},
primaryClass = {math.OC},
adsurl = {https://ui.adsabs.harvard.edu/abs/2018arXiv181211343C},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}


### If using scipy ###

@ARTICLE{2020SciPy-NMeth,
author = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
Haberland, Matt and Reddy, Tyler and Cournapeau, David and
Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
Kern, Robert and Larson, Eric and Carey, C J and
Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
{VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
Harris, Charles R. and Archibald, Anne M. and
Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
{van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
title = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
Computing in Python}},
journal = {Nature Methods},
year = {2020},
volume = {17},
pages = {261--272},
adsurl = {https://rdcu.be/b08Wh},
doi = {10.1038/s41592-019-0686-2},
}

### If using iMinuit ###

@ARTICLE{1975CoPhC..10..343J,
author = {James, Frederick and Roos, Matts},
title = "{Minuit - a system for function minimization and analysis of the parameter errors and correlations}",
journal = {Computer Physics Communications},
year = 1975,
month = dec,
volume = {10},
number = {6},
pages = {343-367},
doi = {10.1016/0010-4655(75)90039-9},
adsurl = {https://ui.adsabs.harvard.edu/abs/1975CoPhC..10..343J},
}
Loading
Loading