Skip to content

Commit

Permalink
Merge pull request #32 from chimaerase/update-pre-commit
Browse files Browse the repository at this point in the history
Update pre commit and CI configs
  • Loading branch information
paulthebaker authored Oct 26, 2022
2 parents 481db2b + 2c2b4f3 commit 2d548a5
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 136 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
release:
release:
types:
- published

Expand All @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, '3.10']

steps:
- name: Checkout repository
Expand Down Expand Up @@ -57,10 +57,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up Python
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.7"
python-version: "3.10"
- name: Install non-python dependencies on linux
run: |
sudo apt install libopenmpi-dev
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand All @@ -103,4 +103,4 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
twine upload dist/*
twine upload dist/*
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
repos:
- repo: https://github.com/ambv/black
rev: 19.10b0
rev: 22.10.0
hooks:
- id: black
args: ["--config=pyproject.toml", "--check"]
args: ["--config=pyproject.toml"]
- repo: https://gitlab.com/pycqa/flake8
rev: "3.7.7"
rev: 5.0.4
hooks:
- id: flake8
args: ["--config=.flake8"]
- repo: https://github.com/timothycrosley/isort
rev: 5.6.1
rev: 5.10.1
hooks:
- id: isort

12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ init:
@./venv/bin/python3 -m pip install -e .

format:
black .

lint:
black --check .
flake8 .
pre-commit run --all-files

clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts

Expand All @@ -61,7 +57,7 @@ clean-test: ## remove test and coverage artifacts
rm -f .coverage
rm -fr htmlcov/

test: lint ## run tests quickly with the default Python
test: format ## run tests quickly with the default Python
pytest -v --durations=10 --full-trace --cov-report html --cov-config .coveragerc --cov=PTMCMCSampler tests

coverage: test ## check code coverage quickly with the default Python
Expand All @@ -74,7 +70,7 @@ dist: clean ## builds source and wheel package
ls -l dist

test-sdist: ## Test source distribution
mkdir tmp
mkdir tmp
cd tmp
python -m venv venv-sdist
venv-sdist/bin/python -m pip install --upgrade pip setuptools wheel
Expand All @@ -83,7 +79,7 @@ test-sdist: ## Test source distribution
rm -rf tmp venv-sdist

test-wheel: ## Test wheel
mkdir tmp2
mkdir tmp2
cd tmp2
python -m venv venv-wheel
venv-wheel/bin/python -m pip install --upgrade pip setuptools
Expand Down
2 changes: 1 addition & 1 deletion PTMCMCSampler/PTMCMCSampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def temperatureLadder(self, Tmin, Tmax=None, tstep=None):
tstep = np.exp(np.log(Tmax / Tmin) / (self.nchain - 1))
ladder = np.zeros(self.nchain)
for ii in range(self.nchain):
ladder[ii] = Tmin * tstep ** ii
ladder[ii] = Tmin * tstep**ii
else:
ladder = np.array([1])

Expand Down
12 changes: 6 additions & 6 deletions PTMCMCSampler/nutsjump.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,10 @@ def __call__(self, x, iter, beta):
dist = np.random.randn()

# Do the leapfrog
mq0 = q0 + 0.5 * vec * self.cd ** 2 * np.dot(vec, grad0) / 2 / val
mq0 = q0 + 0.5 * vec * self.cd**2 * np.dot(vec, grad0) / 2 / val
q1 = mq0 + dist * vec * self.cd / np.sqrt(val)
logp1, grad1 = self.func_grad_white(q1)
mq1 = q1 + 0.5 * vec * self.cd ** 2 * np.dot(vec, grad1) / 2 / val
mq1 = q1 + 0.5 * vec * self.cd**2 * np.dot(vec, grad1) / 2 / val

qxy = 0.5 * (np.sum((mq0 - q1) ** 2 / val) - np.sum((mq1 - q0) ** 2 / val))

Expand Down Expand Up @@ -454,16 +454,16 @@ def find_reasonable_epsilon(self, theta0, grad0, logp0):

a = 2.0 * float((acceptprob > 0.5)) - 1.0
# Keep moving epsilon in that direction until acceptprob crosses 0.5.
while (acceptprob ** a) > (2.0 ** (-a)):
epsilon = epsilon * (2.0 ** a)
while (acceptprob**a) > (2.0 ** (-a)):
epsilon = epsilon * (2.0**a)
_, rprime, _, logpprime = self.leapfrog(theta0, r0, grad0, epsilon)

acceptprob = np.exp(self.loghamiltonian(logpprime, rprime) - self.loghamiltonian(logp0, r0))

return epsilon

def stop_criterion(self, thetaminus, thetaplus, rminus, rplus, force_trajlen, index):
""" Compute the stop condition in the main loop
"""Compute the stop condition in the main loop
dot(dtheta, rminus) >= 0 & dot(dtheta, rplus >= 0)
INPUTS
Expand Down Expand Up @@ -809,7 +809,7 @@ def __call__(self, x, iter, beta):
if iter <= self.nburn:
# Still in the burn-in phase. So adjust epsilon
self.epsilon = np.exp(self.mu - np.sqrt(self.iter) / self.gamma * self.Hbar)
eta = self.iter ** -self.kappa
eta = self.iter**-self.kappa
self.epsilonbar = np.exp((1.0 - eta) * np.log(self.epsilonbar) + eta * np.log(self.epsilon))

else:
Expand Down
Loading

0 comments on commit 2d548a5

Please sign in to comment.