Improve flipping sequence generation - #1507
Conversation
… multiple appends
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1507 +/- ##
==========================================
- Coverage 94.41% 94.36% -0.06%
==========================================
Files 136 136
Lines 10659 10653 -6
==========================================
- Hits 10064 10053 -11
- Misses 595 600 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| qd_detuned = update.replace( | ||
| qd_pulse, amplitude=qd_pulse.amplitude + delta_amplitude | ||
| ) | ||
| sequence.extend([(qd_channel, qd_detuned)] * (flips * (4 if rx90 else 2))) |
There was a problem hiding this comment.
I don't think this will be a big issue because in flipping we are not sweeping over no pulse nor channel, so even though the pulses have the same UUID this should in principle still work. However if you do a list comprehension maybe you can achieve still a speedup but this time you'll avoid duplicating the same pulse N times, since UUID will be different everytime.
| sequence.extend([(qd_channel, qd_detuned)] * (flips * (4 if rx90 else 2))) | |
| sequence.extend([(qd_channel, qd_detuned) for _ in range(flips * (4 if rx90 else 2))]) |
There was a problem hiding this comment.
I increased the max flips to 50 just to exaggerate the example
Proposed method (avg): 6.909229274839163s
List comprehension (avg): 7.0412845250219105s
Also, both methods preserve the UUID since its just using the same object as a reference
natives = platform.natives.single_qubit[0]
qd_channel, qd_pulse = natives.RX()[0]
qd_detuned = update.replace(
qd_pulse, amplitude=qd_pulse.amplitude + 0.05
)
subseq = [(qd_channel, qd_detuned) for _ in range(2)]
print(subseq[0][1].id == subseq[1][1].id)
subseq = [(qd_channel, qd_detuned)] * 2
print(subseq[0][1].id == subseq[1][1].id)True
True
There was a problem hiding this comment.
Ah yeah you're right, actually I was wrong, either you call the replace function in the list comprehension or maybe we can use model_copy method, maybe even new method of _PulseLike class.
There was a problem hiding this comment.
This PR is no more linked to #1508, for which we need to recycle the same pulse for the entire experiment;
this function is then used only for the flipping, which does not sweep over any pulse, hence we don't have memory problems and the number of identical pulses is no more a constraint.
If for you is fine to use even here the same pulse for different qubits and for the entire experiment, then this PR is fine to merge for me.
While testing #1504, I noticed that the flipping sequence generation was a bit slow especially with the default settings.
I tried to speed it up by moving the detuned pulse generation out of the loop and using
list.extendinstead of multiplelist.appendcalls. Not sure if there is a problem for the other instruments if the same pulse object is reused.QPU test to check if flipping still works
flipping.tar.gz
Small perf test and script