Skip to main content

Grain

Docs PyPI version

A scheduler for resource-aware parallel external computing on clusters.

Install

pip install grain-scheduler

Overview

Dask-like async-native delayed objects for you to run jobs in an arbitary mix of parallel and sequential manner.

from grain.delayed import delayed
from grain.resource import Cores

@delayed
async def identity(x):
    # Access what CPU(s) have been allocated for us
    n_cpu, cpus = GVAR.res.N, ','.join(map(str,GVAR.res.c))
    # Pretend that we are doing something seriously ...
    await trio.run_process(f'mpirun -np {n_cpu} --bind-to cpulist:ordered --cpu-set {cpu} sleep 1')
    return x

@delayed
async def weighted_sum():
    # Run the expensive function **remotely** (on a worker) by demanding resource 1 CPU core
    # Note that `r_` is a Future, or a placeholder of the return value
    r_ = (identity @ Cores(1))(0)

    # Futures are composable
    # Composition implies dependency / parallelization opportunity
    r_ += (identity @ Cores(1))(1) * 1 + (identity @ Cores(1))(2) * 2
    # Block until all dependencies finish, then return the composed value
    return await r_

    # Or do the same in a fancier way
    #return await sum(
    #    (identity @ Cores(1))(i) * i for i in range(3)
    #)

# Run the cheap, orchestrating function **locally**
print(await (weighted_sum() + weighted_sum()))
# Output: 10

Check out tutorial for complete demos and how to set up workers.

Resource-awareness

Every job in the job queue has a resource request infomation along with the job to run. Before the executor run each job, it inspects each worker for resource availability. If resource is insufficient, the job queue is suspended until completed jobs return resources. Resources can be CPU cores, virtual memory, both, (or anything user defined following interface grain.resource.Resource).

Every time a job function runs, it has access to GVAR.res, a context-local variable giving the information of specific resource dedicated to the job. (e.g. if a job is submitted with Cores(3), asking for 3 CPU cores, it might receive allocation like Cores([6,7,9]).)

Ergonomic user interface

Async-native API introduces minimal changes to the serial code, while enabling access to the entire Python async ecosystem accommodating complex workflows.

Minimal configuration is needed for migrating to a new supercomputing cluster (See sample configs in the example/ dir). When running, the grain commandline helper provides easy access to dashboard and worker scaling.

Metadata

Release files for grain-scheduler 0.17.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for grain-scheduler 0.17.1
File Size Uploaded Provenance Actions
grain_scheduler-0.17.1.tar.gz 45.4 kB Without provenance Details for grain_scheduler-0.17.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for grain-scheduler 0.17.1
File Interpreter ABI Platform Actions
grain_scheduler-0.17.1-py3-none-any.whl Python 3 none any Details for grain_scheduler-0.17.1-py3-none-any.whl

Total release size: 1.5 MB

Release files / grain_scheduler-0.17.1.tar.gz

Download URL grain_scheduler-0.17.1.tar.gz
Size 45.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9cb0684d16746fbc42603746d017440f54a3462d8f52b023fc1d6cffc08567de
BLAKE2b-256 checksum
How to use checksums
18273dd74fc1a6cc2f14aaccf8aadac0f9be4814fb970f5f4c5da66e8c19007e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / grain_scheduler-0.17.1-py3-none-any.whl

Download URL grain_scheduler-0.17.1-py3-none-any.whl
Size 1.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
273c37c678cc482918b367f8f37e6356806b7767e1001e17b32215e296a2bfbc
BLAKE2b-256 checksum
How to use checksums
682fbe5ddd53c05f7e95c82f814d19d6c43ac7d8901ad7d00f24ffb96e3a3efe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Security for grain-scheduler 0.17.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page