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

DAFNI Workflow Enhancements #299

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
15 changes: 13 additions & 2 deletions .github/workflows/publish-to-dafni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,25 @@ jobs:
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install causal-testing-framework -e .[dev]
python -m pip install dafni-cli

- name: Run tests before uploading
id: tests
run: |
python -m pytest ./dafni/tests

- name: Build the container
if: steps.tests.outcome == 'success'
run: |
docker build -t ctf:${{ env.VERSION }} -f ./dafni/Dockerfile .
docker save ctf:${{ env.VERSION }} | gzip > ctf-dafni-${{ env.VERSION }}.tar.gz

- name: Install DAFNI-CLI and log in
- name: Log into DAFNI
run: |
python -m pip install dafni-cli
dafni login

- name: Upload to DAFNI
Expand Down
17 changes: 7 additions & 10 deletions dafni/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ ENV PYTHONDONTWRITEBYTECODE=1
## from crashing without emitting any logs due to buffering
ENV PYTHONUNBUFFERED=1

#Label maintainer
# Label maintainer
LABEL maintainer="Dr. Farhad Allian - The University of Sheffield"

# Create a folder for the source code/outputs
RUN mkdir -p ./causal_testing
RUN mkdir -p ./data/outputs

# Copy the source code and test files from build into the container
COPY --chown=nobody ../causal_testing ./causal_testing
COPY --chown=nobody ./dafni/main_dafni.py ./
# Copy the source code from local root and test files from build into the container
COPY --chown=nobody ./causal_testing ./causal_testing
COPY --chown=nobody ./dafni/src/ ./src
COPY --chown=nobody ./dafni/data/inputs ./data/inputs

# Install core dependencies using PyPi
RUN pip install causal-testing-framework --no-cache-dir

#For local testing purposes
ENV VARIABLES_PATH=./data/inputs/variables.json \
CAUSAL_TESTS=./data/inputs/causal_tests.json \
DATA_PATH=./data/inputs/runtime_data.csv \
DAG_PATH=./data/inputs/dag.dot
# Set the PYTHONPATH environment variable to include the /src directory
ENV PYTHONPATH="/src:${PYTHONPATH}"

# Define the entrypoint/commands
CMD python main_dafni.py --variables_path $VARIABLES_PATH --dag_path $DAG_PATH --data_path $DATA_PATH --tests_path $CAUSAL_TESTS
CMD python -m main_dafni --dag_path $DAG_PATH --data_path $DATA_PATH --tests_path $TESTS_PATH
7 changes: 5 additions & 2 deletions dafni/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ to upload the framework onto [DAFNI](https://www.dafni.ac.uk).
- `data` contains two sub-folders (the structure is important for DAFNI).
- `inputs` is a folder that contains the input files that are (separately) uploaded to DAFNI.
- `causal_tests.json` is a JSON file that contains the causal tests.
- `variables.json` is a JSON file that contains the variables and constraints to be used.
- `dag.dot` is a dot file that contains the directed acyclc graph (dag) file.
- `dag.dot` is a dot file that contains the directed acyclic graph (dag). Causal variables are defined as
node metadata attributes in this file as key-value pairs using the following syntax:
`node [datatype="int", typestring="input"]`. The `datatype` key specifies the datatype of the causal variable
as a string (e.g. `"int"`, `"str"`) and the `typestring` key specifies its typestring, which is also a string
representing the variable type (e.g. `"input"` or `"output"`).
- `runtime_data.csv` is a csv file that contains the runtime data.

- `outputs` is a folder where the `causal_tests_results.json` output file is created.
Expand Down
13 changes: 9 additions & 4 deletions dafni/data/inputs/dag.dot
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
digraph CausalDAG {
rankdir=LR;
"vaccine" -> "cum_vaccinations";
"vaccine" -> "cum_vaccinated";
"vaccine" -> "cum_infections";
"max_doses";
vaccine [datatype="int", typestring="input"];
cum_vaccinations [datatype="int", typestring="output"];
cum_vaccinated [datatype="int", typestring="output"];
cum_infections [datatype="int", typestring="output"];
max_doses [datatype="int", typestring="output"];
vaccine -> cum_vaccinations;
vaccine -> cum_vaccinated;
vaccine -> cum_infections;
max_doses;
}
108 changes: 81 additions & 27 deletions dafni/data/outputs/causal_tests_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
"outcome": "cum_vaccinations",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 252628.1066666667,
"ci_low": 252271.33332001517,
"ci_high": 252984.8800133182
"effect_estimate": {
"max_doses": 252628.1066666667
},
"ci_low": [
252271.33332001517
],
"ci_high": [
252984.8800133182
]
}
},
{
Expand All @@ -42,9 +48,15 @@
"outcome": "cum_vaccinated",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 213111.93333333335,
"ci_low": 212755.15056812647,
"ci_high": 213468.71609854023
"effect_estimate": {
"max_doses": 213111.93333333335
},
"ci_low": [
212755.15056812647
],
"ci_high": [
213468.71609854023
]
f-allian marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
Expand All @@ -66,9 +78,15 @@
"outcome": "cum_infections",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 2666.3066666666664,
"ci_low": 2619.972040648758,
"ci_high": 2712.6412926845746
"effect_estimate": {
"max_doses": 2666.3066666666664
},
"ci_low": [
2619.972040648758
],
"ci_high": [
2712.6412926845746
]
}
},
{
Expand All @@ -89,9 +107,15 @@
"outcome": "cum_vaccinations",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 315785.1333333332,
"ci_low": 315339.1666500188,
"ci_high": 316231.1000166476
"effect_estimate": {
"vaccine": 315785.1333333332
},
"ci_low": [
315339.1666500188
],
"ci_high": [
316231.1000166476
]
}
},
{
Expand All @@ -112,9 +136,15 @@
"outcome": "cum_vaccinated",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 266389.91666666657,
"ci_low": 265943.93821015797,
"ci_high": 266835.89512317517
"effect_estimate": {
"vaccine": 266389.91666666657
},
"ci_low": [
265943.93821015797
],
"ci_high": [
266835.89512317517
]
}
},
{
Expand All @@ -135,9 +165,15 @@
"outcome": "cum_infections",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 3332.883333333332,
"ci_low": 3274.9650508109467,
"ci_high": 3390.801615855717
"effect_estimate": {
"vaccine": 3332.883333333332
},
"ci_low": [
3274.9650508109467
],
"ci_high": [
3390.801615855717
]
}
},
{
Expand All @@ -159,9 +195,15 @@
"outcome": "cum_vaccinated",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": 0.9998656401531605,
"ci_low": 0.9929245394499968,
"ci_high": 1.0068067408563242
"effect_estimate": {
"cum_vaccinations": 0.9998656401531605
},
"ci_low": [
0.9929245394499968
],
"ci_high": [
1.0068067408563242
]
}
},
{
Expand All @@ -183,9 +225,15 @@
"outcome": "cum_infections",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": -0.006416682407515084,
"ci_low": -0.05663010083886572,
"ci_high": 0.043796736023835554
"effect_estimate": {
"cum_vaccinations": -0.006416682407515084
},
"ci_low": [
-0.05663010083886572
],
"ci_high": [
0.043796736023835554
]
}
},
{
Expand All @@ -207,9 +255,15 @@
"outcome": "cum_infections",
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": -0.006176900588291234,
"ci_low": -0.05639349612119588,
"ci_high": 0.04403969494461341
"effect_estimate": {
"cum_vaccinated": -0.006176900588291234
},
"ci_low": [
-0.05639349612119588
],
"ci_high": [
0.04403969494461341
]
}
}
]
4 changes: 2 additions & 2 deletions dafni/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ services:
causal-testing-framework:
build:
context: ../
dockerfile: ./dafni/Dockerfile
dockerfile: dafni/Dockerfile
env_file:
- .env
volumes:
- .:/usr/src/app
- ./dafni:/usr/src/
8 changes: 0 additions & 8 deletions dafni/model_definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ spec:
path: inputs/
required: true

- name: Variables
description: >
A .JSON file containing the input variables to be used
default:
- 02e755c8-952b-461a-a914-4f4ffbe2edf1
path: inputs/
required: true

outputs:
datasets:
- name: causal_test_results.json
Expand Down
Empty file added dafni/src/__init__.py
Empty file.
Loading
Loading