Equispaced context of pulse builder doesn't work as expected. This is reported by @ajavadia .
with qk.pulse.build() as bgate_0_1:
with qk.pulse.align_equispaced(duration=800):
qk.pulse.play(qk.pulse.library.GaussianSquare(duration=600, amp=.5, sigma=30, width=400),
qk.pulse.DriveChannel(0))
qk.pulse.play(qk.pulse.library.GaussianSquare(duration=300, amp=.5, sigma=30, width=100),
qk.pulse.DriveChannel(1))
returns

We specified 800dt as the duration of context, however the total duration becomes 1100.
This is caused by following logic:
align_equispaced relocates all sub schedule blocks (_children) with equispaced interval. In above example, the pulse on d0 and d1 (they are Play instruction schedule components) are independent children and will be aligned sequentially.
Interval is decided by (specified duration - current schedule duration) / (number of children), however if the schedule under the context consists of multiple channels, some schedules may be overlapped and net schedule duration may become shorter than the sum of all duration of children.
We should calculate the input schedule duration with
duration = sum([child_sched.duration for child_sched in schedule._children])
rather than
duration = schedule.duration
Above example intends to align two pulses at the center, thus we should use the context as follows:
with qk.pulse.build() as bgate_0_1:
with qk.pulse.align_equispaced(duration=800):
qk.pulse.play(qk.pulse.library.GaussianSquare(duration=600, amp=.5, sigma=30, width=400),
qk.pulse.DriveChannel(0))
with qk.pulse.align_equispaced(duration=800):
qk.pulse.play(qk.pulse.library.GaussianSquare(duration=300, amp=.5, sigma=30, width=100),
qk.pulse.DriveChannel(1))
However this is not intuitive and we may be able to create align_center context to make multi-channel alignment easier.
with qk.pulse.build() as bgate_0_1:
with qk.pulse.align_center():
qk.pulse.play(qk.pulse.library.GaussianSquare(duration=600, amp=.5, sigma=30, width=400),
qk.pulse.DriveChannel(0))
qk.pulse.play(qk.pulse.library.GaussianSquare(duration=300, amp=.5, sigma=30, width=100),
qk.pulse.DriveChannel(1))
I'm bit busy recently so I hope someone in community will fix this...
@nkanazawa1989 Can I work on this? Also for the expected behaviour, should it be like the future extension (i.e. have them equispaced for each channel separately) or should it be staggered so that in the example, the first pulse starts at 0, but the second pulse ends at 800. If it is the latter, I am not exactly sure what the spacing should be in general though.
Thanks @msuwama for taking this issue! :) For now we should have them equispaced in parallel otherwise we cannot infer starting time of each pulse. In this specific example, total duration becomes 900 > duration=800 so input schedule block is returned just as it is. If we specify duration=1000 the first pulse starts at t=0 and second pulse starts at t=700. This is correct behavior of equispaced alignment though this is not expected behavior -- this is why we need to implement align_center context to make this alignment more intuitive.