Skip to content

Commit fcab481

Browse files
authored
Merge branch 'main' into 323-batch-test-execution
2 parents 0b126f3 + 15513be commit fcab481

File tree

11 files changed

+146
-491
lines changed

11 files changed

+146
-491
lines changed

.github/workflows/publish-to-dafni.yaml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ jobs:
1818
- name: Get release version
1919
id: get_release
2020
run: |
21-
export VERSION=$(curl -sSL https://api.github.com/repos/CITCOM-project/CausalTestingFramework/releases/latest | jq -r '.tag_name' | head -c 2)
22-
echo "::set-output name=version::$VERSION"
21+
# Extract the version without the 'v' prefix using regex
22+
export VERSION=$(curl -sSL https://api.github.com/repos/CITCOM-project/CausalTestingFramework/releases/latest | jq -r '.tag_name' | sed -E 's/^v?([0-9]+(\.[0-9]+)?).*/\1/')
23+
echo "version=$VERSION" >> $GITHUB_OUTPUT
2324
2425
build_and_upload:
2526
name: Docker Build
@@ -38,17 +39,28 @@ jobs:
3839
with:
3940
python-version: '3.10'
4041

42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
python -m pip install causal-testing-framework -e .[dev]
46+
python -m pip install dafni-cli
47+
48+
- name: Check if unit tests are passing first
49+
id: tests
50+
uses: ./.github/workflows/ci-tests.yml
51+
4152
- name: Build the container
53+
if: success() && steps.tests.outcome == 'success'
4254
run: |
4355
docker build -t ctf:${{ env.VERSION }} -f ./dafni/Dockerfile .
4456
docker save ctf:${{ env.VERSION }} | gzip > ctf-dafni-${{ env.VERSION }}.tar.gz
4557
46-
- name: Install DAFNI-CLI and log in
58+
59+
- name: Log into DAFNI
4760
run: |
48-
python -m pip install dafni-cli
4961
dafni login
5062
5163
- name: Upload to DAFNI
5264
run: |
53-
dafni upload model ./dafni/model_definition.yaml ctf-dafni-${{ env.VERSION }}.tar.gz --version-message "Causal Testing Framework ${{ env.VERSION }}. Uploaded via Github Actions." --parent-id ${{ env.DAFNI_PARENT_ID }} -y
54-
dafni logout
65+
dafni upload model ./dafni/model_definition.yaml ctf-dafni-${{ env.VERSION }}.tar.gz --version-message "Causal Testing Framework v${{ env.VERSION }}. Uploaded via Github Actions." --parent-id ${{ env.DAFNI_PARENT_ID }} -y
66+
dafni logout

dafni/Dockerfile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define the Python version neded for CTF
2-
FROM python:3.10-slim
2+
FROM python:3.12-slim
33

44
## Prevents Python from writing pyc files
55
ENV PYTHONDONTWRITEBYTECODE=1
@@ -8,26 +8,22 @@ ENV PYTHONDONTWRITEBYTECODE=1
88
## from crashing without emitting any logs due to buffering
99
ENV PYTHONUNBUFFERED=1
1010

11-
#Label maintainer
11+
# Label maintainer
1212
LABEL maintainer="Dr. Farhad Allian - The University of Sheffield"
1313

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

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 ./
18+
# Copy the source code from local root and test files from build into the container
19+
COPY --chown=nobody ./causal_testing ./causal_testing
2120
COPY --chown=nobody ./dafni/data/inputs ./data/inputs
2221

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

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
25+
# Set the PYTHONPATH environment variable to include the /src directory
26+
ENV PYTHONPATH="/causal_testing:${PYTHONPATH}"
3127

3228
# 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
29+
CMD python -m causal_testing --dag_path $DAG_PATH --data_path $DATA_PATH --test_config $TESTS_PATH --output $OUTPUT

dafni/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@ to upload the framework onto [DAFNI](https://www.dafni.ac.uk).
55
- It is **not** recommended to install the causal testing framework using Docker, and should only be installed
66
using [PyPI](https://pypi.org/project/causal-testing-framework/).
77

8-
### Folders
8+
### Directory Hierarchy
99

1010
- `data` contains two sub-folders (the structure is important for DAFNI).
1111
- `inputs` is a folder that contains the input files that are (separately) uploaded to DAFNI.
1212
- `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.
13+
- `dag.dot` is a dot file that contains the directed acyclic graph (dag). In this file, Causal Variables are defined as
14+
node metadata attributes as key-value pairs using the following syntax:
15+
`node [datatype="int", typestring="input"]`. The `datatype` key specifies the datatype of the causal variable
16+
as a string (e.g. `"int"`, `"str"`) and the `typestring` key specifies its typestring, which is also a string
17+
representing the variable type (e.g. `"input"` or `"output"`).
18+
- `runtime_data.csv` is the `.csv` file that contains the runtime data.
1619

1720
- `outputs` is a folder where the `causal_tests_results.json` output file is created.
1821

1922
### Docker files
20-
- `main_dafni.py` is the entry-point to the causal testing framework that is used by Docker.
2123
- `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.
24+
- `Dockerfile` is the main blueprint that builds the image. The main command calls the `causal_testing` module,
25+
with specified paths for the DAG, input runtime data, test configurations, and the output filename as defined above.
26+
This command is identical to that referenced in the main [README.md](../README.md) file.
2627
- `docker-compose.yaml` is another method of building the image and running the container in one line.
2728
Note: the `.env` file that contains the environment variables for `main_dafni.py` is only used here.
29+
- `.dockerignore` tells the Dockerfile which files to not include in the image.
30+
- `.env` is an example of a configuration file containing the environment variables. This is only required
31+
if using `docker-compose` to build the image.
2832

2933

dafni/data/inputs/causal_tests.json

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,11 @@
11
{
22
"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-
},
483
{
494
"name": "vaccine --> cum_vaccinations",
505
"estimator": "LinearRegressionEstimator",
516
"estimate_type": "coefficient",
527
"effect": "direct",
53-
"mutations": [
54-
"vaccine"
55-
],
8+
"treatment_variable": "vaccine",
569
"expected_effect": {
5710
"cum_vaccinations": "SomeEffect"
5811
},
@@ -64,9 +17,7 @@
6417
"estimator": "LinearRegressionEstimator",
6518
"estimate_type": "coefficient",
6619
"effect": "direct",
67-
"mutations": [
68-
"vaccine"
69-
],
20+
"treatment_variable": "vaccine",
7021
"expected_effect": {
7122
"cum_vaccinated": "SomeEffect"
7223
},
@@ -78,9 +29,7 @@
7829
"estimator": "LinearRegressionEstimator",
7930
"estimate_type": "coefficient",
8031
"effect": "direct",
81-
"mutations": [
82-
"vaccine"
83-
],
32+
"treatment_variable": "vaccine",
8433
"expected_effect": {
8534
"cum_infections": "SomeEffect"
8635
},
@@ -92,9 +41,7 @@
9241
"estimator": "LinearRegressionEstimator",
9342
"estimate_type": "coefficient",
9443
"effect": "direct",
95-
"mutations": [
96-
"cum_vaccinations"
97-
],
44+
"treatment_variable": "cum_vaccinations",
9845
"expected_effect": {
9946
"cum_vaccinated": "NoEffect"
10047
},
@@ -107,9 +54,7 @@
10754
"estimator": "LinearRegressionEstimator",
10855
"estimate_type": "coefficient",
10956
"effect": "direct",
110-
"mutations": [
111-
"cum_vaccinations"
112-
],
57+
"treatment_variable": "cum_vaccinations",
11358
"expected_effect": {
11459
"cum_infections": "NoEffect"
11560
},
@@ -122,9 +67,7 @@
12267
"estimator": "LinearRegressionEstimator",
12368
"estimate_type": "coefficient",
12469
"effect": "direct",
125-
"mutations": [
126-
"cum_vaccinated"
127-
],
70+
"treatment_variable": "cum_vaccinated",
12871
"expected_effect": {
12972
"cum_infections": "NoEffect"
13073
},

dafni/data/inputs/dag.dot

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
digraph CausalDAG {
22
rankdir=LR;
3-
"vaccine" -> "cum_vaccinations";
4-
"vaccine" -> "cum_vaccinated";
5-
"vaccine" -> "cum_infections";
6-
"max_doses";
3+
vaccine [datatype="int", typestring="input"];
4+
cum_vaccinations [datatype="int", typestring="output"];
5+
cum_vaccinated [datatype="int", typestring="output"];
6+
cum_infections [datatype="int", typestring="output"];
7+
max_doses [datatype="int", typestring="output"];
8+
vaccine -> cum_vaccinations;
9+
vaccine -> cum_vaccinated;
10+
vaccine -> cum_infections;
11+
max_doses;
712
}

dafni/data/inputs/variables.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)