Skip to content

Commit

Permalink
Merge pull request #269 from DavAug/issue-268-myokit-upgrade
Browse files Browse the repository at this point in the history
Issue 268 myokit upgrade
  • Loading branch information
DavAug authored Aug 5, 2023
2 parents b8d80ff + 100bb9c commit 2da8463
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 393 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-test-python-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v1
Expand All @@ -24,7 +24,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: install sundials
run: |
sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, David Augustin
Copyright (c) 2023, David Augustin
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
2 changes: 1 addition & 1 deletion chi/_error_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,7 @@ def fix_parameters(self, name_value_dict):
self._fixed_params_values[index] = value

# If all parameters are free, set mask and values to None again
if np.alltrue(~self._fixed_params_mask):
if np.all(~self._fixed_params_mask):
self._fixed_params_mask = None
self._fixed_params_values = None

Expand Down
4 changes: 2 additions & 2 deletions chi/_log_pdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def __call__(self, parameters):
top_parameters, bottom_parameters, covariates=self._covariates)

# Return if values already lead to a rejection
if np.isinf(score):
return score
if np.isinf(score): # noqa: no cover
return score # noqa: no cover

# Transform bottom-level parameters
# Identity, if model does not tranform parameters
Expand Down
2 changes: 1 addition & 1 deletion chi/_mechanistic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ def fix_parameters(self, name_value_dict):
self._fixed_params_values[index] = value

# If all parameters are free, set mask and values to None again
if np.alltrue(~self._fixed_params_mask):
if np.all(~self._fixed_params_mask):
self._fixed_params_mask = None
self._fixed_params_values = None

Expand Down
2 changes: 1 addition & 1 deletion chi/_population_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3274,7 +3274,7 @@ def fix_parameters(self, name_value_dict):
self._fixed_params_values[index] = value

# If all parameters are free, set mask and values to None again
if np.alltrue(~self._fixed_params_mask):
if np.all(~self._fixed_params_mask):
self._fixed_params_mask = None
self._fixed_params_values = None

Expand Down
8 changes: 4 additions & 4 deletions chi/plots/_time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def _compute_bulk_probs(self, data, bulk_probs, time_key, sample_key):
biom_upper = reduced_data[mask][sample_key].min()

# Append percentiles to container
container = container.append(pd.DataFrame({
container = pd.concat([container, pd.DataFrame({
'Time': [time],
'Lower': [biom_lower],
'Upper': [biom_upper],
'Bulk probability': [str(bulk_prob)]}))
'Bulk probability': [str(bulk_prob)]})])

return container

Expand Down Expand Up @@ -538,11 +538,11 @@ def _compute_bulk_probs(self, data, bulk_probs, time_key, sample_key):
biom_upper = reduced_data[mask][sample_key].min()

# Append percentiles to container
container = container.append(pd.DataFrame({
container = pd.concat([container, pd.DataFrame({
'Time': [time],
'Lower': [biom_lower],
'Upper': [biom_upper],
'Bulk probability': [str(bulk_prob)]}))
'Bulk probability': [str(bulk_prob)]})])

return container

Expand Down
4 changes: 2 additions & 2 deletions chi/tests/test_error_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,11 +1487,11 @@ def test_set_get_parameter_names(self):
self.error_model.fix_parameters(name_value_dict={
'Sigma base': 1})
self.error_model.set_parameter_names(
['myokit.tumour_volume Sigma rel.'])
['global.tumour_volume Sigma rel.'])

names = self.error_model.get_parameter_names()
self.assertEqual(len(names), 1)
self.assertEqual(names[0], 'myokit.tumour_volume Sigma rel.')
self.assertEqual(names[0], 'global.tumour_volume Sigma rel.')

# Reset to defaults
self.error_model.set_parameter_names(None)
Expand Down
88 changes: 44 additions & 44 deletions chi/tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_call(self):
self.assertEqual(draws.loc[2], 2)

# Map parameters
param_map = {'myokit.tumour_volume': 'myokit.tumour_volume'}
param_map = {'global.tumour_volume': 'global.tumour_volume'}
pw_ll = chi.compute_pointwise_loglikelihood(
self.log_likelihood, self.posterior_samples,
param_map=param_map)
Expand Down Expand Up @@ -396,7 +396,7 @@ def test_call(self):

# # Map parameters
# param_map = {
# 'Pooled myokit.tumour_volume': 'Pooled myokit.tumour_volume'}
# 'Pooled global.tumour_volume': 'Pooled global.tumour_volume'}
# pw_ll = chi.compute_pointwise_loglikelihood(
# self.hierarch_log_likelihood,
# self.hierarch_posterior_samples,
Expand Down Expand Up @@ -510,7 +510,7 @@ def test_call_bad_input(self):
param_map=param_map)

# Not all parameters of the log-likelihood can be identified
param_map = {'myokit.tumour_volume': 'Something else'}
param_map = {'global.tumour_volume': 'Something else'}
with self.assertRaisesRegex(ValueError, 'The parameter <Something'):
chi.compute_pointwise_loglikelihood(
self.log_likelihood, self.posterior_samples,
Expand Down Expand Up @@ -682,7 +682,7 @@ def setUpClass(cls):
cls.problem = chi.ProblemModellingController(model, error_models)

data = DataLibrary().lung_cancer_control_group()
cls.problem.set_data(data, {'myokit.tumour_volume': 'Tumour volume'})
cls.problem.set_data(data, {'global.tumour_volume': 'Tumour volume'})

n_parameters = 7
log_prior = pints.ComposedLogPrior(*[
Expand Down Expand Up @@ -739,11 +739,11 @@ def test_run(self):
n_parameters = 7
parameters = result['Parameter'].unique()
self.assertEqual(len(parameters), n_parameters)
self.assertEqual(parameters[0], 'myokit.tumour_volume')
self.assertEqual(parameters[1], 'myokit.drug_concentration')
self.assertEqual(parameters[2], 'myokit.kappa')
self.assertEqual(parameters[3], 'myokit.lambda_0')
self.assertEqual(parameters[4], 'myokit.lambda_1')
self.assertEqual(parameters[0], 'global.tumour_volume')
self.assertEqual(parameters[1], 'global.drug_concentration')
self.assertEqual(parameters[2], 'global.kappa')
self.assertEqual(parameters[3], 'global.lambda_0')
self.assertEqual(parameters[4], 'global.lambda_1')
self.assertEqual(parameters[5], 'Sigma base')
self.assertEqual(parameters[6], 'Sigma rel.')

Expand Down Expand Up @@ -788,18 +788,18 @@ def test_run(self):
parameters = result['Parameter'].unique()
self.assertEqual(len(parameters), 16)
self.assertEqual(parameters[0], 'Sigma rel.')
self.assertEqual(parameters[1], 'Pooled myokit.tumour_volume')
self.assertEqual(parameters[2], 'Pooled myokit.drug_concentration')
self.assertEqual(parameters[3], 'ID 1 myokit.kappa')
self.assertEqual(parameters[4], 'ID 2 myokit.kappa')
self.assertEqual(parameters[5], 'ID 3 myokit.kappa')
self.assertEqual(parameters[6], 'ID 4 myokit.kappa')
self.assertEqual(parameters[7], 'ID 5 myokit.kappa')
self.assertEqual(parameters[8], 'ID 6 myokit.kappa')
self.assertEqual(parameters[9], 'ID 7 myokit.kappa')
self.assertEqual(parameters[10], 'ID 8 myokit.kappa')
self.assertEqual(parameters[11], 'Pooled myokit.lambda_0')
self.assertEqual(parameters[12], 'Pooled myokit.lambda_1')
self.assertEqual(parameters[1], 'Pooled global.tumour_volume')
self.assertEqual(parameters[2], 'Pooled global.drug_concentration')
self.assertEqual(parameters[3], 'ID 1 global.kappa')
self.assertEqual(parameters[4], 'ID 2 global.kappa')
self.assertEqual(parameters[5], 'ID 3 global.kappa')
self.assertEqual(parameters[6], 'ID 4 global.kappa')
self.assertEqual(parameters[7], 'ID 5 global.kappa')
self.assertEqual(parameters[8], 'ID 6 global.kappa')
self.assertEqual(parameters[9], 'ID 7 global.kappa')
self.assertEqual(parameters[10], 'ID 8 global.kappa')
self.assertEqual(parameters[11], 'Pooled global.lambda_0')
self.assertEqual(parameters[12], 'Pooled global.lambda_1')
self.assertEqual(parameters[13], 'Pooled Sigma base')
self.assertEqual(parameters[14], 'Log mean Sigma rel.')
self.assertEqual(parameters[15], 'Log std. Sigma rel.')
Expand All @@ -817,10 +817,10 @@ def test_run_catch_exception(self):
# Get test data and model
problem = copy.deepcopy(self.problem)
problem.fix_parameters({
'myokit.drug_concentration': 1,
'myokit.kappa': 1,
'myokit.lambda_0': 1,
'myokit.lambda_1': 1,
'global.drug_concentration': 1,
'global.kappa': 1,
'global.lambda_0': 1,
'global.lambda_1': 1,
'Sigma base': 1,
'Sigma rel.': 1})
problem.set_log_prior(pints.ComposedLogPrior(*[
Expand All @@ -842,7 +842,7 @@ def test_run_catch_exception(self):

parameters = result['Parameter'].unique()
self.assertEqual(len(parameters), 1)
self.assertEqual(parameters[0], 'myokit.tumour_volume')
self.assertEqual(parameters[0], 'global.tumour_volume')

runs = result['Run'].unique()
self.assertEqual(len(runs), 3)
Expand Down Expand Up @@ -878,7 +878,7 @@ def setUpClass(cls):
problem = chi.ProblemModellingController(model, error_models)

data = DataLibrary().lung_cancer_control_group()
problem.set_data(data, {'myokit.tumour_volume': 'Tumour volume'})
problem.set_data(data, {'global.tumour_volume': 'Tumour volume'})

n_parameters = 7
log_prior = pints.ComposedLogPrior(*[
Expand Down Expand Up @@ -929,11 +929,11 @@ def test_run(self):
self.assertEqual(len(parameters), 7)
self.assertEqual(parameters[0], 'Sigma base')
self.assertEqual(parameters[1], 'Sigma rel.')
self.assertEqual(parameters[2], 'myokit.drug_concentration')
self.assertEqual(parameters[3], 'myokit.kappa')
self.assertEqual(parameters[4], 'myokit.lambda_0')
self.assertEqual(parameters[5], 'myokit.lambda_1')
self.assertEqual(parameters[6], 'myokit.tumour_volume')
self.assertEqual(parameters[2], 'global.drug_concentration')
self.assertEqual(parameters[3], 'global.kappa')
self.assertEqual(parameters[4], 'global.lambda_0')
self.assertEqual(parameters[5], 'global.lambda_1')
self.assertEqual(parameters[6], 'global.tumour_volume')

chains = result.chain
self.assertEqual(len(chains), 3)
Expand Down Expand Up @@ -978,21 +978,21 @@ def test_run(self):

parameters = sorted(list(result.data_vars.keys()))
self.assertEqual(len(parameters), 16)
self.assertEqual(parameters[0], 'ID 1 myokit.kappa')
self.assertEqual(parameters[1], 'ID 2 myokit.kappa')
self.assertEqual(parameters[2], 'ID 3 myokit.kappa')
self.assertEqual(parameters[3], 'ID 4 myokit.kappa')
self.assertEqual(parameters[4], 'ID 5 myokit.kappa')
self.assertEqual(parameters[5], 'ID 6 myokit.kappa')
self.assertEqual(parameters[6], 'ID 7 myokit.kappa')
self.assertEqual(parameters[7], 'ID 8 myokit.kappa')
self.assertEqual(parameters[0], 'ID 1 global.kappa')
self.assertEqual(parameters[1], 'ID 2 global.kappa')
self.assertEqual(parameters[2], 'ID 3 global.kappa')
self.assertEqual(parameters[3], 'ID 4 global.kappa')
self.assertEqual(parameters[4], 'ID 5 global.kappa')
self.assertEqual(parameters[5], 'ID 6 global.kappa')
self.assertEqual(parameters[6], 'ID 7 global.kappa')
self.assertEqual(parameters[7], 'ID 8 global.kappa')
self.assertEqual(parameters[8], 'Log mean Sigma rel.')
self.assertEqual(parameters[9], 'Log std. Sigma rel.')
self.assertEqual(parameters[10], 'Pooled Sigma base')
self.assertEqual(parameters[11], 'Pooled myokit.drug_concentration')
self.assertEqual(parameters[12], 'Pooled myokit.lambda_0')
self.assertEqual(parameters[13], 'Pooled myokit.lambda_1')
self.assertEqual(parameters[14], 'Pooled myokit.tumour_volume')
self.assertEqual(parameters[11], 'Pooled global.drug_concentration')
self.assertEqual(parameters[12], 'Pooled global.lambda_0')
self.assertEqual(parameters[13], 'Pooled global.lambda_1')
self.assertEqual(parameters[14], 'Pooled global.tumour_volume')
self.assertEqual(parameters[15], 'Sigma rel.')

chains = result.chain
Expand Down
22 changes: 11 additions & 11 deletions chi/tests/test_log_pdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ def test_call_and_compute_pointwise_ll(self):
self.assertEqual(score, ref_score_2)
n_obs = 3
self.assertEqual(pw_score.shape, (n_obs,))
self.assertEqual(np.sum(pw_score), score)
self.assertAlmostEqual(np.sum(pw_score), score)

def test_evaluateS1(self):
# Test case I: Compute reference score manually
Expand Down Expand Up @@ -1987,7 +1987,7 @@ def test_fix_parameters(self):
self.assertEqual(len(parameter_names), 7)
self.assertEqual(parameter_names[0], 'dose.drug_amount')
self.assertEqual(parameter_names[1], 'central.size')
self.assertEqual(parameter_names[2], 'myokit.elimination_rate')
self.assertEqual(parameter_names[2], 'global.elimination_rate')
self.assertEqual(parameter_names[3], 'central.drug_amount Sigma base')
self.assertEqual(parameter_names[4], 'central.drug_amount Sigma rel.')
self.assertEqual(parameter_names[5], 'dose.drug_amount Sigma base')
Expand All @@ -1997,7 +1997,7 @@ def test_fix_parameters(self):
self.log_likelihood.fix_parameters(name_value_dict={
'dose.absorption_rate': None,
'dose.drug_amount Sigma base': 0.5,
'myokit.elimination_rate': 0.3})
'global.elimination_rate': 0.3})

n_parameters = self.log_likelihood.n_parameters()
self.assertEqual(n_parameters, 6)
Expand All @@ -2015,7 +2015,7 @@ def test_fix_parameters(self):
self.log_likelihood.fix_parameters(name_value_dict={
'central.drug_amount': None,
'dose.drug_amount Sigma base': None,
'myokit.elimination_rate': None})
'global.elimination_rate': None})

n_parameters = self.log_likelihood.n_parameters()
self.assertEqual(n_parameters, 9)
Expand All @@ -2026,7 +2026,7 @@ def test_fix_parameters(self):
self.assertEqual(parameter_names[1], 'dose.drug_amount')
self.assertEqual(parameter_names[2], 'central.size')
self.assertEqual(parameter_names[3], 'dose.absorption_rate')
self.assertEqual(parameter_names[4], 'myokit.elimination_rate')
self.assertEqual(parameter_names[4], 'global.elimination_rate')
self.assertEqual(parameter_names[5], 'central.drug_amount Sigma base')
self.assertEqual(parameter_names[6], 'central.drug_amount Sigma rel.')
self.assertEqual(parameter_names[7], 'dose.drug_amount Sigma base')
Expand All @@ -2046,7 +2046,7 @@ def test_get_parameter_names(self):
self.assertEqual(parameter_names[1], 'dose.drug_amount')
self.assertEqual(parameter_names[2], 'central.size')
self.assertEqual(parameter_names[3], 'dose.absorption_rate')
self.assertEqual(parameter_names[4], 'myokit.elimination_rate')
self.assertEqual(parameter_names[4], 'global.elimination_rate')
self.assertEqual(parameter_names[5], 'central.drug_amount Sigma base')
self.assertEqual(parameter_names[6], 'central.drug_amount Sigma rel.')
self.assertEqual(parameter_names[7], 'dose.drug_amount Sigma base')
Expand Down Expand Up @@ -2227,11 +2227,11 @@ def test_get_parameter_names(self):
parameter_names = self.log_posterior.get_parameter_names()

self.assertEqual(len(parameter_names), 7)
self.assertEqual(parameter_names[0], 'myokit.tumour_volume')
self.assertEqual(parameter_names[1], 'myokit.drug_concentration')
self.assertEqual(parameter_names[2], 'myokit.kappa')
self.assertEqual(parameter_names[3], 'myokit.lambda_0')
self.assertEqual(parameter_names[4], 'myokit.lambda_1')
self.assertEqual(parameter_names[0], 'global.tumour_volume')
self.assertEqual(parameter_names[1], 'global.drug_concentration')
self.assertEqual(parameter_names[2], 'global.kappa')
self.assertEqual(parameter_names[3], 'global.lambda_0')
self.assertEqual(parameter_names[4], 'global.lambda_1')
self.assertEqual(parameter_names[5], 'Sigma base')
self.assertEqual(parameter_names[6], 'Sigma rel.')

Expand Down
Loading

0 comments on commit 2da8463

Please sign in to comment.