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

Add results.counts() method to allow easy counting of sampling data #157

Open
josh146 opened this issue Aug 2, 2019 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@josh146
Copy link
Member

josh146 commented Aug 2, 2019

Something that would be nice to have, as a convenience to the user, is a results.counts() method, that analyzes the sampled data and returns counts. I.e.,

>>> results.counts()
{'0,0,0,0': 46,
 '0,1,0,0': 10,
 '1,0,1,0': 1,
 '1,0,0,0': 4,
 '0,0,1,0': 9,
 '2,0,0,3': 1,
 '0,0,0,1': 9,
 '0,1,1,0': 5,
 '0,0,1,1': 3,
 '2,0,1,1': 1,
 '0,1,0,1': 2,
 '0,0,0,2': 2,
 '0,1,1,1': 1,
 '0,2,0,0': 1,
 '0,2,1,1': 1,
 '0,0,2,0': 2,
 '1,0,0,1': 1,
 '1,0,0,2': 1}

This is relatively easy to do, so should be a small PR:

from collections import Counter

def count(self):
    # convert a single shot of samples into a bitstring,
    # for example [0, 1, 0, 2] -> "0102"
    bitstrings = [",".join([str(j) for j in i]) for i in self.samples.T]
    # count the number of times each bitstring occurs
    return {k:v for k, v in Counter(bitstrings).items()}
@josh146 josh146 added the enhancement New feature or request label Aug 2, 2019
@josh146
Copy link
Member Author

josh146 commented Aug 2, 2019

(Note that this really only makes sense for measurements that return integer results, such as MeasureFock() or MeasureThreshold()).

@co9olguy
Copy link
Member

co9olguy commented Aug 8, 2019

seems like something that should be packaged as a method of the Results class. Might make sense to make both results.samples and results.counts lazy-loading?

@josh146
Copy link
Member Author

josh146 commented Aug 9, 2019

Might make sense to make both results.samples and results.counts lazy-loading?

Definitely would be nice! Especially to reduce network load.

@felipeoyarce
Copy link
Contributor

Hi @josh146 and @co9olguy 😄 I would like to work in this issue, what do you think?

@co9olguy
Copy link
Member

Hi @felipeoyarce, thanks for your interest.

This is quite an old issue, but I think it's still applicable, so if you want to take a chance at it, go for it 🙂

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

No branches or pull requests

3 participants