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

Fix for using TDMProgram with timebins % concurrent_modes != 0 #611

Merged
merged 34 commits into from
Aug 5, 2021

Conversation

thisac
Copy link
Contributor

@thisac thisac commented Jul 21, 2021

Ready for review, but since it relies on changes in the td3-tdmprogram branch, it's best to wait till that one is merged before merging this PR. Thus the do not merge label.

Context:
The TDMProgram will produce wrong results if the number of timebins is not an integer multiple of the number of concurrent modes. This is because the tdmprogram.unroll() function simpy multiplies the unique circuit with the number of shots, not taking into account which qumode has been measured most recently.

Description of the Change:

  • The way multiple shots are calculated is changed. It now calculates each shot separately instead of stitching together several identical circuits at the end.

  • The way the measured mode order is calculated is improved (and now works with the new shots calculation).

  • TDMProgram is tidied up slightly by changing a few attributes to private and adding corresponding properties to access them.

Benefits:
The following now works properly:

theta = [0] * 3
r = 3
shots = 2

prog = sf.TDMProgram(N=2)
with prog.context(theta) as (p, q):
    ops.Xgate(50) | q[1]
    ops.MeasureHomodyne(p[0]) | q[0]
eng = sf.Engine("gaussian")
res = eng.run(prog, shots=shots)
samples = res.samples

print(samples)

outputting

[[[ 0.5660403  49.47315214 49.76274829]]

 [[48.94508121 49.77226491 51.71599116]]]

Possible Drawbacks:

Related GitHub Issues:
fixes #607

@thisac thisac requested a review from fab1an-q July 21, 2021 22:20
@thisac thisac self-assigned this Jul 21, 2021
@thisac thisac requested a review from nquesada July 21, 2021 22:22
@codecov
Copy link

codecov bot commented Jul 21, 2021

Codecov Report

Merging #611 (12b1f14) into master (ec08408) will increase coverage by 0.00%.
The diff coverage is 98.59%.

@@           Coverage Diff           @@
##           master     #611   +/-   ##
=======================================
  Coverage   98.56%   98.56%           
=======================================
  Files          77       77           
  Lines        8893     8904   +11     
=======================================
+ Hits         8765     8776   +11     
  Misses        128      128           
Impacted Files Coverage Δ
strawberryfields/program.py 100.00% <ø> (ø)
strawberryfields/tdm/tdmprogram.py 98.24% <98.38%> (+0.08%) ⬆️
strawberryfields/api/devicespec.py 95.31% <100.00%> (+0.07%) ⬆️
strawberryfields/engine.py 96.49% <100.00%> (ø)
strawberryfields/io.py 96.90% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec08408...12b1f14. Read the comment docs.

Copy link
Contributor

@fab1an-q fab1an-q left a comment

Choose a reason for hiding this comment

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

Thanks a lot @thisac, that's a beautiful fix! Passed all of my own tests as well.

@fab1an-q
Copy link
Contributor

fab1an-q commented Jul 22, 2021 via email

Base automatically changed from td3-tdmprogram to master August 4, 2021 18:27
@thisac thisac merged commit 45309dc into master Aug 5, 2021
@thisac thisac deleted the tdm-shots-fix branch August 5, 2021 22:19
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.

TDMprogram requires timebins % concurrent_modes == 0
3 participants