Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/evalml/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ class RunConfig(BaseModel):
False,
description="If true, the ECCODES_DEFINITION_PATH environment variable will not be set to the COSMO local definitions.",
)
squash_venv: bool = Field(
True,
description="If true (default), package the virtual environment as a squashfs image before running inference. "
"Set to false to activate the virtual environment directly and skip the squashfs build step.",
)

config: Dict[str, Any] | str

Expand Down
26 changes: 19 additions & 7 deletions workflow/rules/inference.smk
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,11 @@ def _inference_routing_fn(wc):
rule inference_execute:
input:
okfile=_inference_routing_fn,
image=lambda wc: OUT_ROOT
/ f"data/runs/{RUN_CONFIGS[wc.run_id]['env_id']}/venv.squashfs",
env=lambda wc: (
OUT_ROOT / f"data/runs/{RUN_CONFIGS[wc.run_id]['env_id']}/venv.squashfs"
if RUN_CONFIGS[wc.run_id].get("squash_venv", True)
else OUT_ROOT / f"data/runs/{RUN_CONFIGS[wc.run_id]['env_id']}/.venv"
),
output:
okfile=touch(OUT_ROOT / "logs/inference_execute/{run_id}-{init_time}.ok"),
log:
Expand All @@ -283,7 +286,8 @@ rule inference_execute:
ntasks=lambda wc: get_resource(wc, "tasks", 1),
gpus=lambda wc: get_resource(wc, "gpu", 1),
params:
image_path=lambda wc, input: f"{Path(input.image).resolve()}",
env_path=lambda wc, input: f"{Path(input.env).resolve()}",
squash_venv=lambda wc: RUN_CONFIGS[wc.run_id].get("squash_venv", True),
workdir=lambda wc: (
OUT_ROOT / f"data/runs/{wc.run_id}/{wc.init_time}"
).resolve(),
Expand All @@ -298,11 +302,12 @@ rule inference_execute:

cd {params.workdir}

squashfs-mount {params.image_path}:/user-environment -- bash -c '
source /user-environment/bin/activate
_run_inference() {{
local VENV=$1
source "$VENV/bin/activate"

if [ "{params.disable_local_definitions}" = "False" ]; then
export ECCODES_DEFINITION_PATH=/user-environment/share/eccodes-cosmo-resources/definitions
export ECCODES_DEFINITION_PATH="$VENV/share/eccodes-cosmo-resources/definitions"
fi

CMD_ARGS=()
Expand All @@ -321,7 +326,14 @@ rule inference_execute:
--gres={resources.gres} \
--ntasks={resources.ntasks} \
anemoi-inference run config.yaml "${{CMD_ARGS[@]}}"
'
}}
export -f _run_inference

if [ "{params.squash_venv}" = "True" ]; then
squashfs-mount {params.env_path}:/user-environment -- bash -c '_run_inference /user-environment'
else
_run_inference "{params.env_path}"
fi

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmh I'm not really happy with all this code duplication. Can we try avoid it?

@lclanzi lclanzi Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in latest commit

) >{log} 2>&1
"""
# fmt: on
12 changes: 12 additions & 0 deletions workflow/tools/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@
"title": "Disable Local Eccodes Definitions",
"type": "boolean"
},
"squash_venv": {
"default": true,
"description": "If true (default), package the virtual environment as a squashfs image before running inference. Set to false to activate the virtual environment directly and skip the squashfs build step.",
"title": "Squash Venv",
"type": "boolean"
},
"config": {
"anyOf": [
{
Expand Down Expand Up @@ -733,6 +739,12 @@
"title": "Disable Local Eccodes Definitions",
"type": "boolean"
},
"squash_venv": {
"default": true,
"description": "If true (default), package the virtual environment as a squashfs image before running inference. Set to false to activate the virtual environment directly and skip the squashfs build step.",
"title": "Squash Venv",
"type": "boolean"
},
"config": {
"anyOf": [
{
Expand Down
Loading