Install & Compatibility
Where this runs
tested against v0.8.11 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.126s · 19.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.9s · import 0.136s · 20MB
18MB installed
● package 18MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
autoray
✓ import autoray as ar
The most common and recommended way to import autoray, typically aliased as `ar` for convenience, to access functions like `ar.do` or `ar.get_namespace`.
numpy
✓ from autoray import numpy as np
Imports a NumPy-like API that dispatches through autoray, allowing for a drop-in replacement for existing NumPy code.
do
✓ from autoray import do
✗ import autoray.do
While `ar.do` is preferred with the alias, `do` can be imported directly. `autoray.do` is not the correct import path for the function itself.
This quickstart demonstrates the core functionalities of `autoray`: automatic backend dispatch using `ar.do()`, explicit backend selection with the `like` argument, and obtaining a backend-specific API using `ar.get_namespace()`. It also shows how to define a function that works generically across different array backends.
import autoray as ar
import numpy as np
# Basic usage with automatic dispatch (inferred from array type)
x_np = np.random.uniform(size=)
y_np = ar.do('sqrt', x_np)
print(f"Numpy sqrt: {y_np}, type: {type(y_np)}")
# Using 'like' argument for explicit backend or inference
# If torch is not installed, this will silently fall back to numpy behavior
# For full torch functionality, ensure 'torch' is installed.
x_torch_like = ar.do('random.uniform', size=(10, 10), like="torch")
print(f"Array generated with 'like="torch"': {type(x_torch_like)}")
# Using get_namespace for a backend-specific API (Python Array API style)
try:
# Attempt to get a torch namespace
xp = ar.get_namespace(like="torch") # Requires 'torch' to be installed for actual torch arrays
z = xp.ones((3, 4), dtype=xp.float32)
result = xp.exp(z)
print(f"Torch-like exp result shape: {result.shape}, type: {type(result)}")
except (ImportError, TypeError):
# Fallback if torch is not installed, get numpy namespace
xp = ar.get_namespace(like="numpy")
z = xp.ones((3, 4), dtype=xp.float32)
result = xp.exp(z)
print(f"Numpy-like exp result shape (fallback): {result.shape}, type: {type(result)}")
# Example of a more complex operation with automatic dispatch
def noised_svd(x):
U, s, VH = ar.do('linalg.svd', x)
sn = s + 0.1 * ar.do('random.normal', size=ar.shape(s), like=s)
return ar.do('einsum', 'ij,j,jk->ik', U, sn, VH)
# Use a numpy array for demonstration
x_complex_op = np.random.rand(10, 10)
y_complex_op = noised_svd(x_complex_op)
print(f"Complex operation result shape: {y_complex_op.shape}")
Errors
Common errors & fixes
ImportError: cannot import name 'Checkpoint' from 'ray.air'
The 'Checkpoint' class has been moved from 'ray.air' to 'ray.train' in newer versions of Ray.
fixUpdate the import statement to 'from ray.train import Checkpoint'.
AttributeError: 'function' object has no attribute 'remote'
Attempting to call the 'remote' method on a function that has not been decorated with '@ray.remote'.
fixEnsure the function is decorated with '@ray.remote' before calling its 'remote' method.
ImportError: cannot import name x from y
The module 'y' does not contain a definition for 'x', possibly due to a typo or incorrect module path.
fixVerify the correct module path and ensure 'x' is defined in 'y'.
AttributeError: 'float' object has no attribute 'ndim'
This error often occurs when a newer version of Autoray (e.g., 0.8.x) is used with older versions of libraries like PennyLane (e.g., v0.29), leading to an incompatibility where Autoray expects an array-like object with an `ndim` attribute but receives a float.
fixUpgrade PennyLane to a compatible version (e.g., `pennylane>=0.29.1`) or downgrade Autoray to a version compatible with your PennyLane installation (e.g., `pip install autoray<0.8`).
AttributeError: module 'autoray.autoray' has no attribute 'NumpyMimic'
This error typically arises due to an incompatibility between Autoray versions (specifically around `autoray==0.8.0`) and dependent libraries like PennyLane, where the `NumpyMimic` class or attribute was moved or removed in Autoray, breaking the integration.
fixUpgrade the dependent library (e.g., PennyLane) to a version compatible with your Autoray installation, or if the issue persists, try downgrading Autoray to an earlier stable version known to work with your specific setup.
Upgrade
Version history
0.11.0latest on PyPI · released Aug 22, 2026
Audit
Dependencies
numpyoptionalCommonly used backend for array operations.
torchoptionalCommonly used backend for deep learning tensor operations.
jaxoptionalCommonly used backend for high-performance numerical computation.
tensorflowoptionalCommonly used backend for deep learning tensor operations.