0

I have a snippet of python code as a function here. The purpose of the code is to use the combinations tool of itertools and turn a list of pairs into a list of triplets by matching items that correlate with each other. Due to the time consuming nature of the function, I have been trying to get it to work using a GPU through numba. Here is the function followed by me calling it:

@jit(target_backend='cuda')
def combinator(size, theuniquegenes, thetuplelist):
    limiter = size+1
    lengths = [l + 1 for l in range(len(theuniquegenes)) if (l + 1 > 2) and (l + 1 < limiter)]
    new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}
    correlations = {x for x in new_combs if all([c in thetuplelist for c in combinations(x, 2)])}
    print(len(correlations))
    tuplelist = thetuplelist + list(correlations)
    print(len(tuplelist))
    return tuplelist
tuplelist = combinator(3, uniquegenes, tuplelist)

Unfortunately, I keep encountering the following error message:

numba.core.errors.UnsupportedError: Failed in object mode pipeline (step: inline calls to locally defined closures)
Use of unsupported opcode (SET_ADD) found
new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}
    ^

How can I rewrite this line to work?

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • The compiler is telling you there are no lowering for set operations. You probably can’t do what you are asking about – talonmies Feb 07 '23 at 01:06

1 Answers1

0

You can replace with a manual set construction instead of a set comprehension. Instead of:

new_combs = {c for l in lengths for c in combinations(theuniquegenes, l)}

do:

new_combs = set()
for l in lengths:
  for c in combinations:
    new_combs.add(c)

This removes the nested function definition implicit in the commprehension, which Numba does not support.

NB: Soon enough, you may be able to write your original code in Numba with PEP 709: Inlined comprehensions.

tekknolagi
  • 10,663
  • 24
  • 75
  • 119