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.

Operation "element in set" never returns

See original GitHub issue

Bug: After a series of add and remove operations on a set in nopython mode the operation “in set” does not return and gets stuck at 100% CPU load.

Isolated code example:

import numba as nb

@ nb.njit()
def problem():

    # init
    openSet = set()

    openSet.add((0, 0))
    openSet.add((1, 0))
    openSet.add((2, 0))
    openSet.add((3, 0))
    openSet.add((4, 0))
    openSet.add((5, 0))
    openSet.add((6, 0))
    openSet.add((7, 0))
    openSet.add((8, 0))

    openSet.remove((2, 0))
    openSet.add((2, 1))
    openSet.remove((2, 1))
    openSet.remove((4, 0))
    openSet.add((5, 1))
    openSet.add((4, 1))
    openSet.remove((7, 0))
    openSet.add((8, 1))
    openSet.add((7, 1))
    openSet.add((6, 1))
    openSet.remove((8, 0))
    openSet.remove((1, 0))
    openSet.remove((0, 0))
    openSet.remove((5, 0))
    openSet.remove((6, 0))
    openSet.remove((3, 0))
    openSet.remove((7, 1))
    openSet.add((8, 2))
    openSet.add((7, 2))
    openSet.add((6, 2))
    openSet.remove((8, 1))
    openSet.remove((6, 1))
    openSet.add((5, 2))
    openSet.remove((4, 1))
    openSet.add((4, 2))
    openSet.remove((5, 1))
    openSet.remove((6, 2))
    openSet.add((7, 3))
    openSet.add((6, 3))
    openSet.add((5, 3))
    openSet.remove((7, 2))
    openSet.add((8, 3))
    openSet.remove((8, 2))
    openSet.remove((4, 2))
    openSet.add((4, 3))
    openSet.add((3, 3))
    openSet.remove((5, 2))
    openSet.remove((7, 3))
    openSet.add((8, 4))
    openSet.add((7, 4))
    print('About to check (6,4) in openSet')
    return (6, 4) in openSet


if __name__ == "__main__":
    print(problem())
    print('DONE')

The code gets stuck with numba 0.52.0 with Python 3.8.5 on Ubuntu 20.04.1 LTS x86_64.

However, @esc on gitter.im also confirmed that the issue persists on OSX.

Isolated code example: https://github.com/icezyclon/astart-pathfinding/blob/main/isolated.py Original code example (from A* search): https://github.com/icezyclon/astart-pathfinding/blob/main/problem.py

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:40 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
esccommented, May 28, 2021

@stuartarchibald and I never got to the bottom of this fully. But we are certain there is a bug present, so I will re-label thhis accordingly.

1reaction
esccommented, Dec 8, 2020

We can’t simply terminate on seeing “DELETED” because the lookup chain needs to remain intact. Otherwise you get issues like the one with About to remove (8, 2) from openSet – where there is one (or maybe more) “DELETED” slots within the lookup chain. Only when we have circled around once, visited all the slots and determined they are either “IN-USE” or “DELTED”, can we safely determine, that the element being looked for isn’t in the set. Incidentally, this also means, the runtime will be exactly O(n) since we need to visit every slot to determine the element isn’t in there.

Should the lookup time for sets no be an average of O(1)? I thought they are similar to dicts? If it is always O(n) then that would mean losing a big advantage in comparison to lists.

See https://wiki.python.org/moin/TimeComplexity for CPython TimeComplexity.

The worst case, only happens under the special circumstances, if the set contains only in-use or deleted slots. If the load on the set is low, the runtime will be O(1) yes, since only a hash is needed to lookup an element.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to retrieve an element from a set without removing it?
In python 3 keys() is an O(1) operations, so yay! However, it no longer returns a list object, it returns a set-like object...
Read more >
Sets - Ada Resource Association
A set never contains two or more equivalent elements. The length of a set is the number of elements it contains.
Read more >
A.18.7 Sets
A set never contains two or more equivalent elements. The length of a set is the number of elements it contains.
Read more >
Python Sets Tutorial: Set Operations & Sets vs Lists - DataCamp
Discover Python Sets. Understand the difference between sets vs lists. Find Python set operations and code examples today!
Read more >
5.1: Sets and Operations on Sets - Mathematics LibreTexts
We have used logical operators (conjunction, disjunction, negation) to form new statements from existing statements. In a similar manner, ...
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