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

feat: add str, repr and getitem to BasisState #808

Merged
merged 6 commits into from
Dec 6, 2023
Merged

Conversation

ajberdy
Copy link
Contributor

@ajberdy ajberdy commented Nov 21, 2023

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

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ajberdy ajberdy requested a review from speller26 November 21, 2023 02:38
@ajberdy ajberdy requested a review from a team as a code owner November 21, 2023 02:38
@ajberdy ajberdy mentioned this pull request Nov 21, 2023
5 tasks
Copy link

codecov bot commented Nov 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (dedfb72) 100.00% compared to head (44dd05e) 100.00%.

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.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jcjaskula-aws jcjaskula-aws left a 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?

src/braket/circuits/basis_state.py Show resolved Hide resolved
@ajberdy
Copy link
Contributor Author

ajberdy commented Nov 21, 2023

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])

Copy link
Contributor

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 BasisStates in conditions.

Suggested change
def __bool__(self):
return any(self.state)

@ajberdy ajberdy merged commit 608a8dc into main Dec 6, 2023
24 checks passed
@ajberdy ajberdy deleted the basis-state-slice branch December 6, 2023 20:42
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.

3 participants