qucontrol / krotov

Python implementation of Krotov's method for quantum optimal control
https://qucontrol.github.io/krotov
Other
70 stars 29 forks source link

ValueError when plotting guess pulses #95

Closed RolandMacDoland closed 3 years ago

RolandMacDoland commented 3 years ago

Description

I was running the guess pulse definition in a function and returned an error for the blackman waveform. It works for a Gaussian pulse definiton.

What I Did

map(cubic_poly, eps1(tlist, None))

Traceback:

<ipython-input-39-1030fd583c05> in eps1(t, args)
      5 def eps1(t, args):
      6     T = tlist[-1]
----> 7     return 0.012 * krotov.shapes.flattop(
      8             t, t_start=0, t_stop=T, t_rise=T/20, t_fall=T/20, func="blackman"
      9         )

~/Library/Caches/pypoetry/virtualenvs/pulse-oisPEMcj-py3.8/lib/python3.8/site-packages/krotov/shapes.py in flattop(t, t_start, t_stop, t_rise, t_fall, func)
     77         t_fall = t_rise
     78     if func == 'blackman':
---> 79         return _flattop_blackman(t, t_start, t_stop, t_rise, t_fall)
     80     elif func == 'sinsq':
     81         return _flattop_sinsq(t, t_start, t_stop, t_rise, t_fall)

~/Library/Caches/pypoetry/virtualenvs/pulse-oisPEMcj-py3.8/lib/python3.8/site-packages/krotov/shapes.py in _flattop_blackman(t, t_start, t_stop, t_rise, t_fall)
     97 
     98 def _flattop_blackman(t, t_start, t_stop, t_rise, t_fall):
---> 99     if t_start <= t <= t_stop:
    100         f = 1.0
    101         if t <= t_start + t_rise:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
goerz commented 3 years ago

How is cubic_poly defined?

RolandMacDoland commented 3 years ago

How is cubic_poly defined?

It is a polynomial function that I use to calibrate the pulse. Thing is, it works for a Gaussian shape but not the flat-top one.

goerz commented 3 years ago

We don't have a Gaussian shape in Krotov, so I'm not sure what you mean.

I can't really look into this without seeing the cubic_poly function, but I'm pretty sure you're passing a list or an array as t for flattop. It takes a scalar value, cf. the big "Note" in the function's documentation.

So this is not a bug