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

Make Clifford objects hashable #8584

Closed
wants to merge 1 commit into from
Closed

Make Clifford objects hashable #8584

wants to merge 1 commit into from

Conversation

itoko
Copy link
Contributor

@itoko itoko commented Aug 19, 2022

Summary

Make Clifford and StabilizerTable objects hashable so that they can be a key of mapping objects.

@itoko itoko requested review from a team and ikkoham as code owners August 19, 2022 06:42
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

@itoko itoko added the Changelog: New Feature Include in the "Added" section of the changelog label Aug 19, 2022
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2887577566

  • 4 of 6 (66.67%) changed or added relevant lines in 2 files are covered.
  • 3 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.002%) to 84.052%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/quantum_info/operators/symplectic/clifford.py 2 3 66.67%
qiskit/quantum_info/operators/symplectic/stabilizer_table.py 2 3 66.67%
Files with Coverage Reduction New Missed Lines %
qiskit/quantum_info/operators/symplectic/stabilizer_table.py 1 88.24%
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
Totals Coverage Status
Change from base Build 2882958684: 0.002%
Covered Lines: 56323
Relevant Lines: 67010

💛 - Coveralls

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Clifford and StabilizerTable are mutable, so doing this breaks the Python data model. We can't put these methods on these classes in general, but if you need to be able to hash them for some external use where you guarantee you won't mutate them, you can use an extra "lookup function" in your code:

def my_hash(clif):
   return ...

and use the output of this in the set/dict. It's functionally equivalent, but the user has to manually call the hash function when doing stores / lookups. If you need to be able to access the Clifford objects from a key, you can keep a separate table which maps hashes to Clifford objects.

@jakelishman
Copy link
Member

(Also, if you need it for speed, #7483 has the fastest implementation of hash I could find as a private method.)

@itoko
Copy link
Contributor Author

itoko commented Aug 20, 2022

Ah, I missed the most basic thing in the first place, Clifford and StabilizerTable are mutable... Thank you for your comments, @jakelishman As you guessed, I wanted to use lru cache for speeding up Clifford to Instruction conversion. I've understood I need to think of another way to speed up. (I'll also check #7483)

@itoko itoko closed this Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants