Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hailctl] batch submit fixes #14805

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
27 changes: 11 additions & 16 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ steps:
export HAIL_DOCTEST_DATA_DIR=$(realpath ./data)
export HAIL_TEST_STORAGE_URI={{ global.test_storage_uri }}/{{ token }}
export PYSPARK_SUBMIT_ARGS="--driver-memory 6g pyspark-shell"

python3 -m pytest \
-Werror:::hail -Werror:::hailtop -Werror::ResourceWarning \
--log-cli-level=INFO \
Expand All @@ -1037,6 +1038,7 @@ steps:
--durations=50 \
--ignore=test/hailtop/batch/ \
--ignore=test/hailtop/inter_cloud \
--ignore=test/hailtop/hailctl/batch \
--timeout=120 \
test
inputs:
Expand Down Expand Up @@ -2995,7 +2997,8 @@ steps:
--instafail \
--durations=50 \
--timeout=360 \
/io/test/hailtop/batch/
/io/test/hailtop/batch/ /io/test/hailtop/hailctl/batch

inputs:
- from: /repo/hail/python/pytest.ini
to: /io/pytest.ini
Expand Down Expand Up @@ -3060,9 +3063,7 @@ steps:
BATCH_ID=$(hailctl batch submit simple_hail.py --name=test-hailctl-batch-submit --files=foo -o json | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID)
STATE=$(echo $STATUS | jq -jr '.state')
if [ "$STATE" == "success" ]; then
exit 0;
else
if [ "$STATE" != "success" ]; then
echo $STATUS;
exit 1;
fi
Expand All @@ -3081,21 +3082,19 @@ steps:
BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json hail_with_args.py 100 | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID)
STATE=$(echo $STATUS | jq -jr '.state')
if [ "$STATE" == "success" ]; then
exit 0;
else
if [ "$STATE" != "success" ]; then
echo $STATUS;
exit 1;
fi

cat >file.sh <<EOF
cat > file.sh << 'EOF'
set -ex

cat foo
cat foo/baz.txt
echo "Hello World!"
EOF

BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json file.sh | jq '.id')
BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json --image-name ubuntu:22.04 file.sh | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID)
STATE=$(echo $STATUS | jq -jr '.state')
if [ "$STATE" == "success" ]; then
Expand All @@ -3114,12 +3113,10 @@ steps:
echo "Hello World! $1 $2"
EOF

BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json file-with-args.sh abc 123 | jq '.id')
BATCH_ID=$(hailctl batch submit --name=test-hailctl-batch-submit --files=foo -o json --image-name ubuntu:22.04 file-with-args.sh abc 123 | jq '.id')
STATUS=$(hailctl batch wait -o json $BATCH_ID)
STATE=$(echo $STATUS | jq -jr '.state')
if [ "$STATE" == "success" ]; then
exit 0;
else
if [ "$STATE" != "success" ]; then
echo $STATUS;
exit 1;
fi
Expand Down Expand Up @@ -3978,8 +3975,6 @@ steps:
dependsOn:
- ci_utils_image
- default_ns
scopes:
- deploy
- kind: runImage
name: test_gcp_ar_cleanup_policies
resources:
Expand Down
33 changes: 28 additions & 5 deletions hail/python/hailtop/hailctl/batch/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import asyncio
import json
from enum import Enum
from typing import Annotated as Ann
from typing import Any, Dict, List, Optional, cast

import orjson
import typer
from typer import Argument as Arg
from typer import Option as Opt

from . import billing, list_batches
from . import submit as _submit
from .batch_cli_utils import (
ExtendedOutputFormat,
ExtendedOutputFormatOption,
Expand Down Expand Up @@ -131,7 +130,7 @@ def wait(
quiet = quiet or output != StructuredFormatPlusText.TEXT
out = batch.wait(disable_progress_bar=quiet)
if output == StructuredFormatPlusText.JSON:
print(json.dumps(out))
print(orjson.dumps(out).decode('utf-8'))
else:
print(out)

Expand Down Expand Up @@ -168,16 +167,40 @@ def submit(
name: Ann[str, Opt(help='The name of the batch.')] = '',
image_name: Ann[Optional[str], Opt(help='Name of Docker image for the job (default: hailgenetics/hail)')] = None,
output: StructuredFormatPlusTextOption = StructuredFormatPlusText.TEXT,
wait: Ann[bool, Opt(help='Wait for the batch to complete.')] = False,
):
"""Submit a batch with a single job that runs SCRIPT with the arguments ARGUMENTS.
If you wish to pass option-like arguments you should use "--". For example:
$ hailctl batch submit --image-name docker.io/image my_script.py -- some-argument --animal dog
Copy a local file into the working directory of the job:
$ hailctl batch submit --image-name docker.io/image my_script.py --files a-file -- some-argument --animal dog
Copy a local file into a particular directory in the job:
$ hailctl batch submit --image-name docker.io/image my_script.py --files a-file:/foo/bar/ -- some-argument --animal dog
$ hailctl batch submit --image-name docker.io/image my_script.py -- some-argument --animal dog
Copy a local directory to the directory /foo/bar/a-directory in the job:
$ hailctl batch submit --image-name docker.io/image my_script.py --files a-directory:/foo/bar/ -- some-argument --animal dog
Copy a local file or a directory to a specific location in the job:
$ hailctl batch submit --image-name docker.io/image my_script.py --files a/local/path:/foo/bar -- some-argument --animal dog
Copy a local directory to a specific location in the job:
$ hailctl batch submit --image-name docker.io/image my_script.py --files a-file:/foo/bar -- some-argument --animal dog
Notes
-----
Copying a local directory to the root directory in the job is not supported (example: ``--files my-local-dir/:/``).
"""
asyncio.run(_submit.submit(name, image_name, files or [], output, script, [*(arguments or []), *ctx.args]))
from .submit import HailctlBatchSubmitError # pylint: disable=import-outside-toplevel
from .submit import submit as _submit # pylint: disable=import-outside-toplevel

try:
asyncio.run(_submit(name, image_name, files or [], output, script, [*(arguments or []), *ctx.args], wait))
except HailctlBatchSubmitError as err:
print(err.message)
raise typer.Exit(err.exit_code)


@app.command('init', help='Initialize a Hail Batch environment.')
Expand Down
Loading