Skip to content

Cyclic-definition checking in Clifford segfaults Python on Windows #10415

@jakelishman

Description

@jakelishman

Environment

  • Qiskit Terra version: 0.24.1
  • Python version: 3.8
  • Operating system: Windows

What is happening?

In the file test/python/quantum_info/operators/symplectic/test_clifford.py, the test TestCliffordGates.test_from_gate_with_cyclic_definition segfaults Python on Windows if the system recursion depth is greater than about 2700. Importing jedi (which might happen via the Terra optional dependencies ipython, seaborn or ipywidgets) always sets the recursion limit to 3000.

How can we reproduce the issue?

The root cause is any too-deep recursion. If you need to test easily, you can put a call to sys.setrecursionlimit(3000) at the top of the test I mentioned above (or something like import IPython will do it for you).

What should happen?

No segfault.

Any suggestions?

I don't understand why Clifford is attempting to handle cyclic definitions - perhaps @itoko knows since the code was added in #9475. Such gates are broken in the Terra data model, and would cause an infinite loop in many places in Qiskit - definition is (from its historical roots) meant to move towards the ["u", "cx"] basis and should never cycle.

If the cyclic-definition handling wasn't added for some specific use, I'd strongly suggest that it and its test are removed. If it was added with some use, then I'd first see if the use can be changed (because it's pretty broken), and if it absolutely cannot be, then the cyclic handling needs fixing to not rely on RecursionError being raised. For one that's very slow, and for two we can't rely on the user having changed the limit; RecursionError is meant to be a catch of last resort like MemoryError, not something to be relied on.

See davidhalter/jedi#1902 and davidhalter/jedi#1925 for more detail from the Jedi side - it's arguable that Jedi shouldn't be messing with the limit in a global manner, but either way, we shouldn't be relying on RecursionError being raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions