question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Iteration limit reached when using histosys modifier.

See original GitHub issue

Summary

Hello everyone,

First of all let me thank you for the wonderful package. As a PhD student playing with LHC data for the first time, it is really helpful.

I would like to take into account a systematic uncertainty in my signal, to do that I tried to add the histosys modifier to my signal in addition to the normfactor for signal strength and the uncorr_bkguncrt for my background.

For some reason this caused pyhf.infer.hypotest to be stuck in a loop and raise an iteration limit exception (it also prints a lot of “nan” in the error report for the function to minimize, its jacobian and minimum).

I tried replacing histosys by shapesys and it seems to work normally.

Am I doing something wrong ? Is this a bug? Can you suggest a workaround for what I am trying to do?

Many thanks

OS / Environment

Ubuntu 20.04

Steps to Reproduce

mod = {
        "channels": [
            { "name": "singlechannel",
              "samples": [
                { "name": "signal",
                  "data": list(signal),
                  "modifiers": [{ "name": "mu", "type": "normfactor", "data": None},
                                { "name": "mod_name", "type": "histosys", "data": {"hi_data": list(hi), "lo_data": list(lo)} }]

                },
                { "name": "background",
                  "data": list(backgr),
                  "modifiers": [ {"name": "uncorr_bkguncrt", "type": "shapesys", "data": list(b_err)} ]
                }
              ]
            }
        ],
        "observations": [
            { "name": "singlechannel", "data": list(obs) }
        ],
        "measurements": [
            { "name": "Measurement", "config": {"poi": "mu", "parameters": [{"bounds": [[0, 1e+6]],"inits": [1.0], "name": "mu"}]} }
        ],
        "version": "1.0.0"
        }

File Upload (optional)

No response

Expected Results

A p-value.

Actual Results

fun: nan
     jac: array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])
 message: 'Iteration limit reached'
    nfev: 2999989
     nit: 100000
    njev: 100000
  status: 9
 success: False
       x: array([nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan])
Traceback (most recent call last):
   File "/mnt/c/pyhf/optimize/mixins.py", line 49
      assert result.success
AssertionError

pyhf Version

0.62

Code of Conduct

  • I agree to follow the Code of Conduct

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
FlorentinJcommented, Dec 7, 2021

Thank you so much! That wes exactly it. A simple pip install scipy --upgrade later (from version 1.5.4), and it now works fine.

0reactions
matthewfeickertcommented, Dec 7, 2021

Thank you so much! That wes exactly it. A simple pip install scipy --upgrade later (from version 1.5.4), and it now works fine.

Glad to hear it! 🙂 The reason I suspected scipy was because the error was coming from the minimizer failing to converge, and there isn’t much in terms of pyhf code there.

Though maybe it was actually a bug in an older version of NumPy (SciPy imposes both lower and upper limits on NumPy) or an interaction between NumPy and SciPy, as if I use scipy==1.5.4 I can still get it to pass:

$ docker run --rm -ti python:3.9 /bin/bash
root@177469c2b9f1:/# python -m venv venv && . venv/bin/activate
(venv) root@177469c2b9f1:/# python -m pip install --upgrade pip setuptools wheel
(venv) root@177469c2b9f1:/# python -m pip install 'scipy==1.5.4' 'pyhf==0.6.3'
(venv) root@177469c2b9f1:/# python -m pip list
Package     Version
----------- -------
attrs       21.2.0
click       8.0.3
jsonpatch   1.32
jsonpointer 2.2
jsonschema  4.2.1
numpy       1.21.4
pip         21.3.1
pyhf        0.6.3
pyrsistent  0.18.0
PyYAML      6.0
scipy       1.5.4
setuptools  59.5.0
tqdm        4.62.3
wheel       0.37.0
(venv) root@177469c2b9f1:/# tail -n 5 issue_1722.py  # copying the example in Issue #1722

# this line takes a long time then fail
cls_obs, cls_expected = pyhf.infer.hypotest(1, wsdata, ws.model(), calctype='asymptotics', return_expected=True, test_stat='qtilde')
print(f"CL_s observed: {cls_obs}")
print(f"CL_s expected: {cls_expected}")
(venv) root@177469c2b9f1:/# python issue_1722.py 
/venv/lib/python3.9/site-packages/pyhf/tensor/numpy_backend.py:352: RuntimeWarning: invalid value encountered in log
  return n * np.log(lam) - lam - gammaln(n + 1.0)
CL_s observed: 0.26319911317665245
CL_s expected: 0.2012008685590555
Read more comments on GitHub >

github_iconTop Results From Across the Web

LME() error - iteration limit reached - Cross Validated
I haven't heard of the error argument to lme and I don't see it in the documentation. Are you sure that isn't a...
Read more >
Why does it say Iteration limit reached and how do I fix it?
Terminate with error message if iteration limit exceeded: if count == Iteration_limit + 1. error('Iteration limit reached. Iteration did not ...
Read more >
how to resolve this **WARNING: EQUIL.ITERATION LIMIT ...
I am doing analysis for lifiting spreader beam by using cable analysis. Some has to confirm the procedure is ... ITERATION LIMIT REACHED?I....
Read more >
Is "iteration limit reached" a warning or an error? #104 - GitHub
While the code runs through completion, it shows in red "iteration limit reached many times for each pN values. Should I be concerned...
Read more >
View a file's version history – Figma Help Center
You can use this process to: View earlier iterations of a design. Find and copy accidentally deleted assets. Access files that have reached...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found