diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index dfd2957..dd75cef 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,17 +9,16 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: '3.10' + python-version: '3.11' - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install -e .[develop] + pip install -e."[develop]" - name: Build documentation run: | - python setup.py build_sphinx + sphinx-build docs build/sphinx/ - name: Deploy documentation uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./build/sphinx/html/ + publish_dir: ./build/sphinx/ if: github.event_name == 'push' \ No newline at end of file diff --git a/README.md b/README.md index d0a7a18..8613c52 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ pip install pySODM Documentation: https://twallema.github.io/pySODM -Manuscript: https://arxiv.org/abs/2301.10664 +Manuscript: https://www.sciencedirect.com/science/article/pii/S1877750323002089 pyPI: https://pypi.org/project/pySODM/ @@ -61,6 +61,8 @@ The [enzyme kinetics](enzyme_kinetics.md) and [influenza 17-18](influenza_1718.m > Published to pyPI. - Version 0.2.3 (2023-05-04, PR #46) > Fixed minor bugs encountered when using pySODM for a dynamic input-output model of the Belgian economy. Published to pyPI. + - Version 0.2.4 (2023-12-04, PR #62) + > Validated the use of Python 3.11. Efficiency gains in simulation of jump processes. Ommitted dependency on Numba. All changes related to publishing our software manuscript in Journal of Computational Science. Improved nomenclature in model defenition. - Version 0.1 (2022-12-23, PR #14) > Application pySODM to three use cases. Documentation website. Unit tests for ODE, JumpProcess and calibration. - Version 0.1.1 (2023-01-09, PR #20) diff --git a/docs/installation.md b/docs/installation.md index a6309e5..4bf7445 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -8,14 +8,14 @@ pip install pySODM ### Install pySODM in a conda environment -When making your own modeling and simulation project, we recommend storing your dependencies in a conda environment. Using a conda environment allows others to more quickly replicate your code. Make sure you have Python (conda) and the required dependency packages installed. We recommend using `Anaconda` to manage your Python packages. See the [conda installation instructions](https://docs.anaconda.com/anaconda/install/) and make sure you have conda up and running. Next: +When making your own modeling and simulation project, we recommend storing your dependencies in a conda environment. Using a conda environment allows others to more quickly replicate your code. Make sure you have Python (conda) and the required dependency packages installed. We recommend using `Anaconda` to manage your Python packages. See the [conda installation instructions](https://docs.conda.io/projects/conda/en/latest/user-guide/install/linux.html) and make sure you have conda up and running. Next: - Update conda after the installation to make sure your version is up-to-date, ``` conda update conda ``` -- Make an environment file `environment.yml` with the dependencies of your own project. pySODM was validated on Python versions 3.9, 3.10 and 3.11. +- Make an environment file `environment.yml` with the dependencies of your own project. pySODM is currently validated on Python 3.11. ``` name: MY_ENVIRONMENT @@ -25,7 +25,6 @@ When making your own modeling and simulation project, we recommend storing your dependencies: - python=3.11 - ... - - ... ``` - Setup/update the `environment`: Dependencies are collected in the conda `environment.yml` file (inside the root folder), so anybody can recreate the required environment using, @@ -49,32 +48,34 @@ When making your own modeling and simulation project, we recommend storing your pip install pySODM ``` - __Note:__ This step needs to be done in a terminal or command prompt. Use your favorite terminal or use the [Anaconda Prompt](https://docs.anaconda.com/anaconda/user-guide/getting-started/#open-anaconda-prompt). Navigate with the `cd` command to the directory where you copied the `pySODM` repository. + __Note:__ The above step should be executed in a Linux terminal or command prompt. Use your favorite terminal or use the [Anaconda Prompt](https://docs.anaconda.com/anaconda/user-guide/getting-started/#open-anaconda-prompt). ### Want to try out the tutorials? -Installing pySODM from pyPI does not give you acces to the tutorials and case studies as these are on Github. To try them out, - -- Download the source code from GitHub. When all went fine, you should have the code on your computer in a directory called `pySODM`. +Installing pySODM from pyPI does not give you acces to the tutorials and case studies as these are located in the source on Github. To try them out, -- All we need to do is setup the PYSODM environment inside `environment.yml` and install pySODM from source inside this environment, +- Download the [source code](https://github.com/twallema/pySODM) from GitHub. When all went fine, you should have the code on your computer in a directory called `pySODM`. +- An environment with the dependencies for the tutorials is available inside the `~/environment.yml` file (environment name: PYSODM). Open a terminal in the root folder and create the PYSODM environment: ``` conda env create -f environment.yml + ``` + +- Activate the environment and install pySODM from source in it: + ``` conda activate PYSODM - pip install -e + pip install -e. ``` ### Want to work on pySODM? -- Create a [`github`](https://github.com/) account if you do not have one already. +- Create a [GitHub](https://github.com/) account if you do not have one already. - On the [pySODM Github repository page](https://github.com/twallema/pySODM) click the `Fork` button. - From your own repository page (your account) of `pySODM`, use [`git`](https://git-scm.com/) to download the code to your own computer. See the [Github documentation](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) on how to clone/download a repository. When all went fine, you should have the code on your computer in a directory called `pySODM`. This folder contains an `environment.yml` file containing all the dependencies necessary to recreate the tutorials and case studies. Install pySODM in this environment with the development requirements (necessary to work on the documentation), - - ``` - conda env create -f environment.yml - conda activate PYSODM - pip install -e ".[develop]" - ``` \ No newline at end of file +``` +conda env create -f environment.yml +conda activate PYSODM +pip install -e ".[develop]" +``` \ No newline at end of file diff --git a/docs/introduction.md b/docs/introduction.md index c68dcb4..6d2cdff 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -12,7 +12,7 @@ pip install pySODM Documentation: https://twallema.github.io/pySODM -Manuscript: https://arxiv.org/abs/2301.10664 +Manuscript: https://www.sciencedirect.com/science/article/pii/S1877750323002089 pyPI: https://pypi.org/project/pySODM/ diff --git a/setup.py b/setup.py index cad7e2e..72e537c 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ name='pySODM', packages=find_packages("src", exclude=["*.tests"]), package_dir={'': 'src'}, - version='0.2.3', + version='0.2.4', description='Simulating and Optimising Dynamical Models', author='Tijs Alleman, KERMIT, Ghent University', author_email='tijs.alleman@ugent.be', diff --git a/tutorials/SIR/workflow_tutorial.py b/tutorials/SIR/workflow_tutorial.py index 7756b4e..1d64c22 100644 --- a/tutorials/SIR/workflow_tutorial.py +++ b/tutorials/SIR/workflow_tutorial.py @@ -3,17 +3,14 @@ """ __author__ = "Tijs Alleman & Wolf Demunyck" -__copyright__ = "Copyright (c) 2023 by T.W. Alleman, BIOSPACE, Ghent University. All Rights Reserved." +__copyright__ = "Copyright (c) 2024 by T.W. Alleman, BIOSPACE, Ghent University. All Rights Reserved." ############################ ## Load required packages ## ############################ -from pyexpat import model -import sys,os -import emcee -import datetime +# General purpose packages import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -215,10 +212,10 @@ def draw_fcn(param_dict, samples_dict): return param_dict # Attach its arguments to the parameter dictionary - params.update({'start_measures': end_date}) + model.parameters.update({'start_measures': end_date}) # Initialize the model with the time dependent parameter funtion - model_with = ODE_SIR(states=init_states, parameters=params, time_dependent_parameters={'beta': lower_infectivity}) + model_with = ODE_SIR(states=model.initial_states, parameters=model.parameters, time_dependent_parameters={'beta': lower_infectivity}) # Simulate the model out_with = model_with.sim([start_date, end_date+pd.Timedelta(days=2*28)], N=100, samples=samples_dict, draw_function=draw_fcn, processes=processes) diff --git a/tutorials/SIR_SI/calibration.py b/tutorials/SIR_SI/calibration.py index f5df22b..4149b0e 100644 --- a/tutorials/SIR_SI/calibration.py +++ b/tutorials/SIR_SI/calibration.py @@ -10,7 +10,7 @@ ## Load required packages ## ############################ -import sys,os +# General purpose packages import corner import pandas as pd import numpy as np @@ -85,7 +85,6 @@ objective_function = log_posterior_probability(model, pars, bounds, data, states, log_likelihood_fnc, log_likelihood_fnc_args, labels=labels) # Initial guess --> pso theta = pso.optimize(objective_function, swarmsize=3*18, max_iter=30, processes=18, debug=True)[0] - #theta = [7, 0.05, 0.1, 0.2, 0.15] # Run Nelder-Mead optimisation theta = nelder_mead.optimize(objective_function, theta, 0.10*np.ones(len(theta)), processes=18, max_iter=30)[0] # Simulate the model @@ -115,7 +114,7 @@ ########################### # Variables - n_mcmc = 1000 + n_mcmc = 100 multiplier_mcmc = 9 processes = 9 print_n = 50 diff --git a/tutorials/influenza_1718/calibration.py b/tutorials/influenza_1718/calibration.py index a3943c0..0fb7ab3 100644 --- a/tutorials/influenza_1718/calibration.py +++ b/tutorials/influenza_1718/calibration.py @@ -1,14 +1,15 @@ """ -This script contains a calibration of an influenza model to 2017-2018 data. +This script contains the calibration of an influenza model to the 2017-2018 surveillance data """ __author__ = "Tijs Alleman & Wolf Demunyck" -__copyright__ = "Copyright (c) 2023 by T.W. Alleman, BIOSPACE, Ghent University. All Rights Reserved." +__copyright__ = "Copyright (c) 2024 by T.W. Alleman, BIOSPACE, Ghent University. All Rights Reserved." ############################ ## Load required packages ## ############################ +# General purpose packages import os import emcee import random @@ -32,19 +33,19 @@ ## Settings ## ############## -tau = 0.50 # Timestep of Tau-Leaping algorithm -alpha = 0.03 # Overdispersion factor (based on COVID-19) -end_calibration = pd.Timestamp('2018-03-01') -identifier = 'twallema_2018-03-01' -n_pso = 3 # Number of PSO iterations -multiplier_pso = 36 # PSO swarm size -n_mcmc = 200 # Number of MCMC iterations -multiplier_mcmc = 36 # Total number of Markov chains = number of parameters * multiplier_mcmc -print_n = 100 # Print diagnostics every print_n iterations -discard = 1000 # Discard first `discard` iterations as burn-in -thin = 10 # Thinning factor emcee chains -n = 100 # Repeated simulations used in visualisations -processes = int(os.getenv('SLURM_CPUS_ON_NODE', mp.cpu_count()/2)) +tau = 0.50 # Timestep of Tau-Leaping algorithm +alpha = 0.03 # Overdispersion factor (based on COVID-19) +end_calibration = pd.Timestamp('2018-03-01') # Enddate of calibration +identifier = 'twallema_2018-03-01' # Give any output of this script an ID +n_pso = 3 # Number of PSO iterations +multiplier_pso = 36 # PSO swarm size +n_mcmc = 50 # Number of MCMC iterations +multiplier_mcmc = 36 # Total number of Markov chains = number of parameters * multiplier_mcmc +print_n = 100 # Print diagnostics every print_n iterations +discard = 1000 # Discard first `discard` iterations as burn-in +thin = 10 # Thinning factor emcee chains +n = 100 # Repeated simulations used in visualisations +processes = int(os.getenv('SLURM_CPUS_ON_NODE', mp.cpu_count()/2)) # Automatically use half the number of available threads (typically corresponds to number of physical CPU cores) ############### ## Load data ## diff --git a/tutorials/influenza_1718/data_conversion.py b/tutorials/influenza_1718/data_conversion.py index 4ed7eac..5c711aa 100644 --- a/tutorials/influenza_1718/data_conversion.py +++ b/tutorials/influenza_1718/data_conversion.py @@ -4,9 +4,7 @@ import os import datetime -import numpy as np import pandas as pd -import matplotlib.pyplot as plt ############### ## Load data ##