pyhf.set_backend

pyhf.set_backend(backend, custom_optimizer=None, precision=None, default=False)[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 pyhf.tensor backend) – One of the supported pyhf backends: NumPy, TensorFlow, PyTorch, and JAX

  • custom_optimizer (pyhf.optimize optimizer) – Optional custom optimizer defined by the user

  • precision (str) – 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