Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cyclic-definition handling from Clifford.from_circuit #10441

Merged

Conversation

jakelishman
Copy link
Member

Summary

This reliance on RecursionError could lead to CPython crashing, when the user had raised the recursion limit beyond what their operating system could actually support in terms of Python frames. This was particularly an issue with Windows when in a context that jedi is active (such as in an IPython session, or if seaborn was imported), since jedi unilaterally sets the recursion limit to 3000, while CPython tends to overflow the stack on Windows at around 2700 frames.

Recursive definition fields are not valid data in the Qiskit model, as the definition is supposed to be hierarchical, and a decomposition in terms of gates that do not involve the current one in any form. For defining equivalences that may involve cycles, one should use the EquivalenceLibrary objects that Terra manages, and the transpiler takes advantage of via the BasisTranslator.

Details and comments

Close #10415. @itoko, you might want to look at this, since I don't know if you had a use-case in mind for the original recursion handling.

This should fix the CI problems that #8967 and #10208 have encountered.

This reliance on `RecursionError` could lead to CPython crashing, when
the user had raised the recursion limit beyond what their operating
system could actually support in terms of Python frames.  This was
particularly an issue with Windows when in a context that `jedi` is
active (such as in an IPython session, or if `seaborn` was imported),
since `jedi` unilaterally sets the recursion limit to 3000, while
CPython tends to overflow the stack on Windows at around 2700 frames.

Recursive `definition` fields are not valid data in the Qiskit model, as
the definition is supposed to be hierarchical, and a decomposition in
terms of gates that do not involve the current one in any form.  For
defining equivalences that may involve cycles, one should use the
`EquivalenceLibrary` objects that Terra manages, and the transpiler
takes advantage of via the `BasisTranslator`.
@jakelishman jakelishman added the Changelog: API Change Include in the "Changed" section of the changelog label Jul 17, 2023
@jakelishman jakelishman requested review from a team and ikkoham as code owners July 17, 2023 17:46
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core
  • @ikkoham

@mtreinish mtreinish added this to the 0.25.0 milestone Jul 17, 2023
@coveralls
Copy link

coveralls commented Jul 17, 2023

Pull Request Test Coverage Report for Build 5586605838

  • 5 of 7 (71.43%) changed or added relevant lines in 1 file are covered.
  • 13 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.02%) to 86.048%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/quantum_info/operators/symplectic/clifford_circuits.py 5 7 71.43%
Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 93.76%
crates/qasm2/src/lex.rs 2 91.65%
qiskit/quantum_info/operators/symplectic/clifford_circuits.py 4 87.8%
crates/qasm2/src/parse.rs 6 97.58%
Totals Coverage Status
Change from base Build 5582955280: 0.02%
Covered Lines: 72403
Relevant Lines: 84143

💛 - Coveralls

Copy link
Contributor

@itoko itoko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The removal of test_from_gate_with_cyclic_definition makes sense to me now. (I didn't understand recursion definition fields are invalid in Qiskit model when I wrote it.)

@mtreinish mtreinish added this pull request to the merge queue Jul 18, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 18, 2023
@jakelishman jakelishman added this pull request to the merge queue Jul 18, 2023
Merged via the queue into Qiskit:main with commit 35f9e7c Jul 18, 2023
13 checks passed
@jakelishman jakelishman deleted the remove-clifford-recursive-definition branch July 18, 2023 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cyclic-definition checking in Clifford segfaults Python on Windows
5 participants