Skip to content

Commit

Permalink
**kwargs input and anesthetic.NestedSamples output (#90)
Browse files Browse the repository at this point in the history
* neighbor spelling (assuming we're sticking to American spelling!)

* updated run_poypolychord to use **kwargs rather than PolyChordSettings

* return anesthetic.NestedSamples output if installed

* added kwargs to run_pypolychord() docstring

* changed examples to use **kwargs

* accidental rename of run_polychord()

* set kwarg defaults separately to run_pypolychord so that they can be given to resume file

* run_polychord creates the paramnames file

* changed other examples paramnames are passed to run_pypolychord

* mention anesthetic output in docstring (incomplete)

* tidied up grade_dims and nlives argument processing

* logx should be logc

* missing comma

* removed settings argument

* Restored old interface

* run_polychord -> run

* reverted Python_Functions/ (apart from logx->logc correction

* put PolyChordSettings back in __init__.py

* run() uses make_resume_file_kwargs_interface

* added run to __init__.py

* update nDerived, prior and dumper to kwargs

* nDims is not a kwarg

* add nDerived, prior and dumper to kwargs

* use default_kwargs to set the defaults, then use this to see if kwargs has any excess keys

* separate default_kwargs that refer to other default_kwargs

* wrong brackets - think it's time to leave this for a moment

* removed accidental commas

* pass kwargs directly rather than creating dict

* added anesthetic to install_requires

* anesthetic now assumed to be installed, so new interface always returns an anesthetic output

* tidy up plotting to just use anesthetic output

* simplified to _make_resume_file(), plus wrapper _legacy_make_resume_file which translates from a settings object

* added run_pypolychord_legacy_interface.py

* update run() docstring to anesthetic output

* removed unused sqrt from run_pypolychord.py

* updated run_pypolychord.ipynb with py2nb

* change requirement to anesthetic==2.0.0b11

* removed creation of .paramnames file from run(), added to run_pypolychord.py

* corrected kwargs error message

* exception handling if chains/ already exists

* update to anesthetic 2.0.0b12

* rather than repeating PolyChordOutput.make_paramnames_file(), make it a static method and reuse it

* changed setup.py to point to github anesthetic as 2.0.0b12 hasn't been released

* remove unecessary os import

* removed commented out/empty lines around paramname creation

* removed unnecessary kwargs = kwargs.copy()

* double quotes to be more civilised

* change to single quotes to make Lucas happy

* update for more recent anesthetic

* line spacing and remove todo (see pr 110

* get anesthetic from pypi instead of gh

* might as well do some formatting

* also fix wrap_loglikelihood for new interface (#110)

* anesthetic back to optional, return None if not installed

* version bump to 1.22.0

* py2nb run_pypolychord.py

* Fix names of run scripts/notebooks

* remove testing print statement

* remove sqrt import, who knows where this came from

* Updated with new recommended interface

* anesthetic root is deprecated

* Update README.rst

* more anesthetic 2 madness

* update notebooks

* remove () from dict

* play around with tests

* add anesthetic to CI install step

* only run tests on python>=3.8

* test likelihood without derived parameters

* some test housekeeping

* use or between the two loglikelihood return options

* use pathlib.Path to save OSError nonsense

* explain paramnames more clearly

* check that grade_dims add up to nDims and test

* update run docstring anesthetic stuff

* correct run_pypolychord return

* correct missing blank lines in run() docstring

* add cluster_dir to kwargs, since technically it could be changed in PolyChordSettings (with difficulty)

* remove os entirely in favour of pathlib

* fix line too long

* update date

* fix default grade_frac

* remove pytest-mpi requirement from CI

* remove unecessary cast to set

* don't use ac shorthand, but also don't clutter the namespace with log and pi

* Revert "don't use ac shorthand, but also don't clutter the namespace with log and pi"

This reverts commit cc807f5.

* from anesthetic import make_2d_axes

---------

Co-authored-by: Adam Ormondroyd <52655393+Ormorod@users.noreply.github.com>
Co-authored-by: Will Handley <wh260@cam.ac.uk>
  • Loading branch information
3 people committed Jan 29, 2024
1 parent 864b7e8 commit b3daab9
Show file tree
Hide file tree
Showing 11 changed files with 839 additions and 126 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
include:
- os: ubuntu-20.04
python-version: '3.6'
python-version: ['3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
Expand All @@ -75,7 +72,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install mpi4py pytest pytest-mpi fortranformat
python -m pip install mpi4py pytest fortranformat anesthetic
- name: Install pypolychord
run: pip install -v '.[test]'
Expand All @@ -84,4 +81,4 @@ jobs:
run: python -m pytest tests

- name: Test pypolychord (MPI)
run: mpirun --oversubscribe -np 3 python -m pytest tests --only-mpi
run: mpirun --oversubscribe -np 3 python -m pytest tests
61 changes: 36 additions & 25 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.21.4
PolyChord v 1.22.0

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,34 +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/handley-lab/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
https://github.com/handley-lab/anesthetic
pip install anesthetic
```
pip install 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 @@ -211,7 +222,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 @@ -232,26 +242,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.21.4"
__version__ = "1.22.0"
from pypolychord.settings import PolyChordSettings
from pypolychord.polychord import run_polychord
from pypolychord.polychord import run_polychord, run
3 changes: 2 additions & 1 deletion 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
Loading

0 comments on commit b3daab9

Please sign in to comment.