pyhf.set_backend#

pyhf.set_backend(backend: str | bytes | pyhf.typing.TensorBackend, custom_optimizer: str | bytes | pyhf.typing.Optimizer | None = None, precision: str | bytes | None = None, default: bool = False) None[source]#

Set the backend and the associated optimizer

Example

>>> import pyhf
>>> pyhf.set_backend("tensorflow")
>>> pyhf.tensorlib.name
'tensorflow'
>>> pyhf.tensorlib.precision
'64b'
>>> pyhf.set_backend(b"pytorch", precision="32b")
>>> pyhf.tensorlib.name
'pytorch'
>>> pyhf.tensorlib.precision
'32b'
>>> pyhf.set_backend(pyhf.tensor.numpy_backend())
>>> pyhf.tensorlib.name
'numpy'
>>> pyhf.tensorlib.precision
'64b'
Parameters:
  • backend (str or bytes or pyhf.tensor backend) – One of the supported pyhf backends: NumPy, TensorFlow, PyTorch, and JAX

  • custom_optimizer (str or bytes or pyhf.optimize optimizer or None) – Optional custom optimizer defined by the user

  • precision (str or bytes or None) – Floating point precision to use in the backend: 64b or 32b. Default is backend dependent.

  • default (bool) – Set the backend as the default backend additionally

Returns:

None