Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simp vax #13

Merged
merged 11 commits into from
Oct 12, 2023
39 changes: 39 additions & 0 deletions .dev_scripts/create_auth_token_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import argparse
from COMPS import Client
from COMPS.CredentialPrompt import CredentialPrompt

__comps_client_version = 10


class StaticCredentialPrompt(CredentialPrompt):
def __init__(self, comps_url, username, password):
if (comps_url is None) or (username is None) or (password is None):
print("Usage: python create_auth_token_args.py --comps_url url --username username --password pwd")
print("\n")
raise RuntimeError('Missing comps_url, or username or password')
self._times_prompted = 0
self.comps_url = comps_url
self.username = username
self.password = password

def prompt(self):
print("logging in with user/pw")
self._times_prompted = self._times_prompted + 1
if self._times_prompted > 3:
raise RuntimeError('Failure authenticating')
return {'Username': self.username, 'Password': self.password}


if __name__ == '__main__':
parser = argparse.ArgumentParser()

parser.add_argument('-c', '--comps_url', default='https://comps2.idmod.org', help='comps url')
parser.add_argument('-u', '--username', help='enter username')
parser.add_argument('-p', '--password', help='enter password')

args = parser.parse_args()

compshost = args.comps_url

Client.login(compshost, StaticCredentialPrompt(comps_url=args.comps_url, username=args.username,
password=args.password))
61 changes: 61 additions & 0 deletions .github/workflows/run_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: run all tests
on:
workflow_dispatch:

jobs:
run-all-test-dev-install:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
python-version: [ 3.9 ]
steps:
- name: Checkout sources
uses: actions/checkout@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Config github user
run: |
git config --global user.email "[email protected]"
git config --global user.name "BambooUser-IDM"
- uses: actions/setup-python@master
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install requirements.txt
run: |
pip install -r requirements_2018.txt --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple
- name: Install from source
run: |
pip install -e .
- name: install test dependencies
run: |
pip3 install unittest-xml-reporting pytest
# - name: Install idm-test package
# run: |
# pip install idm-test>=0.0.13 --extra-index-url https://packages.idmod.org/api/pypi/pypi-production/simple
- name: Login to comps2
run: |
python ./.dev_scripts/create_auth_token_args.py --username "${{ secrets.COMPS_USER }}" --password "${{ secrets.COMPS_PASSWORD }}"
- name: run unittests
run: |
cd tests/unittests
py.test -sv --junitxml=reports/test_results.xml
- name: Upload unittest result to artifactory
if: failure()
uses: actions/upload-artifact@v3
with:
name: unittest_results
path: |
**/test_results.xml
- name: run workflow tests
run: |
cd tests/workflow_tests
py.test -sv --junitxml=reports/test_results.xml
- name: Upload workflow tests results to artifactory
if: failure()
uses: actions/upload-artifact@v3
with:
name: unittest_results
path: |
**/test_results.xml
121 changes: 54 additions & 67 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,108 +12,95 @@ podTemplate(
]) {
node(POD_LABEL) {
container('dtk-rpm-builder'){
def build_ok = true
def build_ok = true
stage('Cleanup Workspace') {
cleanWs()
echo "Cleaned Up Workspace For Project"
echo "${params.BRANCH}"
}
stage('Prepare') {
sh 'python --version'
sh 'python3 --version'
sh 'pip3 --version'

sh 'python3 -m pip install --upgrade pip'
sh 'pip3 install wheel unittest-xml-reporting pytest'
sh 'python3 -m pip install --upgrade setuptools'
sh 'pip3 freeze'
}
stage('Code Checkout') {
if (env.CHANGE_ID) {
echo "I execute on the pull request ${env.CHANGE_ID}"
checkout([$class: 'GitSCM',
branches: [[name: "pr/${env.CHANGE_ID}/head"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[refspec: '+refs/pull/*:refs/remotes/origin/pr/*', credentialsId: '704061ca-54ca-4aec-b5ce-ddc7e9eab0f2', url: '[email protected]:InstituteforDiseaseModeling/emodpy-typhoid.git']]])
branches: [[name: "pr/${env.CHANGE_ID}/head"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[refspec: '+refs/pull/*:refs/remotes/origin/pr/*', credentialsId: '704061ca-54ca-4aec-b5ce-ddc7e9eab0f2', url: '[email protected]:InstituteforDiseaseModeling/emod-typhoid.git']]])
} else {
echo "I execute on the ${env.BRANCH_NAME} branch"
git branch: "${env.BRANCH_NAME}",
credentialsId: '704061ca-54ca-4aec-b5ce-ddc7e9eab0f2',
url: '[email protected]:InstituteforDiseaseModeling/emodpy-typhoid.git'
}
}
stage('Prepare') {
sh 'python3 -m pip install --upgrade pip'
sh "pip3 install wheel"
sh 'python3 -m pip install --upgrade setuptools'
sh 'pip3 freeze'
}
stage('Build') {
sh 'pwd'
sh 'ls -a'
sh 'python3 package_setup.py bdist_wheel'

}
url: '[email protected]:InstituteforDiseaseModeling/emod-typhoid.git'
}
}
stage('Install') {
def curDate = sh(returnStdout: true, script: "date").trim()
echo "The current date is ${curDate}"

echo "I am installing emodpy-typhoid from wheel file built from code"
def wheelFile = sh(returnStdout: true, script: "find ./dist -name '*.whl'").toString().trim()
//def wheelFile = sh(returnStdout: true, script: "python3 ./.github/scripts/get_wheel_filename.py --package-file package_setup.py").toString().trim()
echo "This is the package file: ${wheelFile}"
sh "pip3 install $wheelFile --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple"

sh "pip3 install dataclasses"
sh 'pip3 install keyrings.alt'
sh "pip3 freeze"
echo "I am installing emodpy-typhoid from github source code"
sh "pip3 install -r requirements_2018.txt --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple"
sh "pip3 list"
sh "pip3 install -e ."
sh "pip3 list"
}
stage('Login') {
withCredentials([string(credentialsId: 'Comps_emodpy_user', variable: 'user'), string(credentialsId: 'Comps_emodpy_password', variable: 'password'),
string(credentialsId: 'Bamboo_id', variable: 'bamboo_user'), string(credentialsId: 'Bamboo', variable: 'bamboo_password')]) {
sh 'python3 .dev_scripts/create_auth_token_args.py --comps_url https://comps2.idmod.org --username $user --password $password'
sh 'python3 .dev_scripts/create_auth_token_args.py --comps_url https://comps.idmod.org --username yechen --password $password'
dir('tests/workflow_testing') {
sh 'python3 bamboo_login_with_arguments.py -u $bamboo_user -p $bamboo_password'
}
}
withCredentials([usernamePassword(credentialsId: 'comps_jenkins_user', usernameVariable: 'COMPS_USERNAME', passwordVariable: 'COMPS_PASSWORD'),
usernamePassword(credentialsId: 'comps2_jenkins_user', usernameVariable: 'COMPS2_USERNAME', passwordVariable: 'COMPS2_PASSWORD')])
{
sh 'python3 .dev_scripts/create_auth_token_args.py --comps_url https://comps2.idmod.org --username $COMPS2_USERNAME --password $COMPS2_PASSWORD'
sh 'python3 .dev_scripts/create_auth_token_args.py --comps_url https://comps.idmod.org --username $COMPS_USERNAME --password $COMPS_PASSWORD'
}

}

try{
stage('Unit Test') {
echo "Running Unit test Tests"
dir('tests/unittests') {
sh "pip3 install unittest-xml-reporting"
sh 'python3 -m xmlrunner discover'
junit '*.xml'
sh 'py.test -sv --junitxml=reports/test_results.xml'
junit 'reports/*.xml'
}
}
} catch(e) {
build_ok = false
echo e.toString()
echo e.toString()
}

try{
stage('Workflow Tests') {
stage('Workflow Test') {
echo "Running Workflow Tests"
dir('tests/workflow_testing') {
sh 'python3 -m xmlrunner discover'
junit '*.xml'
dir('tests/workflow_tests') {
sh 'py.test -sv --junitxml=reports/test_results.xml'
junit 'reports/*.xml'
}
}
} catch(e) {
build_ok = false
echo e.toString()
}

stage('Run Examples') {
echo "Running examples"
//sh 'yum -y remove mpich'
//sh 'yum -y install mpich-3.2'
//sh 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/mpich/lib'
sh 'pip3 install snakemake'
dir('examples') {
sh 'snakemake --cores=4 --config python_version=python3'
}
}
if(build_ok) {
currentBuild.result = "SUCCESS"
} else {
currentBuild.result = "FAILURE"
echo e.toString()
}

// stage('Run Examples') {
// echo "Running examples"
// dir('examples') {
// sh 'pip3 install snakemake'
// sh 'snakemake --cores=4 --config python_version=python3'
// }
// }
if(build_ok) {
currentBuild.result = "SUCCESS"
} else {
currentBuild.result = "FAILURE"
}
}
}
}
1 change: 0 additions & 1 deletion emodpy_typhoid/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ def cleanup_for_2018_mode( config ):
config.parameters.Infectious_Period_Distribution = "FIXED_DURATION" # hack
config.parameters.Base_Incubation_Period = 1
config.parameters.Base_Infectious_Period = 1
config.parameters["Listed_Events"] = []

31 changes: 31 additions & 0 deletions emodpy_typhoid/interventions/outbreak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from emod_api import schema_to_class as s2c
from emod_api.interventions import utils
from emod_api.interventions import common
import json

def add_outbreak_individual(start_day: int = 1,
demographic_coverage: float = 1.0,
node_ids: list = None,
repetitions: int = 1,
timesteps_between_repetitions: int = 365,
ind_property_restrictions: list = None):
import emod_api.campaign as campaign
import emod_api.interventions.outbreak as ob
from emod_api.interventions.common import ScheduledCampaignEvent

outbreak = ob.seed_by_coverage(
timestep=start_day,
campaign_builder=campaign,
coverage=demographic_coverage,
intervention_only=True
)

outbreak_event = ScheduledCampaignEvent(camp=campaign,
Start_Day=start_day,
Node_Ids=node_ids,
Number_Repetitions=repetitions,
Timesteps_Between_Repetitions=timesteps_between_repetitions,
Property_Restrictions=ind_property_restrictions,
Intervention_List=[outbreak],
Demographic_Coverage=demographic_coverage)
return outbreak_event
74 changes: 74 additions & 0 deletions emodpy_typhoid/interventions/typhoid_vaccine.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,37 @@ def new_intervention( camp, efficacy=0.82, mode="Shedding", constant_period=0, d
intervention.Changing_Effect.Decay_Time_Constant = decay_constant
return intervention

def new_vax( camp, efficacy=0.82, mode="Acquisition", constant_period=0, decay_constant=6935.0 ):
"""
Create a new 'SimpleVaccine' intervention with specified parameters. If you use this function directly, you'll need to distribute the intervention with a function like ScheduledCampaignEvent or TriggeredCampaignEvent from emod_api.interventions.common.

Args:
camp (Camp): The camp to which the intervention is applied.
efficacy (float, optional): The efficacy of the Typhoid vaccine. Default is 0.82.
mode (str, optional): The mode of the intervention. Default is "Acquisition" Can also be "Transmission" or "All".
constant_period (float, optional): The constant period of the waning effect in days. Default is 0.
decay_constant (float, optional): The decay time constant for the waning effect. Default is 6935.0.

Returns:
SimpleVaccine: A fully configured instance of the SimpleVaccine intervention with the specified parameters.
"""

intervention = s2c.get_class_with_defaults( "SimpleVaccine", camp.schema_path )
if mode == "Acquisition":
intervention.Vaccine_Type = "AcquisitionBlocking"
elif mode == "Transmission":
intervention.Vaccine_Type = "TransmissionBlocking"
elif mode == "All":
intervention.Vaccine_Type = "General"
else:
raise ValueError( f"mode {mode} not recognized. Options are: 'Acquisition', 'Transmission', or 'All'." )

intervention.Waning_Config = s2c.get_class_with_defaults( "WaningEffectBoxExponential" )
intervention.Waning_Config.Initial_Effect = efficacy
intervention.Waning_Config.Box_Duration = constant_period
intervention.Waning_Config.Decay_Time_Constant = decay_constant
return intervention

def new_triggered_intervention(
camp,
efficacy=0.82,
Expand Down Expand Up @@ -65,6 +96,49 @@ def new_triggered_intervention(

return event

def new_routine_immunization(
camp,
efficacy=0.82,
mode="Acquisition",
constant_period=0,
decay_constant=6935.0,
start_day=1,
child_age=9*30,
coverage=1.0,
node_ids=None,
property_restrictions_list=[],
co_event=None # expansion slot
):
"""
Create a new delayed, birth-triggered SimpleVaccine intervention based on specified parameters. Does not add to campaign.

Args:
camp (Camp): The camp to which the intervention is applied.
efficacy (float, optional): The efficacy of the Typhoid vaccine. Default is 0.82.
mode (str, optional): The mode of the intervention. Default is "Shedding".
constant_period (float, optional): The constant period of the waning effect in days. Default is 0.
decay_constant (float, optional): The decay time constant for the waning effect. Default is 6935.0.
start_day (int, optional): The day on which the intervention starts. Default is 1.
child_age (int, optional): The age of the person when they get the vaccine. Defaults to 9 months. Vaccines are actually distribute +/- 7 days.
coverage (float, optional): Demographic coverage of the intervention. Default is 1.0.
node_ids (list, optional): List of node IDs where the intervention is applied. Default is None.
property_restrictions_list (list, optional): List of property restrictions for the intervention. Default is an empty list.
co_event (None, optional): Expansion slot for future use.

Returns:
TriggeredCampaignEvent: An instance of a triggered campaign event with the TyphoidVaccine intervention.
"""
iv = new_vax( camp, efficacy=efficacy, mode=mode, constant_period=constant_period, decay_constant=decay_constant )
age_min = max(0,child_age-7)
delay = {
"Delay_Period_Min": age_min,
"Delay_Period_Max": child_age+7
}

event = common.triggered_campaign_delay_event( camp, start_day=start_day, trigger="Births", delay=delay, intervention=iv, ip_targeting=property_restrictions_list, coverage=coverage )

return event

def new_scheduled_intervention(
camp,
efficacy=0.82,
Expand Down
Loading
Loading