Skip to content

Commit

Permalink
further nautilus compatibility updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Carnall authored and Adam Carnall committed Mar 27, 2024
1 parent ed86491 commit 61268db
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.rst
Expand Up @@ -10,7 +10,9 @@ Bagpipes can be installed with pip:
pip install bagpipes
Please note you cannot run the code just by cloning the repository as the large grids of models aren't included. To fit models to data with the code you may also install the `MultiNest <https://github.com/JohannesBuchner/MultiNest>`_ code. If MultiNest is not installed, `nautilus <https://github.com/johannesulf/nautilus>`_ will be used for fitting. For more information please see the `bagpipes documentation <http://bagpipes.readthedocs.io>`_.
Please note you cannot run the code just by cloning the repository as the large grids of models aren't included.

The default sampler for fitting models to data is the `MultiNest <https://github.com/JohannesBuchner/MultiNest>`_ code, however this requires separate installation, and this can be challening on some systems. Bagpipes is now also compatible with the pure Python `nautilus <https://github.com/johannesulf/nautilus>`_ nested sampling algorithm, which should be installed by default along with Bagpipes, and will be used for fitting if MultiNest is not installed. Even if you are used to using Bagpipes with Multinest, you may wish to try out Nautlus, as this may yield faster and/or more accurate results in some circumstances. For more information please see the `bagpipes documentation <http://bagpipes.readthedocs.io>`_.

**Published papers and citing the code**

Expand Down
8 changes: 4 additions & 4 deletions bagpipes/catalogue/fit_catalogue.py
Expand Up @@ -129,7 +129,7 @@ def __init__(self, IDs, fit_instructions, load_data, spectrum_exists=True,
utils.make_dirs(run=run)

def fit(self, verbose=False, n_live=400, mpi_serial=False,
track_backlog=False, sampler="multinest"):
track_backlog=False, sampler="multinest", pool=1):
""" Run through the catalogue fitting each object.
Parameters
Expand Down Expand Up @@ -182,7 +182,7 @@ def fit(self, verbose=False, n_live=400, mpi_serial=False,

# If not fit the object and update the output catalogue
self._fit_object(self.IDs[i], verbose=verbose, n_live=n_live,
sampler=sampler)
sampler=sampler, pool=pool)

self.done[i] = True

Expand Down Expand Up @@ -284,7 +284,7 @@ def _set_redshift(self, ID):
self.fit_instructions["redshift"] = self.redshifts[ind]

def _fit_object(self, ID, verbose=False, n_live=400, use_MPI=True,
sampler="multinest"):
sampler="multinest", pool=1):
""" Fit the specified object and update the catalogue. """

# Set the correct redshift for this object
Expand All @@ -308,7 +308,7 @@ def _fit_object(self, ID, verbose=False, n_live=400, use_MPI=True,
n_posterior=self.n_posterior)

self.obj_fit.fit(verbose=verbose, n_live=n_live, use_MPI=use_MPI,
sampler=sampler)
sampler=sampler, pool=pool)

if rank == 0:
if self.vars is None:
Expand Down
10 changes: 6 additions & 4 deletions bagpipes/fitting/fit.py
Expand Up @@ -116,7 +116,7 @@ def __init__(self, galaxy, fit_instructions, run=".", time_calls=False,

def fit(self, verbose=False, n_live=400, use_MPI=True,
sampler="multinest", n_eff=0, discard_exploration=False,
n_networks=4, pool=4):
n_networks=4, pool=1):
""" Fit the specified model to the input galaxy data.
Parameters
Expand Down Expand Up @@ -169,8 +169,7 @@ def fit(self, verbose=False, n_live=400, use_MPI=True,
elif sampler not in ["multinest", "nautilus"]:
raise ValueError("Sampler {} not supported.".format(sampler))
elif not (multinest_available or nautilus_available):
raise RuntimeError(
"Neither MultiNest nor nautilus could be loaded.")
raise RuntimeError("No sampling algorithm could be loaded.")

if rank == 0 or not use_MPI:
print("\nBagpipes: fitting object " + self.galaxy.ID + "\n")
Expand All @@ -179,6 +178,7 @@ def fit(self, verbose=False, n_live=400, use_MPI=True,

with warnings.catch_warnings():
warnings.simplefilter("ignore")
os.environ["PYTHONWARNINGS"] = "ignore"

if sampler == "multinest":
pmn.run(self.fitted_model.lnlike,
Expand All @@ -193,11 +193,13 @@ def fit(self, verbose=False, n_live=400, use_MPI=True,
self.fitted_model.lnlike, n_live=n_live,
n_networks=n_networks, pool=pool,
n_dim=self.fitted_model.ndim,
filepath=self.fname + "nautilus.h5")
filepath=self.fname + ".h5")

n_sampler.run(verbose=verbose, n_eff=n_eff,
discard_exploration=discard_exploration)

os.environ["PYTHONWARNINGS"] = ""

if rank == 0 or not use_MPI:
runtime = time.time() - start_time

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Expand Up @@ -54,9 +54,9 @@
# built documents.
#
# The short X.Y version.
version = u'1.0.4'
version = u'1.1.0'
# The full version, including alpha/beta/rc tags.
release = u'1.0.4'
release = u'1.1.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
5 changes: 4 additions & 1 deletion docs/index.rst
Expand Up @@ -29,7 +29,9 @@ Bagpipes is `developed at GitHub <https://github.com/ACCarnall/bagpipes>`_, howe
pip install bagpipes
All of the code's Python dependencies will be automatically installed. The only (optional) non-Python dependency is the MultiNest nested sampling algorithm (used only for fitting). Note that if MultiNest is not installed, Bagpipes will use the nautilus sampler for fitting, instead.
All of the code's Python dependencies will be automatically installed.

Historically, fitting with Bagpipes has relied on the `MultiNest <https://github.com/JohannesBuchner/MultiNest>`_ nested sampling algorithm, a non-Python dependency that requires separate installation. This is sometimes challenging on certain systems. Recently, Bagpipes has been updated such that it will now automatically use the Python-based `nautilus <https://nautilus-sampler.readthedocs.io/en/stable/>`_ sampler for fitting if MultiNest is not installed. If you wish to use MultiNest, the installation instructions below may be of assistance.

The simplest way to install MultiNest if you have an anaconda python disribution is with the command **conda install -c conda-forge multinest**.

Expand Down Expand Up @@ -68,6 +70,7 @@ Note: Depending on when you install, the gcc version might be different. One can

If you are running a Linux operating system, or have MacPorts instead of Homebrew, you may run into additional issues. I may be able to provide advice if you get stuck.


Published papers and citing the code
------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion rtd-environment.yml
Expand Up @@ -13,4 +13,5 @@ dependencies:
- spectres
- numpy==1.22.0
- scipy
- matplotlib
- matplotlib
- nautilus-sampler
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -11,7 +11,7 @@
setup(
name='bagpipes',

version='1.0.4',
version='1.1.0',

description='Galaxy spectral fitting',

Expand Down

0 comments on commit 61268db

Please sign in to comment.