Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: PyPI publisher

on:
release:
types: [published]

jobs:
pypi-publish:
name: Build and upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/rxmc/
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python3 -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_ACCESS_TOKEN }}
70 changes: 70 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13", "3.14"]

steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: black
uses: lgeiger/black-action@v1.0.1
with:
args: .

- name: Check for modified files
id: git-check
run: echo "modified=$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)" >> $GITHUB_OUTPUT

- name: Push changes
if: steps.git-check.outputs.modified == 'true'
uses: stefanzweifel/git-auto-commit-action@v4

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

- name: Install package and dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8
pip install -r requirements.txt
pip install .

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Run tests
run: |
pytest -v

- name: run jupyter notebook tests
run: |
pip install -r examples/requirements.txt
pytest --nbmake examples/ -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#slurm
*.out
*.slurm

# data
*.h5
Expand Down
52 changes: 35 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
# rxmc
Bayesian calibration of reaction models with Markov-Chain Monte Carlo, with flexible and composable models for the likelihood and body of evidence.
[![Python package](https://github.com/beykyle/rxmc/actions/workflows/python-package.yml/badge.svg)](https://github.com/beykyle/rxmc/actions/workflows/python-package.yml)


# RxMC
Bayesian calibration of reaction models, with flexible and composable models for the likelihood and body of evidence.
- curate the corpus of experimental constraints (e.g. using [`exfor_tools`](https://github.com/beykyle/exfor_tools))
- efficiently calculate your model's corresponding predictions for these observables using [`jitR`](https://github.com/beykyle/jitr)
- choose from a variety of likelihood models, or extend the basic [`LikelihoodModel`](https://github.com/beykyle/rxmc/blob/main/src/rxmc/likelihood_model.py) class to implement your own.
- package the constraints, physical model (and solver), and likelihood model together in a [`Evidence`](https://github.com/beykyle/rxmc/blob/main/src/rxmc/evidence.py) object which provides the likelihood of a given model parameter, for use in Bayesian calibration
- run Bayesian calibration using a [`Walker`](https://github.com/beykyle/rxmc/blob/main/src/rxmc/walker.py)

An example of this code in use is in the development of the [East Lansing Model](https://github.com/beykyle/elm)
- package the constraints, physics model, solver, and likelihood model together in a [`Evidence`](https://github.com/beykyle/rxmc/blob/main/src/rxmc/evidence.py) object which provides the likelihood of a given model parameter, for use in Bayesian calibration
- run Bayesian calibration using a [`Walker`](https://github.com/beykyle/rxmc/blob/main/src/rxmc/walker.py), or using a 3rd party MCMC sampler like [emcee](https://emcee.readthedocs.io/en/stable/user/sampler/).

Check out the [`examples/` directory](https://github.com/beykyle/rxmc/blob/main/examples/).

## documentation
- TBD

## installation


### pypi

- TBD
```
pip install rxmc
```

To also install the command line interface:

```
pip install rxm[cli]
```

The use of the CLI is demonstrated in `examples/rxmc_with_emcee_sampler/`.


### for development
```bash
Expand Down Expand Up @@ -70,18 +82,24 @@ This will require that your current python environment satisfies `requirements.t
## test

```
python -m unittest discover ./test
pytest
```

The examples and demos also serve as tests:

```
pip install -r examples/requirements.txt
pytest --nbmake examples/
```

## examples, demos and tutorials

check out the [`examples/` directory](https://github.com/beykyle/rxmc/blob/main/examples/)
check out the [`examples/` directory](https://github.com/beykyle/rxmc/blob/main/examples/). First install example specific dependencies:

```
pip install -r examples/requirements.txt
```

In particular, the following notebooks are useful for getting started with `rxmc`:
- [`examples/linear_calibration_demo.ipynb`](https://github.com/beykyle/rxmc/blob/main/examples/linear_calibration_demo.ipynb) for an illustrative example of fitting a line to data, which serves as the basic `rxmc` tutorial.
- [`systematic_err_demo.ipynb`](https://github.com/beykyle/rxmc/blob/main/examples/systematic_err_demo.ipynb) for a comparison of some of the likelihood models built into `rxmc`, and how to use them for situations involving systematic errors and multiple independent experimental constraints
- [`examples/30s_optical_potential_calibration.ipynb`](https://github.com/beykyle/rxmc/blob/main/examples/30s_optical_potential_calibration.ipynb) for a demo of a full Bayesian calibration of a a local optical potential to real experimental data using `rxmc` and `jitR`, in only 30 seconds!

## use with third party MCMC samplers

The `Evidence` class in `rxmc` can be used with any MCMC sampler that requires a function which returns the log-likelihood of a given parameter set. `rxmc.config.CalibrationConfig` provides a convenient way to package together an `Evidence` object with MCMC sampler settings, and can be used to run MCMC sampling with third party samplers like [`emcee`](https://emcee.readthedocs.io/en/stable/) or [`pymc`](https://www.pymc.io/). A fully fledged example of setting up an inference problem
with `rxmc`, and then using an `emcee` `EnsembleSampler` to sample from the posterior in a massively parallel MPI approach can be found in [`examples/emcee/`](https://github.com/beykyle/rxmc/blob/main/examples/emcee/).
102 changes: 55 additions & 47 deletions examples/30s_optical_potential_calibration.ipynb

Large diffs are not rendered by default.

Binary file added examples/ci_scaled_vs_non_badprior.pdf
Binary file not shown.
Binary file added examples/corner_oc_badprior.pdf
Binary file not shown.
Loading