Skip to main content

excaexca

Execute and cache seamlessly in python.

workflow badge

Quick install

pip install exca

Full documentation

Documentation is available at https://facebookresearch.github.io/exca/

Basic overview

exca provides simple decorators to:

  • execute a (hierarchy of) computation(s) either locally or on distant nodes,
  • cache the result.

The problem:

In ML pipelines, the use of a simple python function, such as my_task:

import numpy as np

def my_task(param: int = 12) -> float:
    return param * np.random.rand()

often requires cumbersome overheads to (1) configure the parameters, (2) submit the job on a cluster, (3) cache the results: e.g.

import pickle
from pathlib import Path
import submitit

# Configure
param = 12

# Check task has already been executed
filepath = tmp_path / f'result-{param}.npy'
if not filepath.exists():

    # Submit job on cluster
    executor = submitit.AutoExecutor(cluster=None, folder=tmp_path)
    job = executor.submit(my_task, param)
    result = job.result()

    # Cache result
    with filepath.open("wb") as f:
        pickle.dump(result, f)

These overheads lead to several issues, such as debugging, handling hierarchical execution and properly saving the results (ending in the classic 'result-parm12-v2_final_FIX.npy').

The solution:

exca can be used to decorate the method of a pydantic model so as to seamlessly configure its execution and caching:

import numpy as np
import pydantic
import exca as xk

class MyTask(pydantic.BaseModel):
    param: int = 12
    infra: xk.TaskInfra = xk.TaskInfra()

    @infra.apply
    def process(self) -> float:
        return self.param * np.random.rand()


task = MyTask(param=1, infra={"folder": tmp_path, "cluster": "auto"})
out = task.process()  # runs on slurm if available
# calling process again will load the cache and not a new random number
assert out == task.process()

See the API reference for all the details

Quick comparison

feature \ tool lru_cache hydra submitit exca
RAM cache ✔ ✔
file cache ✔
remote compute ✔ ✔ ✔
pure python (vs command line) ✔ ✔ ✔
hierarchical config ✔ ✔

Contributing

See the CONTRIBUTING file for how to help out.

Citing

@misc{exca,
    author = {J. Rapin and J.-R. King},
    title = {{Exca - Execution and caching}},
    year = {2024},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://github.com/facebookresearch/exca}},
}

License

exca is MIT licensed, as found in the LICENSE file. Also check-out Meta Open Source Terms of Use and Privacy Policy.

Metadata

Release files for exca 0.6.2

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

Source distribution (sdist)

Source distribution for exca 0.6.2
File Size Uploaded Provenance Actions
exca-0.6.2.tar.gz 185.7 kB Without provenance Details for exca-0.6.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for exca 0.6.2
File Interpreter ABI Platform Actions
exca-0.6.2-py3-none-any.whl Python 3 none any Details for exca-0.6.2-py3-none-any.whl

Total release size: 404.4 kB

Release files / exca-0.6.2.tar.gz

Download URL exca-0.6.2.tar.gz
Size 185.7 kB
Tags Source
SHA-256 checksum
How to use checksums
62d3489d21f3e47a4d69b40ed65fb3cd2ddc3b022a283671f03b8e06ec7822f2
BLAKE2b-256 checksum
How to use checksums
840f73d9030134349b467e0c3f9fa8e0c2796f4b35f5dfee29fbb55dd0dd604c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / exca-0.6.2-py3-none-any.whl

Download URL exca-0.6.2-py3-none-any.whl
Size 218.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a1752782c5f19c16f9feaa78b8b18b24b4f7965ab48ca1e44797a7f9712b381
BLAKE2b-256 checksum
How to use checksums
80a0bd5a6bf124701cc65c8e3aacac462cd125a19c4010ea5ca6342d6901d242
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Security for exca 0.6.2

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.

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files No provenance

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