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.12.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.12-py3-none-any.whl (44.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: scitex_decorators-0.1.12.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.12.tar.gz
Algorithm Hash digest
SHA256 dd1632b55f1e2ae6da163ac0ab935a6b80192e04268e1a73b8b899f93ed1387e
MD5 a2b500f8f2bec7c0d5dbe6b2172e6f91
BLAKE2b-256 05c4d84d7179931916cc1969f361a2b460f9894fbc955d57a894a013ced05ed4

See more details on using hashes here.

Provenance

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

Publisher: pypi-publish-and-github-release-on-tag.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.12-py3-none-any.whl.

File metadata

File hashes

Hashes for scitex_decorators-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 1f1b0f5308eb3605a9b663124de2576e922fb33312123dd1d11c6de0a2d030e2
MD5 a41bb7940a8992cd7ee3a17697cf7a28
BLAKE2b-256 6579b1caf5bb16e169491458931da7bc5f05987b36a18ecfcf60f0e030a58899

See more details on using hashes here.

Provenance

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

Publisher: pypi-publish-and-github-release-on-tag.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