Skip to content
Specular Differentiation

specular.backends.available_backends

available_backends()

Return the supported backends that can be imported in the current environment.

Parameters

None.

Returns

tuple[BackendName, ...] — Available names in the order "numpy", "numba", "jax", omitting backends whose required optional dependencies are missing.

Notes

This call probes all three backends and imports their calculation modules when available. It does not change the selected backend. Successful imports are cached; ordinary import specular does not perform this probe.

A missing required optional dependency excludes that backend from the returned tuple. Other import errors or invalid backend implementations propagate to the caller instead of being treated as a missing installation.

NumPy is included with the package. Install the numba or jax extra to use the corresponding optional backend; see the backend user guide.

This function is also available as specular.available_backends.

Examples

import specular

selected = specular.get_backend()
print(specular.available_backends())
assert specular.get_backend() == selected

With both optional backends installed, the printed tuple is ('numpy', 'numba', 'jax'). A NumPy-only installation prints ('numpy',).

Source code in specular/backends/_registry.py
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
def available_backends() -> tuple[BackendName, ...]:
    """Return supported backends that can be imported in this environment.

    Calling this function probes each backend, but it does not change the
    selected backend. Ordinary :mod:`specular` imports remain lazy.
    """

    available: list[BackendName] = []
    for name in _BACKEND_MODULES:
        try:
            _load_backend(name)
        except _BackendUnavailableError:
            continue
        available.append(name)
    return tuple(available)