QuEraComputing / bloqade-python

QuEra's Neutral Atom SDK for Analog QPUs
https://bloqade.quera.com/
Other
51 stars 13 forks source link

durations, values, etc. should be able to be iterables #694

Open jon-wurtz opened 9 months ago

jon-wurtz commented 9 months ago

Describe the bug One of those feature/bug things; the type requirements when specifying durations and values for a piecewise_linear waveform are too strict.

Minimal broken example

times = np.linspace(0,2,51)
values_func = lambda t:exp(-(t-1)**2)
values = map(times,values_func)

program. . . .piecewise_linear(durations = np.diff(times), values = values)

Expected behavior The function accepts and interprets the inputs correctly

And yes, I understand that "in principle" I could bloqade-ify values_func but at this moment that is too deep in the IR to be functional...

weinbe58 commented 9 months ago

And yes, I understand that "in principle" I could bloqade-ify values_func but at this moment that is too deep in the IR to be functional...

I don't understand what this means, decorators are just python functions so you should be able to do this pretty easily with the current API:

from bloqade import waveform

duration = 4
time_step = 0.05
my_waveform = waveform(duration)(lambda time: ...)
sampled_waveform = my_waveform.sample(time_step, "linear")

program = (
    ...apply(sampled_waveform)
)
jon-wurtz commented 9 months ago

Yes, you can just decorate your function as a waveform, but a user might just put an iterable for durations and values, which is completely reasonable and has an unambiguous interpretation. My example was that iterable is being constructed from a map from some function, but it could possibly be some other user method (or even them just putting in some list). In any case, an iterable is the fundamental object to be put into durations and values.

weinbe58 commented 9 months ago

just wrap the map with list? We're trying to provide clear API not ambiguous ones.