Skip to main content

Python SDK for flux batch jobs and services

Project description

flux-batch

Python SDK to generate Flux batch jobs and services

PyPI - Version

https://github.com/converged-computing/flux-batch/raw/main/img/flux-batch-small.png

Related Projects

  • flux-mcp: MCP functions for Flux.
  • flux-mcp-server: MCP server.
  • fractale-mcp: (fractale) MCP orchestration (agents, databases, ui interfaces).
  • hpc-mcp: HPC tools for a larger set of HPC and converged computing use cases.

Services

  • flux-scribe: Write job events to a local sqlite database via the JournalConsumer (not added yet, written and needs testing)

Usage

This is a small Flux utility that makes it easy to create Flux batch jobs and services. The use case is to submit work (one or more jobs) under an instance, and run a custom service, or epilog and prolog commands. We will provision several services here, and you can also provide your own name to start / stop.

Setup

Install the library and start (or be in) a flux instance.

flux start
pip install -e . --break-system-packages

Examples

We have a few simple examples:

Saving Logs

python3 ./examples/save_logs.py

Flux Scribe Module

export FLUX_SCRIBE_DATABASE=sqlite:///flux-batch-job.db
python3 ./examples/flux_scribe_module.py

General Test

Or run the controlled example to see a batch job with prolog and epilog run and complete:

python3 ./tests/test_flux_batch.py
Flux Batch Module Test
[OK] Connected to Flux.
[*] Creating batch jobs...
[*] Mapping attributes to BatchJobspecV1...
[*] Previewing submission (Dryrun -> Wrapper)...
#!/bin/bash
echo 'Batch Wrapper Starting'
flux submit --wait /bin/echo 'Job 1 starting'
flux submit --wait /bin/sleep 5
flux submit --wait /bin/echo 'Job 2 finished'
flux job wait --all
echo 'Batch Wrapper Finished'
[*] Performing submission (Dryrun -> Wrapper -> Submit)...
[SUCCESS] Batch submitted! Flux Job ID: ƒMX29AwFu
$ flux jobs -a
       JOBID USER     NAME       ST NTASKS NNODES     TIME INFO
   ƒMX29AwFu vscode   test-batch  R      1      1   4.213s 68e8c4399c15
$ flux jobs -a
       JOBID USER     NAME       ST NTASKS NNODES     TIME INFO
   ƒMX29AwFu vscode   test-batch CD      1      1   6.354s 68e8c4399c15

Here is an explicit (manual) example to do the same:

import flux
import flux_batch

# for pretty printing
# from rich import print

handle = flux.Flux()

# Create your batch job with some number of commands
batch = flux_batch.BatchJobV1()
batch.add_job(["echo", "Job 1 starting"])
batch.add_job(["sleep", "5"])
batch.add_job(["echo", "Job 2 finished"])

# Wrap it up into a jobspec
jobspec = flux_batch.BatchJobspecV1.from_jobs(
    batch,
    nodes=1,
    nslots=1,
    time_limit="10m",
    job_name="test-batch",
    # Add saving of logs, info, and metadata
    logs_dir="./logs",
)

# Add a prolog and epilog
jobspec.add_prolog("echo 'Batch Wrapper Starting'")
jobspec.add_epilog("echo 'Batch Wrapper Finished'")

# Add a service (this assumes user level that exists)
jobspec.add_service("flux-scribe")

# Preview it
print(flux_batch.submit(handle, jobspec, dry_run=True))

# Submit that bad boi.
jobid = flux_batch.submit(handle, jobspec)

TODO

  • Option for controlled output (that we can easily get after)
  • Create flux-scribe service, add example (need to test on cluster with systemctl)

License

HPCIC DevTools is distributed under the terms of the MIT license. All new contributions must be made under this license.

See LICENSE, COPYRIGHT, and NOTICE for details.

SPDX-License-Identifier: (MIT)

LLNL-CODE- 842614

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flux_batch-0.0.11.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flux_batch-0.0.11-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file flux_batch-0.0.11.tar.gz.

File metadata

  • Download URL: flux_batch-0.0.11.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for flux_batch-0.0.11.tar.gz
Algorithm Hash digest
SHA256 8acad2aef086cb2fdc929d817f7dbd3596923ab69331bdd37cee75ef06e00635
MD5 0085ad6632958c9e1f811e40e1ac97fd
BLAKE2b-256 0c12e216a51382b5cbeb8c8ab1c36066c16dd58c55942159da3592237b88ffd4

See more details on using hashes here.

File details

Details for the file flux_batch-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: flux_batch-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for flux_batch-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 cd7c04e0a4acb848f7fffa5f3a6b1ed46a01bc26e27f54a5808a55b000a9da2b
MD5 b5fcf8be6990e87fdd1e64258d5def9a
BLAKE2b-256 5be69ed660a903b3648d5f7edf66f58353a3dba08eb7eae946969aad92bce5f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page