Skip to content

Commit 81abffb

Browse files
committed
fix: updated DAFNI config and workflows
1 parent d274678 commit 81abffb

10 files changed

Lines changed: 227 additions & 301 deletions

File tree

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ jobs:
1818
- name: Get release version
1919
id: get_release
2020
run: |
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/')
21+
# Extract only the major version from the latest release tag
22+
export VERSION=$(curl -sSL https://api.github.com/repos/CITCOM-project/CausalTestingFramework/releases/latest \
23+
| jq -r '.tag_name' \
24+
| sed -E 's/^v?([0-9]+).*/\1/')
2325
echo "version=$VERSION" >> $GITHUB_OUTPUT
2426
2527
build_and_upload:
@@ -35,6 +37,7 @@ jobs:
3537

3638
steps:
3739
- uses: actions/checkout@v3
40+
3841
- uses: actions/setup-python@v3
3942
with:
4043
python-version: '3.10'
@@ -45,22 +48,19 @@ jobs:
4548
python -m pip install causal-testing-framework -e .[dev]
4649
python -m pip install dafni-cli
4750
48-
- name: Check if unit tests are passing first
49-
id: tests
50-
uses: ./.github/workflows/ci-tests.yml
51-
5251
- name: Build the container
53-
if: success() && steps.tests.outcome == 'success'
5452
run: |
5553
docker build -t ctf:${{ env.VERSION }} -f ./dafni/Dockerfile .
5654
docker save ctf:${{ env.VERSION }} | gzip > ctf-dafni-${{ env.VERSION }}.tar.gz
5755
58-
5956
- name: Log into DAFNI
6057
run: |
6158
dafni login
6259
6360
- name: Upload to DAFNI
6461
run: |
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
62+
dafni upload model ./dafni/model_definition.yaml \
63+
ctf-dafni-${{ env.VERSION }}.tar.gz \
64+
--version-message "Causal Testing Framework v${{ env.VERSION }}. Uploaded via Github Actions." \
65+
--parent-id ${{ env.DAFNI_PARENT_ID }} -y
66+
dafni logout

dafni/.env

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
#.env
2-
VARIABLES_PATH=./data/inputs/variables.json
2+
DAG_PATH=./data/inputs/dag.dot
33
CAUSAL_TESTS=./data/inputs/causal_tests.json
44
DATA_PATH=./data/inputs/runtime_data.csv
5-
DAG_PATH=./data/inputs/dag.dot
5+
CAUSAL_TEST_RESULTS=./data/outputs/causal_test_results.json
6+
7+
EXECUTION_MODE=auto
8+
ESTIMATOR=LinearRegressionEstimator
9+
EFFECT_TYPE=direct
10+
ESTIMATE_TYPE=coefficient
11+
THREADS=0
12+
IGNORE_CYCLES=false
13+
VERBOSE=false
14+
QUERY=
15+
ADEQUACY=false
16+
BOOTSTRAP_SIZE=100
17+
SILENT=false
18+
BATCH_SIZE=0
19+
20+

dafni/Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV PYTHONDONTWRITEBYTECODE=1
99
ENV PYTHONUNBUFFERED=1
1010

1111
# Label maintainer
12-
LABEL maintainer="Dr. Farhad Allian - The University of Sheffield"
12+
LABEL maintainer="Dr. Neil Walkinshaw - The University of Sheffield"
1313

1414
# Create a folder for the source code/outputs
1515
RUN mkdir -p ./causal_testing
@@ -19,11 +19,12 @@ RUN mkdir -p ./data/outputs
1919
COPY --chown=nobody ./causal_testing ./causal_testing
2020
COPY --chown=nobody ./dafni/data/inputs ./data/inputs
2121

22+
# Copy your entrypoint script
23+
COPY dafni/entrypoint.sh /entrypoint.sh
24+
RUN chmod +x /entrypoint.sh
25+
2226
# Install core dependencies using PyPi
2327
RUN pip install causal-testing-framework --no-cache-dir
2428

25-
# Set the PYTHONPATH environment variable to include the /src directory
26-
ENV PYTHONPATH="/causal_testing:${PYTHONPATH}"
27-
2829
# Define the entrypoint/commands
29-
CMD python -m causal_testing --dag_path $DAG_PATH --data_path $DATA_PATH --test_config $TESTS_PATH --output $OUTPUT
30+
ENTRYPOINT ["/entrypoint.sh"]

dafni/README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
# Causal Testing Framework on DAFNI
22

33
- 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).
4+
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
6-
using [PyPI](https://pypi.org/project/causal-testing-framework/).
6+
using [conda-forge](https://anaconda.org/channels/conda-forge/packages/causal-testing-framework/overview) or [PyPI](https://pypi.org/project/causal-testing-framework/).
77

88
### Directory Hierarchy
99

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-
- `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.
10+
- `data` contains two folders (structure is critical for DAFNI workflows):
11+
- `inputs` contains all input files that are uploaded to DAFNI.
12+
- `causal_tests.json` is a JSON file containing generated causal tests. If it exists, the framework can automatically run tests without regenerating.
13+
- `dag.dot` is a DOT file defining the directed acyclic graph (DAG). Causal variables are stored in node metadata as key-value pairs using the syntax:
14+
`node [datatype="int", typestring="input"]`
15+
- `datatype` specifies the variable's data type (e.g., `"int"`, `"str"`).
16+
- `typestring` specifies whether the variable is an `"input"` or `"output"`.
17+
- `runtime_data.csv` contains the input runtime data for testing.
18+
- `outputs` is the folder where `causal_test_results.json` is created after running tests.
1919

20-
- `outputs` is a folder where the `causal_tests_results.json` output file is created.
20+
### Workflow
2121

22-
### Docker files
23-
- `model_definition.yaml` is the model metadata that is required to be uploaded to DAFNI.
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.
27-
- `docker-compose.yaml` is another method of building the image and running the container in one line.
28-
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.
22+
- The `entrypoint.sh` script now supports auto-detection:
23+
- If `causal_tests.json` exists in `data/inputs`, the script automatically runs the test mode.
24+
- If it does not exist, the script generates the causal tests first.
25+
- The user can still override this behaviour by setting `EXECUTION_MODE` explicitly in the `.env` file.
26+
- Filenames for `causal_tests.json` and `causal_test_results.json` are now configurable through environment variables (`CAUSAL_TESTS` and `CAUSAL_TEST_RESULTS`) in the `.env` file.
27+
- Input/output directories are fixed as `data/inputs` and `data/outputs` to comply with DAFNI requirements.
28+
- The script now reads all configuration parameters (estimator, effect type, threads, verbosity, query filters, adequacy metrics, etc.) **from the `.env` file**, keeping the Docker image and container clean and flexible.
3229

30+
### Docker files
3331

32+
- `model_definition.yaml` is the model metadata required for DAFNI.
33+
- `Dockerfile` builds the container image and uses `entrypoint.sh` as the main entrypoint. All paths and options are now configurable via `.env`.
34+
- `docker-compose.yaml` allows building and running the container with a single command. The `.env` file is required here to define all environment variables.
35+
- `.dockerignore` specifies files to exclude from the Docker image.
36+
- `.env` provides all configurable environment variables for the workflow (execution mode, filenames, estimator options, DAG/effects configuration, and runtime options). This is only needed if using `docker-compose`.

dafni/data/inputs/causal_tests.json

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

0 commit comments

Comments
 (0)