Skip to content

Commit

Permalink
Merge branch 'master' into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
williamjameshandley committed Feb 28, 2024
2 parents 779426a + e72048a commit 01c5ad0
Show file tree
Hide file tree
Showing 18 changed files with 1,017 additions and 404 deletions.
34 changes: 33 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,42 @@ jobs:
run: python run_pypolychord.py

- name: Test pypolychord (MPI)
run: mpirun -np 2 python run_pypolychord.py
run: mpirun --oversubscribe -np 3 python run_pypolychord.py

- name: Test pypolychord (anesthetic)
if: ${{ ! contains( '3.6, 3.7', matrix.python-version ) }}
run: |
pip install -r requirements.txt
python run_pypolychord.py
tests:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies (Linux)
run: sudo apt-get install gfortran libopenmpi-dev

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install mpi4py pytest fortranformat anesthetic
- name: Install pypolychord
run: pip install -v '.[test]'

- name: Test pypolychord (no MPI)
run: python -m pytest tests

- name: Test pypolychord (MPI)
run: mpirun --oversubscribe -np 3 python -m pytest tests
59 changes: 37 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
:target: https://arxiv.org/abs/1506.00171
:alt: Open-access paper

PolyChord v 1.20.2
PolyChord v 1.22.1

Will Handley, Mike Hobson & Anthony Lasenby

wh260@mrao.cam.ac.uk

arXiv:1502.01856
`arXiv:1502.01856 <https://arxiv.org/abs/1502.01856>`_

arXiv:1506.00171
`arXiv:1506.00171 <https://arxiv.org/abs/1506.00171>`_

Latest version Released Apr 2020
Latest version Released Jan 2024


PolyChord Licence
Expand All @@ -26,11 +26,12 @@ file. PolyChord is free for academic usage

Users are also required to cite the PolyChord papers:

- arXiv:1502.01856
- arXiv:1506.00171
- `arXiv:1502.01856 <https://arxiv.org/abs/1502.01856>`_
- `arXiv:1506.00171 <https://arxiv.org/abs/1506.00171>`_

in their publications.


Python quickstart
=================

Expand All @@ -39,30 +40,44 @@ For Python users in a hurry:
.. code:: bash
pip install git+https://github.com/PolyChord/PolyChordLite@master
wget https://raw.githubusercontent.com/PolyChord/PolyChordLite/master/run_pypolychord.py
python run_pypolychord.py
wget https://raw.githubusercontent.com/PolyChord/PolyChordLite/master/quickstart.py
python quickstart.py
You can then modify the file run_pypolychord.py to your needs. If you have mpi compilers available, this version can be run in parallel with mpi.
You should make sure that you have gfortran/gcc (or equivalent) fortran compilers installed.

You should make sure that you have gfortran (or equivalent) fortran compilers installed.
You can then modify the file quickstart.py to your needs. If you have mpi compilers available, this version can be run in parallel with mpi.

If any of the above steps fail (this can in general happen for certain Mac OSX versions), then try installing without pip:
If any of the above steps fail (this can in general happen for certain macOS versions), then try installing without pip:

.. code:: bash
git clone https://github.com/PolyChord/PolyChordLite.git
cd PolyChordLite
python setup.py install
or perhaps:

.. code:: bash
git clone https://github.com/PolyChord/PolyChordLite.git
cd PolyChordLite
make
pip install .
our apologies -- the shifting sands that are macOS do not play well with the delicate dance of fortran, C and Python that is (py)PolyChordLite.

If you do not have sudo access/virtual environments/anaconda, then appending `--user` to the install command may be necessary.

Post Processing
===============

We recommend the tool `anesthetic <https://github.com/williamjameshandley/anesthetic>`_ for post-processing your nested sampling runs. A plot gallery can be found `here <http://htmlpreview.github.io/?https://github.com/williamjameshandley/cosmo_example/blob/master/demos/demo.html>`_
We recommend the pip-installable tool `anesthetic <https://github.com/handley-lab/anesthetic>`_ for post-processing your nested sampling runs. A plot gallery can be found `here <https://anesthetic.readthedocs.io/en/latest/plotting.html>`_

.. code:: bash
pip install anesthetic
https://github.com/williamjameshandley/anesthetic
If `anesthetic` is already installed, then `pypolychord.run()` will return an `anesthetic.NestedSamples` object, which can be used directly for post-processing.

MPI Support
===========
Expand Down Expand Up @@ -215,7 +230,6 @@ You can install direct from the git repository using:
pip install https://github.com/PolyChord/PolyChordLite/archive/master.zip
(N.B. PyPi coming soon)
or you can install locally with the command:

.. code:: bash
Expand All @@ -236,26 +250,27 @@ and check that it's working by running:

.. code:: bash
$ python run_pypolychord.py
$ python quickstart.py
or in MPI:

.. code:: bash
$ mpirun -np 4 python run_pypolychord.py
$ mpirun -np 4 python quickstart.py
If so, the rest of the interface is relatively painless. Follow the example in
run_pypolychord.py, and consult the docstring if you need help:
quickstart.py, and consult the docstring if you need help:

.. code:: python
import pypolychord
from pypolychord.settings import PolyChordSettings
>>> import pypolychord
>>> help(pypolychord.run)
There is also a demo `python notebook <https://github.com/PolyChord/PolyChordLite/blob/master/quickstart.ipynb>`_.

To post-process nested sampling runs we recommend the pip-installable tool `anesthetic <https://github.com/handley-lab/anesthetic>`_. A plot gallery can be found `here <https://anesthetic.readthedocs.io/en/latest/plotting.html>`_

help(pypolychord.run_polychord)
help(PolyChordSettings)

There is also a demo `python notebook <https://github.com/PolyChord/PolyChordLite/blob/master/run_pypolychord.ipynb>`_.

Output files
=============
Expand Down
4 changes: 2 additions & 2 deletions pypolychord/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "1.20.2"
__version__ = "1.22.1"
from pypolychord.settings import PolyChordSettings
from pypolychord.polychord import run_polychord
from pypolychord.polychord import run_polychord, run
5 changes: 3 additions & 2 deletions pypolychord/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def make_paramnames_files(self, paramnames):
self._create_pandas_table(paramnames = paramnames)


def make_paramnames_file(self, paramnames, filename):
@staticmethod
def make_paramnames_file(paramnames, filename):
with open(filename, 'w') as f:
for name, latex in paramnames:
f.write('%s %s\n' % (name, latex))
Expand Down Expand Up @@ -215,7 +216,7 @@ def _dataframes_for_printing(self):
for paramname in self._samples_table.columns[2:]:
mean = np.mean(np.array( self._samples_table[paramname]) )
std = np.std(np.array( self._samples_table[paramname]) )
stats_dict[paramname] = '%.3E +\- %.3E' % (mean, std)
stats_dict[paramname] = '%.3E +/- %.3E' % (mean, std)

lst.append(pd.Series(stats_dict))
return lst
Expand Down
Loading

0 comments on commit 01c5ad0

Please sign in to comment.