Skip to content

Use of Enum and numba #524

Description

@felixhekhorn

@kamillaurent reports:

2026-05-28 03:20:21,201 eko.evolution_operator/INFO: Evolution: computing operators - 193/196 took: 0.909104 s
2026-05-28 03:20:22,105 eko.evolution_operator/INFO: Evolution: computing operators - 194/196 took: 0.903717 s
2026-05-28 03:20:23,390 eko.evolution_operator/INFO: Evolution: computing operators - 195/196 took: 0.897556 s
2026-05-28 03:20:24,109 eko.evolution_operator/INFO: Evolution: computing operators - 196/196 took: 0.717515 s
2026-05-28 03:20:25,765 eko.evolution_operator/INFO: Evolution: Total time 4963.983533 s
[... after some time ...]
Traceback (most recent call last):
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/bin/evolven3fit", line 7, in <module>
    sys.exit(main())
             ^^^^^^
  File "/data/theorie/klaurent/nnpdf/n3fit/src/n3fit/scripts/evolven3fit.py", line 187, in main
    solve(tcard, opcard, args.dump)
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/eko/runner/managed.py", line 29, in solve
    eko.parts[recipe] = parts.evolve(eko, recipe)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/eko/runner/parts.py", line 76, in evolve
    op.compute()
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/eko/evolution_operator/__init__.py", line 981, in compute
    self.integrate()
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/eko/evolution_operator/__init__.py", line 1001, in integrate
    for j, row in enumerate(res):
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/eko/evolution_operator/__init__.py", line 902, in run_op_integration
    res = integrate.quad(
          ^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/scipy/integrate/_quadpack_py.py", line 479, in quad
    retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/scipy/integrate/_quadpack_py.py", line 626, in _quad
    return _quadpack._qagse(func,a,b,args,full_output,epsabs,epsrel,limit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/dispatcher.py", line 687, in typeof_pyval
    tp = typeof(val, Purpose.argument)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/typing/typeof.py", line 33, in typeof
    ty = typeof_impl(val, c)
         ^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/functools.py", line 909, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/typing/typeof.py", line 230, in _typeof_enum
    clsty = typeof_impl(type(val), c)
            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/functools.py", line 909, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/typing/typeof.py", line 249, in _typeof_enum_class
    return typecls(cls, dtypes.pop())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/types/abstract.py", line 68, in __call__
    return cls._intern(inst)
           ^^^^^^^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/types/abstract.py", line 57, in _intern
    inst._code = _autoincr()
                 ^^^^^^^^^^^
  File "/data/theorie/klaurent/miniconda3/envs/nnpdf-dev/lib/python3.12/site-packages/numba/core/types/abstract.py", line 23, in _autoincr
    assert n < 2 ** 32, "Limited to 4 billion types"
AssertionError: Limited to 4 billion types

The problem seems to be (according to Claude run by @juanrojochacon )

The trigger is `_typeof_enum` → `_typeof_enum_class` in the chain: every time EKO calls a Numba-jitted integrand through `scipy.integrate.quad`, Numba inspects the arguments and, for an `Enum` argument, **creates a brand-new `EnumClass` type and interns it**. Numba does not cache enum types by identity properly here, so each call leaks a fresh type into the global registry. EKO's `run_op_integration` runs `quad` an enormous number of times (per grid point, per operator element, per Q² step), so the counter climbs until it overflows 2³².

and a supposed solutions (suggested by the same pair of "people")

The cleanest fix is to stop passing the enum into the jitted function and pass its `.value` (a plain int) instead, converting back inside or branching outside the hot loop

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions