Skip to content

Fix CollectCliffords to index nodes using their ids#13484

Closed
alexanderivrii wants to merge 3 commits into
Qiskit:mainfrom
alexanderivrii:collect_cliffords
Closed

Fix CollectCliffords to index nodes using their ids#13484
alexanderivrii wants to merge 3 commits into
Qiskit:mainfrom
alexanderivrii:collect_cliffords

Conversation

@alexanderivrii

@alexanderivrii alexanderivrii commented Nov 24, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown

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

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
Copy Markdown
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
Copy Markdown
Member 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?

@alexanderivrii

Copy link
Copy Markdown
Member Author

Closing this.

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