Qiskit-terra: Pulse builder equispace context doesn't work with multiple channels.

Created on 19 Nov 2020  路  2Comments  路  Source: Qiskit/qiskit-terra


What is the current behavior?

Equispaced context of pulse builder doesn't work as expected. This is reported by @ajavadia .

Steps to reproduce the problem

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

image

We specified 800dt as the duration of context, however the total duration becomes 1100.
This is caused by following logic:

https://github.com/Qiskit/qiskit-terra/blob/bb627c62ddd54960a5e57a3cc73030d8071c7779/qiskit/pulse/transforms.py#L455-L467

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.

What is the expected behavior?

Suggested solutions

We should calculate the input schedule duration with

duration = sum([child_sched.duration for child_sched in schedule._children])

rather than

duration = schedule.duration

Future extension

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...

bug good first issue

All 2 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kdk picture kdk  路  4Comments

taalexander picture taalexander  路  6Comments

ajavadia picture ajavadia  路  5Comments

manoelmarques picture manoelmarques  路  4Comments

nonhermitian picture nonhermitian  路  6Comments