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

Fix CollectCliffords to index nodes using their ids #13484

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexanderivrii
Copy link
Contributor

@alexanderivrii alexanderivrii commented Nov 24, 2024

Summary

Fixes #13457.

This PR changes the internal field in_degree in BlockCollector to be indexed by the ids of the nodes rather than by nodes themselves. See also #13424 for a related discussion.

In particular, this avoids hashing the nodes as python objects, both making the code faster and avoiding problems for things like PauliLindbladError coming from qiskit_aer.

Details and comments

I am not sure if this change really deserves a release note, but I have decided to add one, given that it does address a reported bug.

Needed because this field is named differently in DAGOpNode and DAGDepNode.
@alexanderivrii alexanderivrii requested a review from a team as a code owner November 24, 2024 07:52
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@alexanderivrii alexanderivrii changed the title Collect cliffords Fix CollectCliffords to index nodes using their ids Nov 24, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11994394990

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • 10 unchanged lines in 4 files lost coverage.
  • Overall coverage increased (+0.002%) to 88.938%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/expr.rs 1 94.02%
crates/circuit/src/packed_instruction.rs 2 94.1%
crates/circuit/src/dag_node.rs 2 79.7%
crates/qasm2/src/lex.rs 5 92.23%
Totals Coverage Status
Change from base Build 11977726745: 0.002%
Covered Lines: 79409
Relevant Lines: 89286

💛 - Coveralls

@@ -54,7 +54,7 @@ def __init__(self, dag: DAGCircuit | DAGDependency):

self.dag = dag
self._pending_nodes: list[DAGOpNode | DAGDepNode] | None = None
self._in_degree: dict[DAGOpNode | DAGDepNode, int] | None = None
self._in_degree: dict[int, int] | None = None
Copy link
Member

Choose a reason for hiding this comment

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

This is problematic, using the node ids is only safe for a single dag. If we want to switch this to be keyed on node ids we can not cache it. We could get away with the cache with the DAGNode storage because the hash and eq implementations are unique; either pre-rust dagcircuit where it was object id based or post-rust dag where this is an actual implementation. But node ids are not unique between dags and the indices are reused between dags and will refer to different nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see the point, but a single BlockCollector class only makes sense for a single DAG, in which case we should be fine using node ids, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CollectCliffords pass fails for circuit with large PauliLindbladError
4 participants