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 import #313

Merged
merged 30 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a6286cd
add ultranest import
JohannesBuchner Jul 11, 2023
592eefe
add test and output data from ultranest and script that creates it; f…
JohannesBuchner Jul 11, 2023
4877bd7
typo
JohannesBuchner Jul 11, 2023
fcabe8e
minimize ultranest data included
JohannesBuchner Jul 11, 2023
caca2f2
move h5py import into function, to make it only run when needed
JohannesBuchner Jul 11, 2023
6283f88
version bump to 2.1.0
lukashergt Jul 11, 2023
bb1eebd
make ultranest part of gui tests
lukashergt Jul 11, 2023
b8cd8ab
fix `test_gui_params` to work for both `pc` and `un`
lukashergt Jul 11, 2023
adb1ebc
put `json` and `h5py` into optional dependencies
lukashergt Jul 11, 2023
8d02f60
remove `json` from optional dependencies as it is a built-in package
lukashergt Jul 11, 2023
070b75e
fix labelling of AxesDataFrame for the case where there are exact mat…
lukashergt Jul 11, 2023
7033eab
skip tests related to ultranest if `h5py` not in `sys.modules`
lukashergt Jul 11, 2023
441c1d7
remove trailing print statement
lukashergt Jul 11, 2023
639bb09
update docs for reading UltraNest samples
lukashergt Jul 11, 2023
ce41b63
rename `makeun.py` to `un_gen_data.py` such that it gets grouped with…
lukashergt Jul 11, 2023
58baf2c
add Johannes Buchner to list of contributors
lukashergt Jul 11, 2023
8b09789
revert commit 070b75e173698a2012563d038d2e66bb82b88774, which checked…
lukashergt Jul 19, 2023
8a060fd
pass `labels=self.get_labels_map()` rather than `labels=self.get_labe…
lukashergt Jul 19, 2023
63e264f
add test for axes labels when dropping labels or when only having par…
lukashergt Jul 19, 2023
c9891f9
correct `read_ultranest` docstring to refer to UltraNest files, not t…
lukashergt Jul 19, 2023
b894efb
add UltraNest to the list of supported file structures in `read_chains`
lukashergt Jul 19, 2023
f6c62cf
improve `read_cobaya`, `read_multinest` and `read_polychord` docstrings
lukashergt Jul 19, 2023
298d8d9
move `bin/gen_data.py` to `tests/example_data/gen_data.py` to have da…
lukashergt Jul 19, 2023
64e7349
bring `gen_data.py` to the anesthetic 2.0.0 century
lukashergt Jul 19, 2023
1acbf53
make `gen_data.py` flake8 conform
lukashergt Jul 19, 2023
71c8cf0
temporarily remove `un/info/results.json`
lukashergt Jul 19, 2023
0ab5210
add `un/info/results.json` back in, hopefully in the right format
lukashergt Jul 19, 2023
d6da757
add `mn` to the gui tests
lukashergt Jul 19, 2023
57b00e1
Merge branch 'master' into master
williamjameshandley Jul 19, 2023
76c982f
Added back in infuriating newline which github automerge fails to do …
williamjameshandley Jul 19, 2023
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anesthetic: nested sampling post-processing
===========================================
:Authors: Will Handley and Lukas Hergt
:Version: 2.0.0
:Version: 2.1.0
:Homepage: https://github.com/handley-lab/anesthetic
:Documentation: http://anesthetic.readthedocs.io/

Expand Down
2 changes: 1 addition & 1 deletion anesthetic/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.0'
__version__ = '2.1.0'
8 changes: 7 additions & 1 deletion anesthetic/read/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from anesthetic.read.getdist import read_getdist
from anesthetic.read.cobaya import read_cobaya
from anesthetic.read.multinest import read_multinest
from anesthetic.read.ultranest import read_ultranest


def read_chains(root, *args, **kwargs):
Expand All @@ -12,6 +13,7 @@ def read_chains(root, *args, **kwargs):

* `PolyChord <https://github.com/PolyChord/PolyChordLite>`_,
* `MultiNest <https://github.com/farhanferoz/MultiNest>`_,
* `UltraNest <https://github.com/JohannesBuchner/UltraNest>`_,
* `CosmoMC <https://github.com/cmbant/CosmoMC>`_,
* `Cobaya <https://github.com/CobayaSampler/cobaya>`_,
* or anything `GetDist <https://github.com/cmbant/getdist>`_
Expand Down Expand Up @@ -45,7 +47,11 @@ def read_chains(root, *args, **kwargs):
"anesthetic.html#anesthetic.samples.MCMCSamples.remove_burn_in"
)
errors = []
for read in [read_polychord, read_multinest, read_cobaya, read_getdist]:
readers = [
read_polychord, read_multinest, read_cobaya,
read_ultranest, read_getdist
]
for read in readers:
try:
samples = read(root, *args, **kwargs)
samples.root = root
Expand Down
12 changes: 9 additions & 3 deletions anesthetic/read/cobaya.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Read MCMCSamples from cobaya chains."""
"""Read MCMCSamples from Cobaya chains."""
import os
import re
import numpy as np
Expand All @@ -13,8 +13,8 @@ def read_paramnames(root):
columns as there are parameters (sampled and derived) plus an
additional two corresponding to the weights (first column) and the
log-posterior (second column). The first line should start with a # and
should list the parameter names corresponding to the columns. This
will be used as label in the pandas array.
should list the parameter names corresponding to the columns. These
will be used as handles in the pandas array.
"""
with open(root + ".1.txt") as f:
header = f.readline()[1:]
Expand All @@ -34,6 +34,12 @@ def read_cobaya(root, *args, **kwargs):
Note that in order to optimally read chains from Cobaya you need to have
`GetDist <https://getdist.readthedocs.io/en/latest/>`__ installed.

Parameters
----------
root : str
root name for reading files in Cobaya format, i.e. the files
``<root>.*.txt`` and ``<root>.updated.yaml``.

Returns
-------
:class:`anesthetic.samples.MCMCSamples`
Expand Down
14 changes: 12 additions & 2 deletions anesthetic/read/multinest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
"""Read NestedSamples from multinest chains."""
"""Read NestedSamples from MultiNest chains."""
import os
import numpy as np
from anesthetic.read.getdist import read_paramnames
from anesthetic.samples import NestedSamples


def read_multinest(root, *args, **kwargs):
"""Read <root>ev.dat and <root>phys_live.points in MultiNest format."""
"""Read MultiNest chain files.

Parameters
----------
root : str
root name for reading files in MultiNest format, i.e. the files
``<root>ev.dat`` and ``<root>phys_live.points`` in the old format, and
``<root>dead-birth.txt`` and ``<root>phys_live-birth.txt`` in the new
format.

"""
try:
data = np.loadtxt(root + 'dead-birth.txt')
samples, logL, logL_birth, _ = np.split(data, [-4, -3, -2], axis=1)
Expand Down
12 changes: 10 additions & 2 deletions anesthetic/read/polychord.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"""Read NestedSamples from polychord chains."""
"""Read NestedSamples from PolyChord chains."""
import os
import numpy as np
from anesthetic.read.getdist import read_paramnames
from anesthetic.samples import NestedSamples


def read_polychord(root, *args, **kwargs):
"""Read ``<root>_dead-birth.txt`` in PolyChord format."""
"""Read PolyChord chain files.

Parameters
----------
root : str
root name for reading files in PolyChord format, i.e. the files
``<root>_dead-birth.txt`` and ``<root>_phys_live-birth.txt``.

"""
birth_file = root + '_dead-birth.txt'
birth_file
data = np.loadtxt(birth_file)
Expand Down
40 changes: 40 additions & 0 deletions anesthetic/read/ultranest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Read NestedSamples from UltraNest results."""
import os
import json
from anesthetic.samples import NestedSamples
try:
import h5py
except ImportError:
pass


def read_ultranest(root, *args, **kwargs):
"""Read UltraNest files.

Parameters
----------
root : str
root name for reading files in UltraNest format, i.e. the files
``<root>/info/results.json`` and ``<root>/results/points.hdf5``.

"""
with open(os.path.join(root, 'info', 'results.json')) as infofile:
labels = json.load(infofile)['paramnames']
num_params = len(labels)

filepath = os.path.join(root, 'results', 'points.hdf5')
with h5py.File(filepath, 'r') as fileobj:
points = fileobj['points']
_, ncols = points.shape
x_dim = ncols - 3 - num_params
logL_birth = points[:, 0]
logL = points[:, 1]
samples = points[:, 3+x_dim:3+x_dim+num_params]

kwargs['label'] = kwargs.get('label', os.path.basename(root))
columns = kwargs.pop('columns', labels)
labels = kwargs.pop('labels', labels)
data = samples

return NestedSamples(data=data, logL=logL, logL_birth=logL_birth,
columns=columns, labels=labels, *args, **kwargs)
2 changes: 1 addition & 1 deletion anesthetic/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def plot_2d(self, axes=None, *args, **kwargs):
axes = self.drop_labels().columns

if not isinstance(axes, AxesDataFrame):
_, axes = make_2d_axes(axes, labels=self.get_labels(),
_, axes = make_2d_axes(axes, labels=self.get_labels_map(),
upper=('upper' in kind),
lower=('lower' in kind),
diagonal=('diagonal' in kind))
Expand Down
191 changes: 0 additions & 191 deletions bin/gen_data.py

This file was deleted.

Loading