-
Notifications
You must be signed in to change notification settings - Fork 118
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
feat: add str, repr and getitem to BasisState #808
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #808 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 129 129
Lines 8388 8396 +8
Branches 1870 1870
=========================================
+ Hits 8388 8396 +8 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add
def index(self, value: Any) -> int:
return list(self.state).index(value)
and maybe a pop
member function too?
I'm not sure about the necessity of an index function, I would say we should add it once we need it. Especially since there's only two values in the iterable. I could more so see the argument for pop, but I think it's slightly ambiguous which side gets popped. |
|
||
def __getitem__(self, item): | ||
return BasisState(self.state[item]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could define __bool__
to use BasisState
s in conditions.
def __bool__(self): | |
return any(self.state) |
Issue #, if available:
Description of changes:
Add a few convenience methods to the BasisState class
Testing done:
Manual and unit testing
Merge Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.