-
Notifications
You must be signed in to change notification settings - Fork 23
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
Autoshape and fock improvements #397
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #397 +/- ##
===========================================
+ Coverage 87.95% 88.03% +0.07%
===========================================
Files 81 80 -1
Lines 6310 6443 +133
===========================================
+ Hits 5550 5672 +122
- Misses 760 771 +11
Continue to review 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.
Awesome work!
I found a few spots with unexpected behaviour/edge case bugs, but nothing that can't be easily squashed.
Again, I may be "doing it wrong(TM)", but I was expecting this to change the shape as the squeezing increases. Am I missing a step somewhere: import numpy as np
import mrmustard as mm
from mrmustard.lab_dev import *
for r in np.linspace(0.0, 3.0, 31):
cc = Number([0], 0) >> Sgate([0], r)
cc.auto_shape()
f = cc.fock()
tail = np.sqrt(np.sum(np.abs(f[..., -10:])**2))
print(f"r={r:0.2f}, shape={cc.fock_shape}, tail={tail}") Here's my output:
Should the shape not increase as |
@aplund I think you wanted this: for r in np.linspace(0.0, 3.0, 31):
cc = Vacuum([0]) >> Sgate([0], r)
cc.auto_shape()
print(f"r={r:0.2f}, shape={cc.fock_shape}") # works The issue with your code was that |
So there's an implicit difference between When I run the code you suggested, I get the output:
Is this the expected behaviour? |
Co-authored-by: Eli Bourassa <[email protected]>
Co-authored-by: Eli Bourassa <[email protected]>
… into opt_contraction
Sure, we can make it clearer in the docstrings.
Yes, now it is. I have removed the lines where |
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.
My only remaining comment is to please include NotImplementedError's for autoshape on batched Bargmann DMs and Kets, since if the method was used as currently written, it would produce incorrect results.
Since that is an easy change to make, and since my only other comments are just catching a couple typos in docstrings, I'm providing an approval so that you don't need to wait on a follow-up review from me after you make those changes.
Not sure if @timmysilv or @aplund wanted to have a second look either?
Co-authored-by: Eli Bourassa <[email protected]>
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.
looks good! just a few little things
Co-authored-by: Matthew Silverman <[email protected]>
… into opt_contraction
Context:
A recommended Fock shape of the components of a circuit can often be determined by the nature of the components and their connectivity. Also, for certain components like
States
we can determine a good choice of shape by stopping e.g. at 99.9% of the norm.Description of the Change:
CircuitComponent
s now have the property.manual_shape
which can be set manually. It starts as[None,...]
and it can be modified like e.g.my_state.manual_shape[1]=9
and now it will be[None, 9, None, ...]
.CircuitComponent
s now have the method.auto_shape()
which computes and returns a tuple with a guesstimate of the recommended shape to the best of our knowledge. It will respect the values in.manual_shape
that have already been set.Circuit
now has the methodpropagate_shapes()
which exploits the context of each component to produce a more compact shape thanauto_shape()
would give in isolation. This gives theCircuit
the power to contract an arrangement of components in theFock
representation in a close to optimal way (excluding throwing SVDs around), when combined with the optimal contraction path (upcoming).autocutoff
method (nowautoshape_numba
). It doesn't any longer travel back and forth between phase space and Bargmann for each mode, and it's the same as Robbe's diagonal method, but specialized for this task, so it's faster.CircuitComponent
so that wire information is available