Giter Club home page Giter Club logo

Comments (5)

matthewfeickert avatar matthewfeickert commented on June 19, 2024

It looks like you're reasonably starting with

pyhf/tests/conftest.py

Lines 59 to 74 in 205eecf

@pytest.fixture(
scope='function',
params=[
(pyhf.tensor.numpy_backend(), None),
(pyhf.tensor.pytorch_backend(), None),
(pyhf.tensor.pytorch_backend(precision='64b'), None),
(pyhf.tensor.tensorflow_backend(), None),
(pyhf.tensor.jax_backend(), None),
(
pyhf.tensor.numpy_backend(poisson_from_normal=True),
pyhf.optimize.minuit_optimizer(),
),
],
ids=['numpy', 'pytorch', 'pytorch64', 'tensorflow', 'jax', 'numpy_minuit'],
)
def backend(request):
for your example, and I believe the reason that we don't run into this bug ever in testing is that we rest the backend automatically

pyhf/tests/conftest.py

Lines 49 to 56 in 205eecf

@pytest.fixture(scope='function', autouse=True)
def reset_backend():
"""
This fixture is automatically run to reset the backend before and after a test function runs.
"""
pyhf.set_backend('numpy', default=True)
yield reset_backend
pyhf.set_backend('numpy', default=True)

@kratsg and I can follow up on this later in the week on PR #2310, but it is currenlty the Labor Day holiday in the US, so we won't get to this today.

from pyhf.

kratsg avatar kratsg commented on June 19, 2024

I cannot reproduce this on 3.8+ (where the Cython code for weakref has been updated to fix other stuff). Is this done only on 3.7? If so, this isn't something we can fix.

from pyhf.

matthewfeickert avatar matthewfeickert commented on June 19, 2024

Backtracking from my original statement (#2310 (review)) I tried to reproduce in a clean Python 3.11 virtual environment built from the following requirements.txt

pyhf[all,minuit]==0.7.3
pytest==7.4.1
pytest-benchmark==4.0.0

which for context gives

$ python -m pip list | grep 'scipy\|jax\|torch\|tensorflow\|iminuit'
iminuit                      2.24.0
jax                          0.4.14
jaxlib                       0.4.14
scipy                        1.11.2
tensorflow                   2.13.0
tensorflow-estimator         2.13.0
tensorflow-io-gcs-filesystem 0.33.0
tensorflow-probability       0.21.0
torch                        2.0.1

In that environment running

pytest issue-2311.py

passes with no errors.

@wernerd-cern Can you please provide an environment defintion file that is able to reprodue your error?

I earlier didn't test well enough in my rush and was also running into an error coming from jax, not pyhf.tensorlib so I wasn't reproducing what originally reported.

from pyhf.

matthewfeickert avatar matthewfeickert commented on June 19, 2024

This was also not able to be reproduced (originally) with Python 3.7

$ docker run --rm -ti -v $PWD:/work:ro python:3.7 /bin/bash
root@691fb3f949d9:/# python -m venv venv && . venv/bin/activate
(venv) root@691fb3f949d9:/# python -m pip install --upgrade pip setuptools wheel
(venv) root@691fb3f949d9:/# python -m pip install --upgrade -r /work/requirements.txt
(venv) root@691fb3f949d9:/# pytest /work/issue-2311.py  # passes
(venv) root@691fb3f949d9:/# python --version --version
Python 3.7.17 (default, Aug 16 2023, 20:32:51) 
[GCC 12.2.0]
(venv) root@691fb3f949d9:/# python -m pip list | grep 'pyhf\|scipy\|jax\|torch\|tensorflow\|iminuit'
iminuit                      2.18.0
jax                          0.3.25
jaxlib                       0.3.25
pyhf                         0.7.3
scipy                        1.7.3
tensorflow                   2.11.0
tensorflow-estimator         2.11.0
tensorflow-io-gcs-filesystem 0.33.0
tensorflow-probability       0.19.0
torch                        1.13.1
(venv) root@691fb3f949d9:/# 

but was reproducible on repeated runs

(venv) root@691fb3f949d9:/# pytest /work/issue-2311.py ..................E.....E...........                                                                                                                         [100%]

======================================================================================= ERRORS ========================================================================================
_________________________________________________________________ ERROR at setup of test_hypotest[tensorflow-1_bins] __________________________________________________________________

request = <SubRequest 'backend' for <Function test_hypotest[tensorflow-1_bins]>>

    @pytest.fixture(
        scope="function",
        params=[
            (pyhf.tensor.numpy_backend(), None),
            (pyhf.tensor.pytorch_backend(), None),
            (pyhf.tensor.pytorch_backend(precision="64b"), None),
            (pyhf.tensor.tensorflow_backend(), None),
            (pyhf.tensor.jax_backend(), None),
            (
                pyhf.tensor.numpy_backend(poisson_from_normal=True),
                pyhf.optimize.minuit_optimizer(),
            ),
        ],
        ids=["numpy", "pytorch", "pytorch64", "tensorflow", "jax", "numpy_minuit"],
    )
    def backend(request):
        # get the ids of all the backends
        param_ids = request._fixturedef.ids
        # the backend we're using: numpy, tensorflow, etc...
        param_id = param_ids[request.param_index]
        # name of function being called (with params), the original name is .originalname
        func_name = request._pyfuncitem.name
    
>       pyhf.set_backend(*request.param)

work/issue-2311.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.7/site-packages/pyhf/events.py:161: in register_wrapper
    result = func(*args, **kwargs)
venv/lib/python3.7/site-packages/pyhf/tensor/manager.py:192: in set_backend
    events.trigger("tensorlib_changed")()
venv/lib/python3.7/site-packages/pyhf/events.py:70: in __call__
    func()(arg(), *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = None

    def _precompute(self):
        tensorlib, _ = get_backend()
>       self.sorted_indices = tensorlib.astensor(self._sorted_indices, dtype='int')
E       AttributeError: 'NoneType' object has no attribute '_sorted_indices'

venv/lib/python3.7/site-packages/pyhf/tensor/common.py:33: AttributeError
-------------------------------------------------------------------------------- Captured stderr setup --------------------------------------------------------------------------------
2023-09-06 01:21:44.619013: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2023-09-06 01:21:44.619043: W tensorflow/compiler/xla/stream_executor/cuda/cuda_driver.cc:265] failed call to cuInit: UNKNOWN ERROR (303)
_____________________________________________________________________ ERROR at setup of test_hypotest[jax-1_bins] _____________________________________________________________________

request = <SubRequest 'backend' for <Function test_hypotest[jax-1_bins]>>

    @pytest.fixture(
        scope="function",
        params=[
            (pyhf.tensor.numpy_backend(), None),
            (pyhf.tensor.pytorch_backend(), None),
            (pyhf.tensor.pytorch_backend(precision="64b"), None),
            (pyhf.tensor.tensorflow_backend(), None),
            (pyhf.tensor.jax_backend(), None),
            (
                pyhf.tensor.numpy_backend(poisson_from_normal=True),
                pyhf.optimize.minuit_optimizer(),
            ),
        ],
        ids=["numpy", "pytorch", "pytorch64", "tensorflow", "jax", "numpy_minuit"],
    )
    def backend(request):
        # get the ids of all the backends
        param_ids = request._fixturedef.ids
        # the backend we're using: numpy, tensorflow, etc...
        param_id = param_ids[request.param_index]
        # name of function being called (with params), the original name is .originalname
        func_name = request._pyfuncitem.name
    
>       pyhf.set_backend(*request.param)

work/issue-2311.py:29: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.7/site-packages/pyhf/events.py:161: in register_wrapper
    result = func(*args, **kwargs)
venv/lib/python3.7/site-packages/pyhf/tensor/manager.py:192: in set_backend
    events.trigger("tensorlib_changed")()
venv/lib/python3.7/site-packages/pyhf/events.py:70: in __call__
    func()(arg(), *args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = None

    def _precompute(self):
        tensorlib, _ = get_backend()
>       self.sorted_indices = tensorlib.astensor(self._sorted_indices, dtype='int')
E       AttributeError: 'NoneType' object has no attribute '_sorted_indices'

from pyhf.

wernerd-cern avatar wernerd-cern commented on June 19, 2024

I set up a clean virtual environment myself with the requirements.txt given by Matthew. My versions are then the following:

$ python --version --version
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]

$ python -m pip list | grep 'scipy\|jax\|torch\|tensorflow\|iminuit'
iminuit                      2.24.0
jax                          0.4.14
jaxlib                       0.4.14
scipy                        1.11.2
tensorflow                   2.13.0
tensorflow-estimator         2.13.0
tensorflow-io-gcs-filesystem 0.33.0
tensorflow-probability       0.21.0
torch                        2.0.1

I then executed pytest issue-2311.py several times and found that the bug occured about 40% of the time. It is the same bug Error message as shown in your previous reply. The "random" nature of when this error occurs makes it quite hard to narrow down further where exactly it happens.
I hope these details of my environment are sufficient. Otherwise I'm glad to provide any further information.

from pyhf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.