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

Pretty good pretty bad measurements #522

Merged
merged 19 commits into from
Apr 5, 2024

Conversation

vprusso
Copy link
Owner

@vprusso vprusso commented Mar 28, 2024

Closes #147

Description

Adding the ability to generate a set of either "pretty good" or "pretty bad" measurement operators.

Copy link

codecov bot commented Mar 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.1%. Comparing base (e7e9064) to head (3d7156d).
Report is 10 commits behind head on master.

Additional details and impacted files
@@          Coverage Diff           @@
##           master    #522   +/-   ##
======================================
  Coverage    98.1%   98.1%           
======================================
  Files         160     162    +2     
  Lines        3090    3112   +22     
  Branches      751     760    +9     
======================================
+ Hits         3032    3054   +22     
  Misses         37      37           
  Partials       21      21           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@purva-thakre
Copy link
Collaborator

purva-thakre commented Mar 28, 2024

Is it Ok if I review this by next Thursday? I want to wrap up the WIP RFC we have for Mitiq over the next few days.

@purva-thakre purva-thakre added this to the v1.0.8 milestone Mar 28, 2024
@vprusso
Copy link
Owner Author

vprusso commented Mar 28, 2024

Is it Ok if I review this by next Thursday? I want to wrap up the WIP RFC we have for Mitiq over the next few days.

Of course, no rush, and thank you again!

Copy link
Collaborator

@purva-thakre purva-thakre left a comment

Choose a reason for hiding this comment

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

Added some quick review comments as I make my way through the 2 papers used for this PR. Will add more comments/suggestions later!

BTW great job with the turnaround for the pretty_bad_measurement function! I saw that it appeared on the arXiv just last week. :)

toqito/measurements/pretty_good_measurement.py Outdated Show resolved Hide resolved
Comment on lines +53 to +54
if probs is None:
probs = n * [1 / n]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you assuming the input ensemble is always normalized? If not, there could be an additional check before lines 53-54 because assuming a uniform distribution by default might not work in the non-normalized scenario when the input probs are not provided.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm. I'm assuming that the probability vector is normalized (if provided). I check to ensure that the vector is a valid probability vector (i.e., it sums to 1). If such a vector is not provided, I decide to use a uniform distribution as a default (which is the section that you've highlighted here).

Maybe I'm missing the broader point here though of what you're trying to convey.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am talking about a case when the provided input vector ensemble is not normalized such that it might not agree with a uniform probability distribution.

For example, the function is provided a non-normalized input ensemble of 4 vectors but we skip providing an input probability distribution that would also normalize the input vector ensemble: 1/3, 1/6, 1/6, 1/3 is different from 1/4, 1/4, 1,4, 1,4.

I think it might be better to use the square root of the inner product of each vector in the non-normalized ensemble with itself to assign a probability distribution after the highlighted lines. Hopefully, this makes sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps, a better example is the trine state example from both docstrings.

image
What if the input is provided as u_1, u_2 (without -1/2), u_3 (without -1/2). It won't make sense to use a uniform probability distribution 1/3, 1/3, 1/3 in this case.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Hmm, but I think there might be a distinction here, right? The probabilities in this case are intended to be treated as "the probability with which the state is selected from the set of states" (so, the ensemble is a tuple--(p_i, rho_i) where the state is a density operator and the p_i is a probability that corresponds to the probability that rho_i is selected). So, IOW, the 1/2 and -1/2 here in this case aren't necessarily relevant to the probability vector object (they are only relevant insofar as they are used to define the actual state).

Does that make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't sat down to do the actual calculations but wouldn't a non-normalized state alter the output of what we consider a PGM or PBM?

If not, then go ahead and merge this PR!

Copy link
Collaborator

@purva-thakre purva-thakre Apr 5, 2024

Choose a reason for hiding this comment

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

Actually, no. I'll go ahead and merge.

toqito/measurements/pretty_bad_measurement.py Show resolved Hide resolved
toqito/measurements/pretty_bad_measurement.py Show resolved Hide resolved
@vprusso
Copy link
Owner Author

vprusso commented Apr 3, 2024

As an added benefit, I think I nipped that pesky docs bug that was causing pseudo-failures in this diff as well just FYI! (@purva-thakre )

vprusso and others added 4 commits April 4, 2024 17:46
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
vprusso and others added 3 commits April 4, 2024 17:47
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
Co-authored-by: Purva Thakre <66048318+purva-thakre@users.noreply.github.com>
@vprusso
Copy link
Owner Author

vprusso commented Apr 5, 2024

Modulo those comment responses, I believe this is in a good state to go. Good call on adding the issue for docs--I think that's a neat idea! Let me know if you disagree, but if you do agree, feel free to let me know or merge away! 🚀

@purva-thakre purva-thakre merged commit 821602e into master Apr 5, 2024
18 checks passed
@purva-thakre purva-thakre deleted the pretty-good-pretty-bad-measurements branch April 5, 2024 22:39
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.

Feature: Pretty Good Measurement
2 participants