Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit setting of the default backend #1004

Closed
phinate opened this issue Jul 29, 2020 · 1 comment · Fixed by #1646
Closed

Explicit setting of the default backend #1004

phinate opened this issue Jul 29, 2020 · 1 comment · Fixed by #1646
Labels
feat/enhancement New feature or request

Comments

@phinate
Copy link
Contributor

phinate commented Jul 29, 2020

It may be desirable in some cases (e.g. #882) to have one consistent backend for all cases, which would enable the propagation of gradients throughout pyhf model construction, for instance. Backends will hit a wall when trying to take the gradient with respect to something that involves pure numpy.

An example implementation of this could be as simple as adding the argument set_default=False to set_backend, followed by something like

def set_backend(..., set_default=False):
    ...
    backend = tensorlib
    if set_default:
        global default_backend
        default_backend = tensorlib
    ...
    tensorlib._setup()
    if set_default:
        default_backend._setup()

It seems like this would be fine at first glance, since the backend checks are done in the lines before this. I managed to get the logpdf of hepdata_like with no issues, but I was unsure what would be a more robust test for changing the default backend. Ideally, one would want to run the whole test suite I guess, to make sure this doesn't secretly change some functionality.

Hope this is useful!

@kratsg
Copy link
Contributor

kratsg commented Jul 29, 2020

The default backend can be set w/o changing the rest of the code. It'll help with the diff'able case for sure. My first guess is you should be able to do

import pyhf
pyhf.default_backend = pyhf.tensor.tensorflow_backend(precision='64b')

at the top of your code? I'm not 100% sure one wants an updated API for this, but...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants