Skip to content

Commit

Permalink
Merge pull request #1449 from pints-team/del-operator
Browse files Browse the repository at this point in the history
Test failures after updates in github actions
  • Loading branch information
MichaelClerx authored Aug 11, 2022
2 parents 37b6f24 + 2e21d62 commit 2afaee9
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 92 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file.
- [#1424](https://github.com/pints-team/pints/pull/1424) Removed the `TriangleWaveTransform` class previously used in some optimisers.

### Fixed
- [#1449](https://github.com/pints-team/pints/pull/1449) Fixed a bug in `MarkovJumpModel.interpolate_mol_counts`.


## [0.4.0] - 2021-12-07
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
2 changes: 1 addition & 1 deletion pints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,4 @@ def version(formatted=False):
#
# Remove any imported modules, so we don't expose them as part of pints
#
del(os, sys)
del os, sys
2 changes: 1 addition & 1 deletion pints/_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def _clean(self):
if w.exitcode is not None: # pragma: no cover
w.join()
cleaned += 1
del(self._workers[k], w)
del self._workers[k], w
if cleaned: # pragma: no cover
gc.collect()
return cleaned
Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_dream.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def _draw(self, i):
Select 2 random chains, not including chain i.
"""
r1, r2 = np.random.choice(self._n_chains, 2, replace=False)
while(r1 == i or r2 == i or r1 == r2):
while r1 == i or r2 == i or r1 == r2:
r1, r2 = np.random.choice(self._n_chains, 2, replace=False)
return r1, r2

Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def tell(self, reply):
# Check reply, copy gradient
energy = float(energy)
gradient = pints.vector(gradient)
assert(gradient.shape == (self._n_parameters, ))
assert gradient.shape == (self._n_parameters, )

# Energy = -log_pdf, so flip both signs!
energy = -energy
Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_mala.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def tell(self, reply):
# Check reply, copy gradient
fx = float(fx)
log_gradient = pints.vector(log_gradient)
assert(log_gradient.shape == (self._n_parameters, ))
assert log_gradient.shape == (self._n_parameters, )

# First point?
if self._current is None:
Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_monomial_gamma_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ def tell(self, reply):
# Check reply, copy gradient
energy = float(energy)
gradient = pints.vector(gradient)
assert(gradient.shape == (self._n_parameters, ))
assert gradient.shape == (self._n_parameters, )

# Energy = -log_pdf, so flip both signs!
energy = -energy
Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_population.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _initialise(self):
# Ask all inner samplers for first point, which should be x0
for chain in self._chains:
x0 = chain.ask()
assert(np.all(x0 == self._x0))
assert np.all(x0 == self._x0)

# Update sampler state
self._running = True
Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_relativistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def tell(self, reply):
# Check reply, copy gradient
energy = float(energy)
gradient = pints.vector(gradient)
assert(gradient.shape == (self._n_parameters, ))
assert gradient.shape == (self._n_parameters, )

# Energy = -log_pdf, so flip both signs!
energy = -energy
Expand Down
2 changes: 1 addition & 1 deletion pints/_mcmc/_slice_rank_shrinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def tell(self, reply):
# Check reply, copy gradient
fx = float(fx)
grad = pints.vector(grad)
assert(grad.shape == (self._n_parameters, ))
assert grad.shape == (self._n_parameters, )

# Very first call
if self._current is None:
Expand Down
2 changes: 1 addition & 1 deletion pints/_optimisers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def __init__(
self._function = function
else:
self._function = pints.ProbabilityBasedError(function)
del(function)
del function

# Create optimiser
if method is None:
Expand Down
2 changes: 1 addition & 1 deletion pints/_optimisers/_cmaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _initialise(self):
"""
Initialises the optimiser for the first iteration.
"""
assert(not self._running)
assert not self._running

# Import cma (may fail!)
# Only the first time this is called in a running program incurs
Expand Down
2 changes: 1 addition & 1 deletion pints/_optimisers/_pso.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _initialise(self):
"""
Initialises the optimiser for the first iteration.
"""
assert(not self._running)
assert not self._running

# Initialize swarm
self._xs = [] # Particle coordinate vectors
Expand Down
2 changes: 1 addition & 1 deletion pints/_optimisers/_snes.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _initialise(self):
"""
Initialises the optimiser for the first iteration.
"""
assert(not self._running)
assert not self._running

# Shorthands
d = self._n_parameters
Expand Down
2 changes: 1 addition & 1 deletion pints/_optimisers/_xnes.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _initialise(self):
"""
Initialises the optimiser for the first iteration.
"""
assert(not self._running)
assert not self._running

# Shorthands
d = self._n_parameters
Expand Down
2 changes: 1 addition & 1 deletion pints/_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ def __init__(self, lower_or_boundaries, upper=None):

# Cache dimension
self._n_parameters = boundaries.n_parameters()
del(boundaries)
del boundaries

def elementwise(self):
""" See :meth:`Transformation.elementwise()`. """
Expand Down
2 changes: 1 addition & 1 deletion pints/plot/_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def surface(points, values, boundaries=None, markers='+', figsize=None):
# Extract x and y points
x = points[:, 0]
y = points[:, 1]
del(points)
del points

# Check boundaries
if boundaries is None:
Expand Down
4 changes: 2 additions & 2 deletions pints/tests/test_log_priors.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,9 +824,9 @@ def test_multivariate_normal_sampling(self):
def test_student_t_prior(self):
# Test two specific function values
p1 = pints.StudentTLogPrior(0, 2, 10)
self.assertEqual(p1([0]), -3.342305863833964)
self.assertAlmostEqual(p1([0]), -3.342305863833964)
p2 = pints.StudentTLogPrior(10, 5, 10)
self.assertEqual(p2([10]), -3.27120468204877)
self.assertAlmostEqual(p2([10]), -3.27120468204877)

# Test exceptions
self.assertRaises(ValueError, pints.StudentTLogPrior, 0, 0, 10)
Expand Down
2 changes: 1 addition & 1 deletion pints/tests/test_opt_optimisation_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def cb(i, opt):
csv = np.genfromtxt(p, delimiter=',', skip_header=1)[:-1]
lb = csv[:, 2]
lg = csv[:, 3]
del(csv)
del csv

fb, fg = np.array(fb), np.array(fg)

Expand Down
2 changes: 1 addition & 1 deletion pints/tests/test_toy_simple_egg_box_logpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_sensitivity_bounds_distance(self):
l, dl = f.evaluateS1([-1, -7])
self.assertEqual(l, f([-1, -7]))
self.assertAlmostEqual(l, -46.269777289511559)
self.assertEqual(dl[0], -4.6662126879796366)
self.assertAlmostEqual(dl[0], -4.6662126879796366)
self.assertAlmostEqual(dl[1], -2.6666666666666639)
self.assertTrue(np.array_equal(f.suggested_bounds(),
[[-30.0, -30.0], [30.0, 30.0]]))
Expand Down
21 changes: 15 additions & 6 deletions pints/tests/test_toy_stochastic_degradation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
# copyright notice and full license details.
#
import unittest

import numpy as np

from pints.toy.stochastic import DegradationModel


Expand Down Expand Up @@ -67,21 +69,28 @@ def test_mean_variance(self):

def test_errors(self):
model = DegradationModel(20)

# parameters, times cannot be negative
times = np.linspace(0, 100, 101)
parameters = [-0.1]
self.assertRaises(ValueError, model.mean, parameters, times)
self.assertRaises(ValueError, model.variance, parameters, times)
self.assertRaisesRegex(ValueError, 'constant must be positive',
model.mean, parameters, times)
self.assertRaisesRegex(ValueError, 'constant must be positive',
model.variance, parameters, times)

times_2 = np.linspace(-10, 10, 21)
parameters_2 = [0.1]
self.assertRaises(ValueError, model.mean, parameters_2, times_2)
self.assertRaises(ValueError, model.variance, parameters_2, times_2)
self.assertRaisesRegex(ValueError, 'Negative times',
model.mean, parameters_2, times_2)
self.assertRaisesRegex(ValueError, 'Negative times',
model.variance, parameters_2, times_2)

# this model should have 1 parameter
parameters_3 = [0.1, 1]
self.assertRaises(ValueError, model.mean, parameters_3, times)
self.assertRaises(ValueError, model.variance, parameters_3, times)
self.assertRaisesRegex(ValueError, 'only 1 parameter',
model.mean, parameters_3, times)
self.assertRaisesRegex(ValueError, 'only 1 parameter',
model.variance, parameters_3, times)


if __name__ == '__main__':
Expand Down
49 changes: 41 additions & 8 deletions pints/tests/test_toy_markov_jump_model.py → .../test_toy_stochastic_markov_jump_model.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_start_with_zero(self):
def test_start_with_twenty(self):
# Run small simulation
model = DegradationModel(20)
times = [0, 1, 2, 100, 1000]
times = [0, 1, 2, 100, 1000, 10000]
parameters = [0.1]
values = model.simulate(parameters, times)
self.assertEqual(len(values), len(times))
Expand All @@ -52,27 +52,60 @@ def test_simulate(self):
# Check interpolation function works as expected
temp_time = np.array([np.random.uniform(time[0], time[1])])
self.assertEqual(
model.interpolate_mol_counts(time, mol_count, temp_time)[0],
20)
model.interpolate_mol_counts(time, mol_count, temp_time)[0], 20)
temp_time = np.array([np.random.uniform(time[1], time[2])])
self.assertEqual(
model.interpolate_mol_counts(time, mol_count, temp_time)[0],
19)
model.interpolate_mol_counts(time, mol_count, temp_time)[0], 19)

# Check interpolation works if 1 time is given
time, mol, out = [1], [7], [0, 1, 2, 3]
interpolated = model.interpolate_mol_counts(time, mol, out)
self.assertEqual(list(interpolated), [7, 7, 7, 7])

# Check if no times are given
self.assertRaisesRegex(ValueError, 'At least one time',
model.interpolate_mol_counts, [], [], out)

# Check if times and count don't match
self.assertRaisesRegex(ValueError, 'must match',
model.interpolate_mol_counts, [1], [2, 3], out)

# Decreasing output times
self.assertRaisesRegex(
ValueError, 'must be non-decreasing',
model.interpolate_mol_counts, [1, 2], [2, 3], [1, 2, 3, 4, 0])

# Check extrapolation outside of output times
# Note: step-wise "interpolation", no actual interpolation!
time = [10, 11]
mol = [5, 6]
out = [0, 10, 10.5, 11, 20]
val = model.interpolate_mol_counts(time, mol, out)
self.assertEqual(list(val), [5, 5, 5, 6, 6])

time = [10]
mol = [5]
out = [0, 10, 10.5, 11, 20]
val = model.interpolate_mol_counts(time, mol, out)
self.assertEqual(list(val), [5, 5, 5, 5, 5])

def test_errors(self):
model = DegradationModel(20)
# times cannot be negative
times_2 = np.linspace(-10, 10, 21)
parameters_2 = [0.1]
self.assertRaises(ValueError, model.simulate, parameters_2, times_2)
self.assertRaisesRegex(ValueError, 'Negative times',
model.simulate, parameters_2, times_2)

# this model should have 1 parameter
times = np.linspace(0, 100, 101)
parameters_3 = [0.1, 1]
self.assertRaises(ValueError, model.simulate, parameters_3, times)
self.assertRaisesRegex(ValueError, 'should have 1 parameter',
model.simulate, parameters_3, times)

# Initial value can't be negative
self.assertRaises(ValueError, DegradationModel, -1)
self.assertRaisesRegex(ValueError, 'Initial molecule count',
DegradationModel, -1)


if __name__ == '__main__':
Expand Down
Empty file modified pints/tests/test_toy_stochastic_michaelis_menten_model.py
100644 → 100755
Empty file.
Empty file modified pints/tests/test_toy_stochastic_production_degradation_model.py
100644 → 100755
Empty file.
Empty file modified pints/tests/test_toy_stochastic_schlogl_model.py
100644 → 100755
Empty file.
10 changes: 4 additions & 6 deletions pints/toy/stochastic/_degradation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DegradationModel(MarkovJumpModel):
.. math::
A \xrightarrow{k} 0
Extends :class:`pints.ForwardModel`, :class:`pints.toy.ToyModel`.
Extends :class:`pints.MarkovJumpModel`.
Parameters
----------
Expand All @@ -29,14 +29,12 @@ class DegradationModel(MarkovJumpModel):
def __init__(self, initial_molecule_count=20):
V = [[-1]]
init_list = [initial_molecule_count]
super(DegradationModel, self).__init__(init_list,
V, self._propensities)
super(DegradationModel, self).__init__(
init_list, V, self._propensities)

@staticmethod
def _propensities(xs, ks):
return [
xs[0] * ks[0],
]
return [xs[0] * ks[0]]

def mean(self, parameters, times):
r"""
Expand Down
Loading

0 comments on commit 2afaee9

Please sign in to comment.