Skip to main content

Decorator library: numpy_fn/torch_fn/pandas_fn/xarray_fn/signal_fn type converters, caching, batching, deprecation — standalone module from the SciTeX ecosystem

Project description

scitex-decorators

SciTeX

Decorator library — type conversion (numpy/torch/pandas/xarray), caching, batching, lifecycle.

Full Documentation · uv pip install scitex-decorators[all]

pypi python docs

tests install-check quality cov


Problem and Solution

# Problem Solution
1 Array-type plumbing — functions that should accept numpy / torch / pandas / xarray end up reimplementing isinstance dispatch + back-conversion every time. @numpy_fn, @torch_fn, @pandas_fn, @xarray_fn, @signal_fn convert inputs to the named type, run the wrapped function, and restore the caller's original type on the way out.
2 Expensive recomputations dominate dev cycles; ad-hoc pickle caches drift in invalidation and disk layout. @cache_disk (joblib) / @cache_disk_async / @cache_mem give SciTeX-aware disk + memory caching with a documented cache-dir resolution order (scitex.config$SCITEX_CACHE_DIR → XDG → ~/.cache).
3 GPU / memory limits force researchers to hand-batch tensors, often re-deriving the loop per project. @batch_fn + @batch_numpy_fn / @batch_torch_fn / @batch_pandas_fn chunk inputs through the wrapped function and reassemble outputs; compose cleanly with the @*_fn converters.

Installation

pip install scitex-decorators              # core (numpy only)
pip install "scitex-decorators[caching]"   # + joblib for cache_disk
pip install "scitex-decorators[torch]"     # + torch_fn / batch_torch_fn
pip install "scitex-decorators[all]"       # everything

Architecture

flowchart LR
    AO["@auto_order"] --> CV["@*_fn converters"]
    CV --> NP["@numpy_fn"]
    CV --> PD["@pandas_fn"]
    CV --> XR["@xarray_fn"]
    CV --> TR["@torch_fn"]
    CV --> SG["@signal_fn"]
    BF["@batch_fn"] --> CV
    CD["@cache_disk<br/>(joblib)"] -.-> NP & PD & TR
    PD2["@preserve_doc"] -.-> NP & PD & TR & XR & SG
    DEP["@deprecated"] -.-> NP & PD & TR
    TO["@timeout"] -.-> CV
    NI["@not_implemented"] -.-> CV
    CO["@combined<br/>(stack of @*_fn)"] --> NP & PD & TR

Each @<type>_fn decorator converts inputs to the named type, calls the wrapped function, then converts back to the caller's original type. The diagram above shows how _combined.py, _auto_order.py, and the caching/timeout decorators compose around the converter family.

Quick Start

import scitex_decorators as dec

@dec.numpy_fn
def kernel(x):
    return x ** 2     # x is numpy inside; return matches caller's type

@dec.cache_disk
def expensive(x): ...

1 Interfaces

Python API
import scitex_decorators as dec

# Type-conversion decorators
@dec.numpy_fn  ; @dec.torch_fn  ; @dec.pandas_fn  ; @dec.xarray_fn
@dec.signal_fn

# Caching (joblib for disk, dict for mem)
@dec.cache_disk        ; @dec.cache_disk_async    ; @dec.cache_mem

# Batching
@dec.batch_fn          ; @dec.batch_numpy_fn / batch_torch_fn / batch_pandas_fn

# Lifecycle
@dec.deprecated(reason="…")
@dec.not_implemented
@dec.preserve_doc
@dec.timeout(seconds=10)
@dec.wrap

# Auto-ordering machinery
dec.enable_auto_order() ; dec.disable_auto_order()

# Conversion helpers
dec.to_numpy(x) ; dec.to_torch(x)
dec.is_torch(x) ; dec.is_cuda(x)

Cache directory resolution

cache_disk / cache_disk_async resolve the cache dir in this order:

  1. scitex.config.get_paths().function_cache (only if scitex is installed)
  2. ${SCITEX_CACHE_DIR}/function_cache
  3. ${XDG_CACHE_HOME}/scitex-decorators/function_cache
  4. ~/.cache/scitex-decorators/function_cache

So the package works without the umbrella scitex installed.

Demo

flowchart LR
    C["caller passes pandas.DataFrame"] --> D["@numpy_fn"]
    D --> N["function body sees numpy.ndarray"]
    N --> R["function returns numpy.ndarray"]
    R --> O["caller receives pandas.DataFrame<br/>(original type restored)"]

Status

Standalone fork of scitex.decorators. Zero scitex.* runtime deps. The umbrella package's scitex.decorators import path is preserved via a sys.modules-alias bridge.

Part of SciTeX

scitex-decorators is part of SciTeX. Install via the umbrella with pip install scitex[decorators] to use as scitex.decorators (Python) or scitex decorators ... (CLI).

Four Freedoms for Research

  1. The freedom to run your research anywhere — your machine, your terms.
  2. The freedom to study how every step works — from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. The freedom to modify any module and share improvements with the community.

AGPL-3.0 — because we believe research infrastructure deserves the same freedoms as the software it runs on.

License

AGPL-3.0-only (see LICENSE).


SciTeX

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

scitex_decorators-0.1.10.tar.gz (36.7 kB view details)

Uploaded Source

Built Distribution

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

scitex_decorators-0.1.10-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

Details for the file scitex_decorators-0.1.10.tar.gz.

File metadata

  • Download URL: scitex_decorators-0.1.10.tar.gz
  • Upload date:
  • Size: 36.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for scitex_decorators-0.1.10.tar.gz
Algorithm Hash digest
SHA256 c45c95d2ac17d7df1b1bc1e8b5185f0a8c2caa0db3bbf45ec97a364d7c39a462
MD5 dc2cdb0d5324d79771ff904fa2d30745
BLAKE2b-256 c11bfbf11bb7ac5a73212bf8558c0b0d0c26bbe52c6174c74a6074293a3fff50

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_decorators-0.1.10.tar.gz:

Publisher: publish-pypi.yml on ywatanabe1989/scitex-decorators

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file scitex_decorators-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for scitex_decorators-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ec59fe79f8f815d1119b8098508b598ffa4a7f933868a429c884a3af5c22f89c
MD5 132bba7ff2e587e28846568b4a81f377
BLAKE2b-256 63bb1fc1175117fa379f79e009102fc276cff7ccd5127a0622d60f1632bad3fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_decorators-0.1.10-py3-none-any.whl:

Publisher: publish-pypi.yml on ywatanabe1989/scitex-decorators

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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