Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .github/workflows/publish-to-dafni.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ jobs:
- name: Get release version
id: get_release
run: |
# Extract the version without the 'v' prefix using regex
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/')
# Extract only the major version from the latest release tag
export VERSION=$(curl -sSL https://api.github.com/repos/CITCOM-project/CausalTestingFramework/releases/latest \
| jq -r '.tag_name' \
| sed -E 's/^v?([0-9]+).*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT

build_and_upload:
Expand All @@ -35,6 +37,7 @@ jobs:

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v3
with:
python-version: '3.10'
Expand All @@ -45,22 +48,19 @@ jobs:
python -m pip install causal-testing-framework -e .[dev]
python -m pip install dafni-cli

- name: Check if unit tests are passing first
id: tests
uses: ./.github/workflows/ci-tests.yml

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


- name: Log into DAFNI
run: |
dafni login

- name: Upload to DAFNI
run: |
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
dafni logout
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
dafni logout
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
![example workflow](https://github.com/CITCOM-project/CausalTestingFramework/actions/workflows/ci-tests.yaml/badge.svg)
![CI tests](https://github.com/CITCOM-project/CausalTestingFramework/actions/workflows/ci-tests.yaml/badge.svg)
[![codecov](https://codecov.io/gh/CITCOM-project/CausalTestingFramework/branch/main/graph/badge.svg?token=04ijFVrb4a)](https://codecov.io/gh/CITCOM-project/CausalTestingFramework)
[![Documentation Status](https://readthedocs.org/projects/causal-testing-framework/badge/?version=latest)](https://causal-testing-framework.readthedocs.io/en/latest/?badge=latest)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/CITCOM-project/CausalTestingFramework)
Expand Down Expand Up @@ -76,7 +76,7 @@ git checkout tags/<tag> -b <branch>
pip install . # For core API only
pip install -e . # For editable install, useful for development work
```
For more information on how to use the Causal Testing Framework, please refer to our [documentation](https://causal-testing-framework.readthedocs.io/en/latest/?badge=latest).
For more information on how to use the Causal Testing Framework, please refer to our [documentation](https://causal-testing-framework.readthedocs.io/en/latest/?badge=latest). If you have any questions, you can also reach us by [email]([email protected]).

>[!NOTE]
>We recommend you use a 64-bit OS (standard in most modern machines) as we have had reports of the installation crashing on legacy 32-bit Debian systems.
Expand All @@ -89,12 +89,12 @@ For more information on how to use the Causal Testing Framework, please refer to

2. If you do not already have causal test cases, you can convert your causal DAG to causal tests by running the following command.
```
python -m causal_testing generate --dag_path $PATH_TO_DAG --output_path $PATH_TO_TESTS
python -m causal_testing generate --dag-path $PATH_TO_DAG --output $PATH_TO_TESTS
```

3. You can now execute your tests by running the following command.
```
python -m causal_testing test --dag_path $PATH_TO_DAG --data_paths $PATH_TO_DATA --test_config $PATH_TO_TESTS --output $OUTPUT
python -m causal_testing test --dag-path $PATH_TO_DAG --data-paths $PATH_TO_DATA --test-config $PATH_TO_TESTS --output $OUTPUT
```
The results will be saved for inspection in a JSON file located at `$OUTPUT`.
In the future, we hope to add a visualisation tool to assist with this.
Expand Down Expand Up @@ -151,4 +151,4 @@ and the software citation should contain the specific Figshare [DOI](https://ord

The Causal Testing Framework is supported by the UK's Engineering and Physical Sciences Research Council (EPSRC),
with the project name [CITCOM](https://gtr.ukri.org/projects?ref=EP%2FT030526%2F1) - "_Causal Inference for Testing of Computational Models_"
under the grant EP/T030526/1.
under the grant EP/T030526/1.
24 changes: 20 additions & 4 deletions dafni/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#.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

# The default file names environment variables for the DAFNI parameters
CAUSAL_TESTS=causal_tests.json
CAUSAL_TEST_RESULTS=causal_test_results.json

# The default generate and test environment variables for the DAFNI parameters
EXECUTION_MODE=test
ESTIMATOR=LinearRegressionEstimator
EFFECT_TYPE=direct
ESTIMATE_TYPE=coefficient
THREADS=0
IGNORE_CYCLES=false
VERBOSE=false
QUERY=None
ADEQUACY=false
BOOTSTRAP_SIZE=100
SILENT=false
BATCH_SIZE=0


34 changes: 15 additions & 19 deletions dafni/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
# Define the Python version neded for CTF
FROM python:3.12-slim

## Prevents Python from writing pyc files
ENV PYTHONDONTWRITEBYTECODE=1
#
## Keeps Python from buffering stdout and stderr to avoid the framework
## from crashing without emitting any logs due to buffering
ENV PYTHONUNBUFFERED=1

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

# Create a folder for the source code/outputs
RUN mkdir -p ./causal_testing
RUN mkdir -p ./data/outputs
LABEL maintainer="Dr. Neil Walkinshaw - The University of Sheffield"

# 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/data/inputs ./data/inputs
WORKDIR /

# Install core dependencies using PyPi
RUN pip install causal-testing-framework --no-cache-dir
# Copy source code
COPY causal_testing /causal_testing

# Set the PYTHONPATH environment variable to include the /src directory
# Set PYTHONPATH
ENV PYTHONPATH="/causal_testing:${PYTHONPATH}"

# Define the entrypoint/commands
CMD python -m causal_testing --dag_path $DAG_PATH --data_path $DATA_PATH --test_config $TESTS_PATH --output $OUTPUT
# Install dependencies
RUN pip install --no-cache-dir causal-testing-framework

# Copy entrypoint
COPY dafni/entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
47 changes: 25 additions & 22 deletions dafni/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
# Causal Testing Framework on DAFNI

- This directory contains the containerisation files of the causal testing framework using Docker, which is used
to upload the framework onto [DAFNI](https://www.dafni.ac.uk).
to upload the framework onto [DAFNI](https://www.dafni.ac.uk).
- It is **not** recommended to install the causal testing framework using Docker, and should only be installed
using [PyPI](https://pypi.org/project/causal-testing-framework/).
using [conda-forge](https://anaconda.org/channels/conda-forge/packages/causal-testing-framework/overview) or [PyPI](https://pypi.org/project/causal-testing-framework/).

### Directory Hierarchy

- `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.
- `dag.dot` is a dot file that contains the directed acyclic graph (dag). In this file, Causal Variables are defined as
node metadata attributes 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 the `.csv` file that contains the runtime data.
- `data` contains two folders (structure is critical for DAFNI workflows):
- `inputs` contains all input files that are uploaded to DAFNI.
- `causal_tests.json` is a JSON file containing generated causal tests. If it exists, the framework can automatically run tests without regenerating.
- `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:
`node [datatype="int", typestring="input"]`
- `datatype` specifies the variable's data type (e.g., `"int"`, `"str"`).
- `typestring` specifies whether the variable is an `"input"` or `"output"`.
- `runtime_data.csv` contains the input runtime data for testing.
- `outputs` is the folder where `causal_test_results.json` is created after running tests.

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

### Docker files
- `model_definition.yaml` is the model metadata that is required to be uploaded to DAFNI.
- `Dockerfile` is the main blueprint that builds the image. The main command calls the `causal_testing` module,
with specified paths for the DAG, input runtime data, test configurations, and the output filename as defined above.
This command is identical to that referenced in the main [README.md](../README.md) file.
- `docker-compose.yaml` is another method of building the image and running the container in one line.
Note: the `.env` file that contains the environment variables for `main_dafni.py` is only used here.
- `.dockerignore` tells the Dockerfile which files to not include in the image.
- `.env` is an example of a configuration file containing the environment variables. This is only required
if using `docker-compose` to build the image.
- The `entrypoint.sh` script now supports auto-detection:
- If `causal_tests.json` exists in `data/inputs`, the script automatically runs the test mode.
- If it does not exist, the script generates the causal tests first.
- The user can still override this behaviour by setting `EXECUTION_MODE` explicitly in the `.env` file.
- 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.
- Input/output directories are fixed as `data/inputs` and `data/outputs` to comply with DAFNI requirements.
- 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.

### Docker files

- `model_definition.yaml` is the model metadata required for DAFNI.
- `Dockerfile` builds the container image and uses `entrypoint.sh` as the main entrypoint. All paths and options are now configurable via `.env`.
- `docker-compose.yaml` allows building and running the container with a single command. The `.env` file is required here to define all environment variables.
- `.dockerignore` specifies files to exclude from the Docker image.
- `.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`.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"effect_estimate": {
"vaccine": 315785.1333333332
},
"ci_low": [
315339.1666500188
],
"ci_high": [
316231.1000166476
]
"ci_low": {
"vaccine": 315339.1666500188
},
"ci_high": {
"vaccine": 316231.1000166476
}
}
},
{
Expand All @@ -45,14 +45,14 @@
"adjustment_set": [],
"effect_measure": "coefficient",
"effect_estimate": {
"vaccine": 266389.91666666657
"vaccine": 266389.9166666665
},
"ci_low": [
265943.93821015797
],
"ci_high": [
266835.89512317517
]
"ci_low": {
"vaccine": 265943.9382101579
},
"ci_high": {
"vaccine": 266835.8951231751
}
}
},
{
Expand All @@ -75,12 +75,12 @@
"effect_estimate": {
"vaccine": 3332.883333333332
},
"ci_low": [
3274.9650508109467
],
"ci_high": [
3390.801615855717
]
"ci_low": {
"vaccine": 3274.9650508109467
},
"ci_high": {
"vaccine": 3390.801615855717
}
}
},
{
Expand All @@ -103,14 +103,14 @@
],
"effect_measure": "coefficient",
"effect_estimate": {
"cum_vaccinations": 0.9998656401531605
"cum_vaccinations": 0.9998656401531969
},
"ci_low": [
0.9929245394499968
],
"ci_high": [
1.0068067408563242
]
"ci_low": {
"cum_vaccinations": 0.9929245394500371
},
"ci_high": {
"cum_vaccinations": 1.0068067408563566
}
}
},
{
Expand All @@ -133,14 +133,14 @@
],
"effect_measure": "coefficient",
"effect_estimate": {
"cum_vaccinations": -0.006416682407515084
"cum_vaccinations": -0.006416682407513252
},
"ci_low": [
-0.05663010083886572
],
"ci_high": [
0.043796736023835554
]
"ci_low": {
"cum_vaccinations": -0.05663010083886358
},
"ci_high": {
"cum_vaccinations": 0.043796736023837074
}
}
},
{
Expand All @@ -163,14 +163,14 @@
],
"effect_measure": "coefficient",
"effect_estimate": {
"cum_vaccinated": -0.006176900588291234
"cum_vaccinated": -0.00617690058829258
},
"ci_low": [
-0.05639349612119588
],
"ci_high": [
0.04403969494461341
]
"ci_low": {
"cum_vaccinated": -0.056393496121197616
},
"ci_high": {
"cum_vaccinated": 0.044039694944612455
}
}
}
]
3 changes: 2 additions & 1 deletion dafni/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ services:
env_file:
- .env
volumes:
- .:/usr/src/
- ./data/inputs:/data/inputs:ro
- ./data/outputs:/data/outputs
Loading