Skip to content

Commit 38ef8d8

Browse files
committed
small tweaks
1 parent c67cb75 commit 38ef8d8

10 files changed

Lines changed: 146 additions & 62 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
5151
- name: Build the container
5252
run: |
53-
docker build -t ctf:${{ env.VERSION }} -f ./dafni/Dockerfile .
53+
docker build --no-cache -t ctf:${{ env.VERSION }} -f ./dafni/Dockerfile .
5454
docker save ctf:${{ env.VERSION }} | gzip > ctf-dafni-${{ env.VERSION }}.tar.gz
5555
5656
- name: Log into DAFNI

dafni/.env

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
#.env
2-
DAG_PATH=./data/inputs/dag.dot
3-
CAUSAL_TESTS=./data/inputs/causal_tests.json
4-
DATA_PATH=./data/inputs/runtime_data.csv
5-
CAUSAL_TEST_RESULTS=./data/outputs/causal_test_results.json
62

7-
EXECUTION_MODE=auto
3+
# The default file names environment variables for the DAFNI parameters
4+
CAUSAL_TESTS=causal_tests.json
5+
CAUSAL_TEST_RESULTS=causal_test_results.json
6+
7+
# The default generate and test environment variables for the DAFNI parameters
8+
EXECUTION_MODE=test
89
ESTIMATOR=LinearRegressionEstimator
910
EFFECT_TYPE=direct
1011
ESTIMATE_TYPE=coefficient
1112
THREADS=0
1213
IGNORE_CYCLES=false
1314
VERBOSE=false
14-
QUERY=
15+
QUERY=None
1516
ADEQUACY=false
1617
BOOTSTRAP_SIZE=100
1718
SILENT=false

dafni/Dockerfile

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,25 @@
1-
# Define the Python version neded for CTF
21
FROM python:3.12-slim
32

4-
## Prevents Python from writing pyc files
53
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
4+
95
ENV PYTHONUNBUFFERED=1
106

11-
# Label maintainer
127
LABEL maintainer="Dr. Neil Walkinshaw - The University of Sheffield"
138

14-
# Create a folder for the source code/outputs
15-
RUN mkdir -p ./causal_testing
16-
RUN mkdir -p ./data/outputs
9+
WORKDIR /
10+
11+
# Copy source code
12+
COPY causal_testing /causal_testing
13+
14+
# Set PYTHONPATH
15+
ENV PYTHONPATH="/causal_testing:${PYTHONPATH}"
1716

18-
# Copy the source code from local root and test files from build into the container
19-
COPY --chown=nobody ./causal_testing ./causal_testing
20-
COPY --chown=nobody ./dafni/data/inputs ./data/inputs
17+
# Install dependencies
18+
RUN pip install --no-cache-dir causal-testing-framework
2119

22-
# Copy your entrypoint script
20+
# Copy entrypoint
2321
COPY dafni/entrypoint.sh /entrypoint.sh
24-
RUN chmod +x /entrypoint.sh
2522

26-
# Install core dependencies using PyPi
27-
RUN pip install causal-testing-framework --no-cache-dir
23+
RUN chmod +x /entrypoint.sh
2824

29-
# Define the entrypoint/commands
3025
ENTRYPOINT ["/entrypoint.sh"]
File renamed without changes.
File renamed without changes.

dafni/data/outputs/causal_test_results.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@
103103
],
104104
"effect_measure": "coefficient",
105105
"effect_estimate": {
106-
"cum_vaccinations": 0.9998656401531978
106+
"cum_vaccinations": 0.9998656401531969
107107
},
108108
"ci_low": {
109-
"cum_vaccinations": 0.9929245394500337
109+
"cum_vaccinations": 0.9929245394500371
110110
},
111111
"ci_high": {
112-
"cum_vaccinations": 1.006806740856362
112+
"cum_vaccinations": 1.0068067408563566
113113
}
114114
}
115115
},
@@ -133,13 +133,13 @@
133133
],
134134
"effect_measure": "coefficient",
135135
"effect_estimate": {
136-
"cum_vaccinations": -0.006416682407512808
136+
"cum_vaccinations": -0.006416682407513252
137137
},
138138
"ci_low": {
139-
"cum_vaccinations": -0.056630100838863134
139+
"cum_vaccinations": -0.05663010083886358
140140
},
141141
"ci_high": {
142-
"cum_vaccinations": 0.04379673602383752
142+
"cum_vaccinations": 0.043796736023837074
143143
}
144144
}
145145
},

dafni/docker-compose.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ services:
66
env_file:
77
- .env
88
volumes:
9-
- .:/usr/src/
9+
- ./data/inputs:/data/inputs:ro
10+
- ./data/outputs:/data/outputs

dafni/entrypoint.sh

Lines changed: 109 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
11
#!/bin/sh
22
set -e
33

4-
# Auto-detect mode if EXECUTION_MODE=auto
4+
INPUT_DIR="data/inputs"
5+
OUTPUT_DIR="data/outputs"
6+
7+
# --------------------------
8+
# DEBUG ENVIRONMENT VARIABLES
9+
# --------------------------
10+
echo "=== DEBUG: Environment Variables ==="
11+
echo "ADEQUACY: '$ADEQUACY'"
12+
echo "BOOTSTRAP_SIZE: '$BOOTSTRAP_SIZE'"
13+
echo "EXECUTION_MODE: '$EXECUTION_MODE'"
14+
echo "VERBOSE: '$VERBOSE'"
15+
echo "===================================="
16+
17+
# --------------------------
18+
# Discover the DAGs first (.dot)
19+
# --------------------------
20+
DAG_FILES=$(find "$INPUT_DIR/dag-data" -name "*.dot" 2>/dev/null || true)
21+
22+
if [ -z "$DAG_FILES" ]; then
23+
echo "ERROR: No .dot DAG file found in $INPUT_DIR/dag-data"
24+
exit 1
25+
fi
26+
27+
set -- $DAG_FILES
28+
if [ "$#" -ne 1 ]; then
29+
echo "ERROR: Expected exactly one DAG (.dot) file, found $#"
30+
exit 1
31+
fi
32+
33+
DAG_PATH="$1"
34+
echo "Using DAG file: $DAG_PATH"
35+
36+
# --------------------------
37+
# Discover runtime CSV data (can be multiple)
38+
# --------------------------
39+
DATA_PATHS=$(find "$INPUT_DIR/runtime-data" -name "*.csv" 2>/dev/null || true)
40+
41+
if [ -z "$DATA_PATHS" ]; then
42+
echo "ERROR: No runtime CSV files found in $INPUT_DIR/runtime-data"
43+
exit 1
44+
fi
45+
46+
echo "Found CSV files: $DATA_PATHS"
47+
48+
# Causal tests path for checking if it exists in inputs
49+
CAUSAL_TESTS_INPUT_PATH="$INPUT_DIR/causal-tests/$CAUSAL_TESTS"
50+
# Causal tests path for writing (generate mode)
51+
CAUSAL_TESTS_OUTPUT_PATH="$OUTPUT_DIR/$CAUSAL_TESTS"
52+
# Results path (test mode)
53+
CAUSAL_TEST_RESULTS_PATH="$OUTPUT_DIR/$CAUSAL_TEST_RESULTS"
54+
55+
# --------------------------
56+
# Auto-detect mode
57+
# --------------------------
558
if [ "$EXECUTION_MODE" = "auto" ]; then
6-
if [ -f "$CAUSAL_TESTS" ]; then
59+
if [ -d "$INPUT_DIR/causal-tests" ] && [ -f "$CAUSAL_TESTS_INPUT_PATH" ]; then
760
EXECUTION_MODE="test"
8-
echo "Auto mode: causal_tests.json found -> running TEST mode"
61+
echo "Auto mode: causal tests found in inputs -> running TEST mode"
962
else
1063
EXECUTION_MODE="generate"
11-
echo "Auto mode: No causal tests found -> running GENERATE mode"
64+
echo "Auto mode: no causal tests found in inputs -> running GENERATE mode"
1265
fi
1366
else
1467
echo "Execution mode explicitly set to: $EXECUTION_MODE"
@@ -19,34 +72,65 @@ fi
1972
# --------------------------
2073
if [ "$EXECUTION_MODE" = "generate" ]; then
2174
echo "Running causal_testing GENERATE..."
75+
echo "Will write causal tests to: $CAUSAL_TESTS_OUTPUT_PATH"
76+
2277
python -m causal_testing generate \
23-
--dag-path "$DAG_PATH" \
24-
--output "$CAUSAL_TESTS" \
25-
--estimator "$ESTIMATOR" \
26-
--effect-type "$EFFECT_TYPE" \
27-
--estimate-type "$ESTIMATE_TYPE" \
28-
$( [ "$IGNORE_CYCLES" = "true" ] && echo "--ignore-cycles" ) \
29-
--threads "$THREADS"
78+
-D "$DAG_PATH" \
79+
-o "$CAUSAL_TESTS_OUTPUT_PATH" \
80+
-e "$ESTIMATOR" \
81+
-T "$EFFECT_TYPE" \
82+
-E "$ESTIMATE_TYPE" \
83+
-t "$THREADS" \
84+
$([ "$IGNORE_CYCLES" = "true" ] && echo "-i")
3085

3186
# --------------------------
3287
# Test mode
3388
# --------------------------
3489
elif [ "$EXECUTION_MODE" = "test" ]; then
35-
if [ ! -f "$CAUSAL_TESTS" ]; then
36-
echo "Error: Causal tests file not found at $CAUSAL_TESTS"
90+
if [ ! -f "$CAUSAL_TESTS_INPUT_PATH" ]; then
91+
echo "ERROR: Causal tests file not found at $CAUSAL_TESTS_INPUT_PATH"
3792
exit 1
3893
fi
3994

4095
echo "Running causal_testing TEST..."
41-
python -m causal_testing test \
42-
--dag-path "$DAG_PATH" \
43-
--data-paths "$DATA_PATH" \
44-
--test-config "$CAUSAL_TESTS" \
45-
--output "$CAUSAL_TEST_RESULTS" \
46-
$( [ "$IGNORE_CYCLES" = "true" ] && echo "--ignore-cycles" ) \
47-
$( [ "$VERBOSE" = "true" ] && echo "--verbose" ) \
48-
$( [ -n "$QUERY" ] && echo "--query" "$QUERY" ) \
49-
$( [ "$ADEQUACY" = "true" ] && echo "--adequacy --adequacy-bootstrap-size $BOOTSTRAP_SIZE" ) \
50-
$( [ "$SILENT" = "true" ] && echo "--silent" ) \
51-
$( [ "$BATCH_SIZE" != "0" ] && echo "--batch-size $BATCH_SIZE" )
52-
fi
96+
echo "Using causal tests from: $CAUSAL_TESTS_INPUT_PATH"
97+
98+
# DEBUG: Show which branch we're taking
99+
echo "=== DEBUG: Adequacy Check ==="
100+
if [ "$ADEQUACY" = "true" ]; then
101+
echo "ADEQUACY is TRUE - will pass -a -b $BOOTSTRAP_SIZE"
102+
else
103+
echo "ADEQUACY is FALSE - will NOT pass -a -b flags"
104+
fi
105+
echo "============================="
106+
107+
# Build command with adequacy flags only when ADEQUACY is true
108+
if [ "$ADEQUACY" = "true" ]; then
109+
echo "DEBUG: Executing WITH adequacy flags"
110+
python -m causal_testing test \
111+
-D "$DAG_PATH" \
112+
-d $DATA_PATHS \
113+
-t "$CAUSAL_TESTS_INPUT_PATH" \
114+
-o "$CAUSAL_TEST_RESULTS_PATH" \
115+
$([ "$IGNORE_CYCLES" = "true" ] && echo "-i") \
116+
$([ "$VERBOSE" = "true" ] && echo "-v") \
117+
$([ -n "$QUERY" ] && [ "$QUERY" != "None" ] && echo "-q '$QUERY'") \
118+
-a -b $BOOTSTRAP_SIZE \
119+
$([ "$SILENT" = "true" ] && echo "-s") \
120+
$([ "$BATCH_SIZE" != "0" ] && echo "--batch-size $BATCH_SIZE")
121+
else
122+
echo "DEBUG: Executing WITHOUT adequacy flags"
123+
python -m causal_testing test \
124+
-D "$DAG_PATH" \
125+
-d $DATA_PATHS \
126+
-t "$CAUSAL_TESTS_INPUT_PATH" \
127+
-o "$CAUSAL_TEST_RESULTS_PATH" \
128+
$([ "$IGNORE_CYCLES" = "true" ] && echo "-i") \
129+
$([ "$VERBOSE" = "true" ] && echo "-v") \
130+
$([ -n "$QUERY" ] && [ "$QUERY" != "None" ] && echo "-q '$QUERY'") \
131+
$([ "$SILENT" = "true" ] && echo "-s") \
132+
$([ "$BATCH_SIZE" != "0" ] && echo "--batch-size $BATCH_SIZE")
133+
fi
134+
fi
135+
136+
echo "Execution completed successfully"

dafni/model_definition.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,31 @@ spec:
143143
A .csv file containing the input runtime data to be used
144144
default:
145145
- 2b7336cd-eb68-4c1f-8f91-26d8969b8cb3
146-
path: inputs/
146+
path: inputs/runtime-data
147147
required: true
148148

149149
- name: DAG data
150150
description: >
151151
A .dot file containing the input DAG to be used
152152
default:
153153
- 74665fdb-43a2-4c51-b81e-d5299b38bf8c
154-
path: inputs/
154+
path: inputs/dag-data
155155
required: true
156156

157157
- name: Causal tests
158158
description: >
159159
A .JSON file containing the input causal tests to be used. This file can also be generated using the input DAG.
160-
default:
161-
- 6f2f7c1f-81b4-4804-8f86-cca304dc7f66
162-
path: inputs/
160+
path: inputs/causal-tests
163161
required: false
164162

165163
outputs:
166164
datasets:
165+
- name: causal_tests.json
166+
type: json
167+
description: >
168+
Generated causal tests from the DAG. Created when running in generate mode or auto mode (when no causal tests are provided).
169+
167170
- name: causal_test_results.json
168171
type: json
169172
description: >
170-
A JSON file containing the output causal test results.
173+
Results from executing causal tests. Created when running in test mode or auto mode (when causal tests are provided).

0 commit comments

Comments
 (0)