-
Notifications
You must be signed in to change notification settings - Fork 16
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 MontePythonReader and MontePythonSamples classes #14
add MontePythonReader and MontePythonSamples classes #14
Conversation
* Created a new file `read/montepythonreader.py` containing the class `MontePythonReader` which reads and processes MontePython chain files using `montepython.analyze`. - Extracts parameter names from MontePython's log.param file. - Removes burn-in and non-markovian points from the data. - Extracts tex names of the parameters. - Extracts parameter limits from MontePython's log.param file. * The new class `MontePythonSamples` in sampler.py calls `MontePythonReader` and turns the data into an `MCMCSamples` instance. Changes to be committed: * modified: anesthetic/__init__.py * new file: anesthetic/read/montepythonreader.py * modified: anesthetic/samples.py
Codecov Report
@@ Coverage Diff @@
## master #14 +/- ##
=========================================
+ Coverage 84.48% 85.7% +1.21%
=========================================
Files 14 15 +1
Lines 986 1070 +84
=========================================
+ Hits 833 917 +84
Misses 153 153
Continue to review full report at Codecov.
|
I very much approve of a monte python reader. Could you give me a bit more background on how a |
I modelled |
My query is whether one needs an entire new class for MontePythonSamples. At the moment there are MCMCSamples, which covers getdist format (I believe that @Pablo-Lemos may have a cosmosis format, which if so should be offered as a PR when they have time), and NestedSamples, which covers MultiNest and PolyChord formatting. I had envisaged that the role of the readers was to convert samples into one of these two classes to provide a unified 'inference interface'. NestedSamples are distinct from MCMCSamples, because they provide additional functionality such as evidence calculation and run-time replaying, but it's not clear to me what MontePython adds over GetDist in its samples which couldn't just be incorporated into the MCMCSamples class |
The difference between MontePython and GetDist is similar to the difference between MultiNest and PolyChord I think. So, yes, we probably could have the I guess I am not sure how to make |
Ah, I see. OK. You'll have to implement an
|
* Created file samplereader.py which replaces nested.py and takes over its job of inferring from the root which sampler was used and calls the appropriate reader out of the following list: - MultiNestReader - PolyChordReader - GetDistReader - MontePythonReader * MontePythonReader was expanded by the properties `log_param_file`, `paramnames_file` and `log_file` which are used in `SampleReader` to determine whether the provided root is a MontePython root. * Deferred the proper calls to `montepython.analyze` to the `_init` method in `MontePythonReader` (previously already done in `__init__`) such that an instance can be created and its properties used even if the provided root actually is not a MontePython root. This allows the necessary checks in `SampleReader` to be done. * Removed `MontePythonSamples` as this is now handled by `MCMCSamples`. Changes to be committed: * modified: anesthetic/__init__.py * modified: anesthetic/read/montepythonreader.py * new file: anesthetic/read/samplereader.py * modified: anesthetic/samples.py
Ok, I've managed to merge What do you think? |
This looks good. I like how you're using montepython's native chain reading. Makes me wonder whether a similar strategy should be applied for GetDist. Are you able to rename Ideally you should also add a couple of tests to confirm that the code works on a variety of machines. I assume that we want to keep montepython as an optional dependency, so it might be worth implementing an 'optional install' for the .travis system, as is done for fgivenx |
How essential is it to use MontePython's native functionality (in case people just have chains, but don't want to install montepython)? |
|
I thought as much. Would it be worth suffixing the other files with 'reader' for consistency?
Link to fgivenx above should give you the .travis.yml file modifications. Basically you have two different requirements files that it chooses to read from, one 'minimal' and the other with all optional dependencies installed. To do this you'd need to create the second requirements file, and extend the env section of .travis.yml a-la fgivenx.
It's worth remarking that the getdist ones should also potentially have burn-in removed, but anesthetic does not do this. |
I think that would be good. I actually generally think it is good when the module name reflects the class name therein.
What do you mean? Add a comment in the docs of |
That would be for another PR. For now you could raise an issue that our system doesn't provide an interface for removing burn in. |
|
… warn when MP updates cause trouble
…plaining of not being able to download 2.7 archive
…stallation issues with pypolychord which is not needed
…ly support OSX with python2
…not installed * `MontePythonReader._init` raises an ImportError when montepython package is not installed. - `test_read_montepython` now xfails (instead of skipping) when montepython is not installed. Changes to be committed: * modified: anesthetic/read/montepythonreader.py * modified: tests/test_samples.py
Then again, getdist only performs burn-in removal by discarding a certain fraction of the first steps. This would be easy enough to do with a pandas dataframe after the sample has been read with |
Not if the chains come from multiple files which are then combined. If anesthetic labelled which chain the points had come from (not a bad idea anyway), then this would be easy enough to do, but it would be most easy if there were an additional keyword argument passed to MCMCSamples and the reader. Definitely worth raising as an issue (or two) to remind somebody to do this at some point. |
mcmc = MCMCSamples(root='./tests/example_data/mp') | ||
mcmc.plot_2d(['x0', 'x1', 'x2', 'x3']) | ||
mcmc.plot_1d(['x0', 'x1', 'x2', 'x3']) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the use of this decorator to implement the conditional passing -- not something I've used before.
Many thanks @lukashergt . This kind of PR is essential for increasing the usage of this package |
Created a new file
read/montepythonreader.py
containing the classMontePythonReader
which reads and processes MontePython chain filesusing
montepython.analyze
.The new class
MontePythonSamples
in sampler.py callsMontePythonReader
and turns the data into anMCMCSamples
instance.Changes to be committed:
Checklist:
flake8 anesthetic tests
)pydocstyle --convention=numpy anesthetic
)python -m pytest
)