Skip to content

Commit e7a3e90

Browse files
authored
Merge pull request #251 from CITCOM-project/dafni-branch
Dockerised framework for DAFNI
2 parents 4034519 + 5972be0 commit e7a3e90

File tree

12 files changed

+804
-0
lines changed

12 files changed

+804
-0
lines changed

dafni/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
../*
2+
../!causal_testing
3+
./!main_dafni.py
4+
./!data/

dafni/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#.env
2+
VARIABLES_PATH=./data/inputs/variables.json
3+
CAUSAL_TESTS=./data/inputs/causal_tests.json
4+
DATA_PATH=./data/inputs/runtime_data.csv
5+
DAG_PATH=./data/inputs/dag.dot

dafni/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Define the Python version neded for CTF
2+
FROM python:3.10-slim
3+
4+
## Prevents Python from writing pyc files
5+
ENV PYTHONDONTWRITEBYTECODE=1
6+
#
7+
## Keeps Python from buffering stdout and stderr to avoid the framework
8+
## from crashing without emitting any logs due to buffering
9+
ENV PYTHONUNBUFFERED=1
10+
11+
#Label maintainer
12+
LABEL maintainer="Dr. Farhad Allian - The University of Sheffield"
13+
14+
# Create a folder for the source code/outputs
15+
RUN mkdir -p ./causal_testing
16+
RUN mkdir -p ./data/outputs
17+
18+
# Copy the source code and test files from build into the container
19+
COPY --chown=nobody ../causal_testing ./causal_testing
20+
COPY --chown=nobody ./dafni/main_dafni.py ./
21+
COPY --chown=nobody ./dafni/data/inputs ./data/inputs
22+
23+
# Install core dependencies using PyPi
24+
RUN pip install causal-testing-framework --no-cache-dir
25+
26+
#For local testing purposes
27+
ENV VARIABLES_PATH=./data/inputs/variables.json \
28+
CAUSAL_TESTS=./data/inputs/causal_tests.json \
29+
DATA_PATH=./data/inputs/runtime_data.csv \
30+
DAG_PATH=./data/inputs/dag.dot
31+
32+
# Define the entrypoint/commands
33+
CMD python main_dafni.py --variables_path $VARIABLES_PATH --dag_path $DAG_PATH --data_path $DATA_PATH --tests_path $CAUSAL_TESTS

dafni/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Causal Testing Framework on DAFNI
2+
3+
- This directory contains the containerisation files of the causal testing framework using Docker, which is used
4+
to upload the framework onto [DAFNI](https://www.dafni.ac.uk).
5+
- It is **not** recommended to install the causal testing framework using Docker, and should only be installed
6+
using [PyPI](https://pypi.org/project/causal-testing-framework/).
7+
8+
### Folders
9+
10+
- `data` contains two sub-folders (the structure is important for DAFNI).
11+
- `inputs` is a folder that contains the input files that are (separately) uploaded to DAFNI.
12+
- `causal_tests.json` is a JSON file that contains the causal tests.
13+
- `variables.json` is a JSON file that contains the variables and constraints to be used.
14+
- `dag.dot` is a dot file that contains the directed acyclc graph (dag) file.
15+
- `runtime_data.csv` is a csv file that contains the runtime data.
16+
17+
- `outputs` is a folder where the `causal_tests_results.json` output file is created.
18+
19+
### Docker files
20+
- `main_dafni.py` is the entry-point to the causal testing framework that is used by Docker.
21+
- `model_definition.yaml` is the model metadata that is required to be uploaded to DAFNI.
22+
- `.env` is an example of a configuration file containing the environment variables. This is only required
23+
if using `docker-compose` to build the image.
24+
- `Dockerfile` is the main blueprint that builds the image.
25+
- `.dockerignore` tells the Dockerfile which files to not include in the image.
26+
- `docker-compose.yaml` is another method of building the image and running the container in one line.
27+
Note: the `.env` file that contains the environment variables for `main_dafni.py` is only used here.
28+
29+

dafni/data/inputs/causal_tests.json

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "max_doses _||_ cum_vaccinations",
5+
"estimator": "LinearRegressionEstimator",
6+
"estimate_type": "coefficient",
7+
"effect": "direct",
8+
"mutations": [
9+
"max_doses"
10+
],
11+
"expected_effect": {
12+
"cum_vaccinations": "NoEffect"
13+
},
14+
"formula": "cum_vaccinations ~ max_doses",
15+
"alpha": 0.05,
16+
"skip": false
17+
},
18+
{
19+
"name": "max_doses _||_ cum_vaccinated",
20+
"estimator": "LinearRegressionEstimator",
21+
"estimate_type": "coefficient",
22+
"effect": "direct",
23+
"mutations": [
24+
"max_doses"
25+
],
26+
"expected_effect": {
27+
"cum_vaccinated": "NoEffect"
28+
},
29+
"formula": "cum_vaccinated ~ max_doses",
30+
"alpha": 0.05,
31+
"skip": false
32+
},
33+
{
34+
"name": "max_doses _||_ cum_infections",
35+
"estimator": "LinearRegressionEstimator",
36+
"estimate_type": "coefficient",
37+
"effect": "direct",
38+
"mutations": [
39+
"max_doses"
40+
],
41+
"expected_effect": {
42+
"cum_infections": "NoEffect"
43+
},
44+
"formula": "cum_infections ~ max_doses",
45+
"alpha": 0.05,
46+
"skip": false
47+
},
48+
{
49+
"name": "vaccine --> cum_vaccinations",
50+
"estimator": "LinearRegressionEstimator",
51+
"estimate_type": "coefficient",
52+
"effect": "direct",
53+
"mutations": [
54+
"vaccine"
55+
],
56+
"expected_effect": {
57+
"cum_vaccinations": "SomeEffect"
58+
},
59+
"formula": "cum_vaccinations ~ vaccine",
60+
"skip": false
61+
},
62+
{
63+
"name": "vaccine --> cum_vaccinated",
64+
"estimator": "LinearRegressionEstimator",
65+
"estimate_type": "coefficient",
66+
"effect": "direct",
67+
"mutations": [
68+
"vaccine"
69+
],
70+
"expected_effect": {
71+
"cum_vaccinated": "SomeEffect"
72+
},
73+
"formula": "cum_vaccinated ~ vaccine",
74+
"skip": false
75+
},
76+
{
77+
"name": "vaccine --> cum_infections",
78+
"estimator": "LinearRegressionEstimator",
79+
"estimate_type": "coefficient",
80+
"effect": "direct",
81+
"mutations": [
82+
"vaccine"
83+
],
84+
"expected_effect": {
85+
"cum_infections": "SomeEffect"
86+
},
87+
"formula": "cum_infections ~ vaccine",
88+
"skip": false
89+
},
90+
{
91+
"name": "cum_vaccinations _||_ cum_vaccinated | ['vaccine']",
92+
"estimator": "LinearRegressionEstimator",
93+
"estimate_type": "coefficient",
94+
"effect": "direct",
95+
"mutations": [
96+
"cum_vaccinations"
97+
],
98+
"expected_effect": {
99+
"cum_vaccinated": "NoEffect"
100+
},
101+
"formula": "cum_vaccinated ~ cum_vaccinations + vaccine",
102+
"alpha": 0.05,
103+
"skip": false
104+
},
105+
{
106+
"name": "cum_vaccinations _||_ cum_infections | ['vaccine']",
107+
"estimator": "LinearRegressionEstimator",
108+
"estimate_type": "coefficient",
109+
"effect": "direct",
110+
"mutations": [
111+
"cum_vaccinations"
112+
],
113+
"expected_effect": {
114+
"cum_infections": "NoEffect"
115+
},
116+
"formula": "cum_infections ~ cum_vaccinations + vaccine",
117+
"alpha": 0.05,
118+
"skip": false
119+
},
120+
{
121+
"name": "cum_vaccinated _||_ cum_infections | ['vaccine']",
122+
"estimator": "LinearRegressionEstimator",
123+
"estimate_type": "coefficient",
124+
"effect": "direct",
125+
"mutations": [
126+
"cum_vaccinated"
127+
],
128+
"expected_effect": {
129+
"cum_infections": "NoEffect"
130+
},
131+
"formula": "cum_infections ~ cum_vaccinated + vaccine",
132+
"alpha": 0.05,
133+
"skip": false
134+
}
135+
]
136+
}

dafni/data/inputs/dag.dot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
digraph CausalDAG {
2+
rankdir=LR;
3+
"vaccine" -> "cum_vaccinations";
4+
"vaccine" -> "cum_vaccinated";
5+
"vaccine" -> "cum_infections";
6+
"max_doses";
7+
}

dafni/data/inputs/runtime_data.csv

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
pop_size,pop_type,pop_infected,n_days,vaccine_type,use_waning,rand_seed,cum_infections,cum_deaths,cum_recoveries,cum_vaccinations,cum_vaccinated,target_elderly,vaccine,max_doses
2+
50000,hybrid,1000,50,pfizer,True,1169,6277.0,15.0,6175.0,629466.0,530715.0,True,1,2
3+
50000,hybrid,1000,50,pfizer,True,8888,6381.0,18.0,6274.0,630796.0,532010.0,True,1,2
4+
50000,hybrid,1000,50,pfizer,True,370,6738.0,15.0,6621.0,631705.0,532864.0,True,1,2
5+
50000,hybrid,1000,50,pfizer,True,9981,6784.0,18.0,6682.0,634582.0,535795.0,True,1,2
6+
50000,hybrid,1000,50,pfizer,True,6305,6757.0,20.0,6659.0,631292.0,532464.0,True,1,2
7+
50000,hybrid,1000,50,pfizer,True,1993,5844.0,17.0,5755.0,633314.0,534478.0,True,1,2
8+
50000,hybrid,1000,50,pfizer,True,1938,6465.0,19.0,6353.0,627724.0,528993.0,True,1,2
9+
50000,hybrid,1000,50,pfizer,True,4797,7044.0,15.0,6919.0,631246.0,532433.0,True,1,2
10+
50000,hybrid,1000,50,pfizer,True,2308,6878.0,6.0,6801.0,628865.0,530038.0,True,1,2
11+
50000,hybrid,1000,50,pfizer,True,4420,6429.0,11.0,6348.0,633803.0,535030.0,True,1,2
12+
50000,hybrid,1000,50,pfizer,True,2314,6566.0,15.0,6477.0,629288.0,530550.0,True,1,2
13+
50000,hybrid,1000,50,pfizer,True,7813,6913.0,17.0,6818.0,629290.0,530512.0,True,1,2
14+
50000,hybrid,1000,50,pfizer,True,1050,6963.0,14.0,6860.0,627981.0,529212.0,True,1,2
15+
50000,hybrid,1000,50,pfizer,True,3215,6671.0,17.0,6577.0,628802.0,530038.0,True,1,2
16+
50000,hybrid,1000,50,pfizer,True,2286,6597.0,13.0,6505.0,628986.0,530195.0,True,1,2
17+
50000,hybrid,1000,50,pfizer,True,3080,6926.0,16.0,6834.0,633636.0,534904.0,True,1,2
18+
50000,hybrid,1000,50,pfizer,True,7405,6438.0,15.0,6347.0,630353.0,531540.0,True,1,2
19+
50000,hybrid,1000,50,pfizer,True,9668,6577.0,15.0,6485.0,631257.0,532409.0,True,1,2
20+
50000,hybrid,1000,50,pfizer,True,8211,6197.0,13.0,6103.0,633827.0,535056.0,True,1,2
21+
50000,hybrid,1000,50,pfizer,True,4686,6761.0,16.0,6653.0,630557.0,531737.0,True,1,2
22+
50000,hybrid,1000,50,pfizer,True,3591,7328.0,24.0,7214.0,629949.0,531124.0,True,1,2
23+
50000,hybrid,1000,50,pfizer,True,4834,6617.0,22.0,6512.0,632609.0,533705.0,True,1,2
24+
50000,hybrid,1000,50,pfizer,True,6142,7017.0,17.0,6902.0,635965.0,537252.0,True,1,2
25+
50000,hybrid,1000,50,pfizer,True,6877,6845.0,15.0,6753.0,635678.0,536925.0,True,1,2
26+
50000,hybrid,1000,50,pfizer,True,1878,6480.0,20.0,6390.0,630807.0,531999.0,True,1,2
27+
50000,hybrid,1000,50,pfizer,True,3761,6972.0,16.0,6890.0,631100.0,532329.0,True,1,2
28+
50000,hybrid,1000,50,pfizer,True,1741,6581.0,20.0,6491.0,632835.0,534088.0,True,1,2
29+
50000,hybrid,1000,50,pfizer,True,5592,6561.0,19.0,6461.0,636799.0,537959.0,True,1,2
30+
50000,hybrid,1000,50,pfizer,True,7979,7075.0,17.0,6966.0,632902.0,534140.0,True,1,2
31+
50000,hybrid,1000,50,pfizer,True,71,6291.0,13.0,6203.0,631694.0,532901.0,True,1,2

dafni/data/inputs/variables.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"variables": [
3+
{
4+
"name": "pop_size",
5+
"datatype": "int",
6+
"typestring": "Input",
7+
"constraint": 50000
8+
},
9+
{
10+
"name": "pop_infected",
11+
"datatype": "int",
12+
"typestring": "Input",
13+
"constraint": 1000
14+
},
15+
{
16+
"name": "n_days",
17+
"datatype": "int",
18+
"typestring": "Input",
19+
"constraint": 50
20+
},
21+
{
22+
"name": "vaccine",
23+
"datatype": "int",
24+
"typestring": "Input"
25+
},
26+
{
27+
"name": "cum_infections",
28+
"datatype": "int",
29+
"typestring": "Output"
30+
},
31+
{
32+
"name": "cum_vaccinations",
33+
"datatype": "int",
34+
"typestring": "Output"
35+
},
36+
{
37+
"name": "cum_vaccinated",
38+
"datatype": "int",
39+
"typestring": "Output"
40+
},
41+
{
42+
"name": "max_doses",
43+
"datatype": "int",
44+
"typestring": "Output"
45+
}
46+
]
47+
}

0 commit comments

Comments
 (0)