-
Notifications
You must be signed in to change notification settings - Fork 56
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
Calculation of n-body marginals of a GBS distribution #253
Conversation
Codecov Report
@@ Coverage Diff @@
## master #253 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 21 21
Lines 1319 1337 +18
=========================================
+ Hits 1319 1337 +18
Continue to review full report at Codecov.
|
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.
Mostly I'm just a little confused by what this function is trying to do.
So my first request is to improve the docstring.
Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
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.
Since I know wheel builds can be flaky, I'm going to go ahead and approve.
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.
Fixing some rendering issues.
But thanks for adding this documentation 💯
Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
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.
I missed the itertools.product
code snippet, but once that's merged, all good to go 👍
Co-authored-by: Christina Lee <chrissie.c.l@gmail.com>
Calculation of n-body marginals of a GBS distribution.
For an M-mode Gaussian state there exists a photon number distribution with probability mass function
p[i_0,i_1,\ldots, i_{M-1}]
The function
n_body_marginals
calculates the first n-body marginals of the (all-mode) probability distribution p. The n=1 marginals or single body marginals are simply the probability that mode k has i photons, i.e. p_k[i].For n=2 one obtains the two-body probabilities. For two modes k and l this is a two dimensional probability distribution p_{k,l}[i,j]
Note that these marginals have interesting permutation properties, for example p_{k,l}[i,j] = p_{l,k}[j,i].
The function provided here takes advantage of these symmetries to minimize the amount of calculations.
The return of the function is a list of tensors where the first entry contains the one-body marginals of the M modes (giving a tensor of shape (M, cutoff)), the second entry contains the two-body marginals (giving a tensor of shape (M,M,cutoff, cutoff)) and so on and so forth.
To be clever about not calculating things that can be obtained by permutations it checks whether the index vector representing the modes is sorted. From the way
itertools.product
works we know that it will always a sorted index vector before generating any of its unordered permutations. Thus whenever the index vector is ordered we perform the numerical calculation.If it is a unsorted index vector it realizes, in line 671 that it can be obtained by permuting the marginal distribution of something that has already been calculated.
Finally, one extra thing about notation, we take a mode index vector with repetitions, for example (1,1,2,2) to not mean a 4 body marginal but rather a two-boyd marginal for modes (1,2). That is why the
ind
variable is turned into a set in line 666.We use OrderedDict to remove repeated elements from a list and we use
argsort
to find the correct permutations allowing to figure how to permute the k-body marginal of a sorted index vector into an unsorted one.