grape_unitary: Incompatible Qobj shapes

86 views
Skip to first unread message

gözde üstün

unread,
May 5, 2022, 6:26:10 AM5/5/22
to QuTiP: Quantum Toolbox in Python
I am trying to run grape_unitary function but I am getting the following error:

grape_error.png
I actually posted another message in the group but for some reason, it is not in the forum. So I am writing again. 
I actually did not understand what can cause this error.
And here is my code:
Hamiltonian.py

Simon Cross

unread,
May 12, 2022, 7:17:39 AM5/12/22
to qu...@googlegroups.com
Hi Gözde,

You need to specify the dimensions if you create a Qobj from a numpy array, like so:

  my_unitary=Qobj(my_unitary, dims=[[2, 2, 2], [2, 2, 2]])

Without the dims specified, they default to [[8], [8]] which then does not match the dimensions of your H_s and H_non_stat.

When submitting examples, please check that they run by themselves -- I had to fix a number of unrelated things before I could get to your error and offer help.

Schiavo,
Simon



gözde üstün

unread,
May 13, 2022, 2:37:41 AM5/13/22
to QuTiP: Quantum Toolbox in Python
Hello,
Thanks a lot for the explanation and sorry about the code. Before submitting example, I cleaned my code since it was too long (5000 line) but probably with the cleaning, maybe I deleted something necessary...  I actually checked it too but anyway sorry about that

Also I have one small question: what is the difference between grape_unitary and cy_grape_unitary? The same code worked with cy_grape because. So if the dimensions are not match, how it could be run with cy_grape algorithm wihtout a problem?

Thanks
Best regards

12 Mayıs 2022 Perşembe tarihinde saat 21:17:39 UTC+10 itibarıyla hodg...@gmail.com şunları yazdı:

Simon Cross

unread,
May 13, 2022, 5:12:40 AM5/13/22
to qu...@googlegroups.com
Hi Gözde,

cy_grape_unitary is a Cython re-implementation of grape_unitary. The
Cython implementation uses numpy arrays in places instead of Qobjs and
thus doesn't check dimensions. It probably should, but it is also
labelled "Experimental: work in progress" in its docstring. :)

Regards,
Simon

gözde üstün

unread,
Aug 2, 2022, 8:49:31 AM8/2/22
to QuTiP: Quantum Toolbox in Python
Hello again,

I have one question. All your notebooks:
uses this line:
 u0=u0 = np.array([np.random.rand(len(times)) * 2 * pi * 0.05 for _ in range(len(H_ops))])

What this 2*pi*0.005 or 2*pi*0.05 represents? Why is it 0.005? What is the units here? Do we have any limitations over units?

I am trying to find X gate for single qubit Hamiltonian with the gyro-magnetic ratio is 28 Ghz. And I am giving my time in terms of ns: times=(0,100,100) and I can't find my X gate. I can send you my full code if you like

Thanks in advance
Gozde

13 Mayıs 2022 Cuma tarihinde saat 19:12:40 UTC+10 itibarıyla hodg...@gmail.com şunları yazdı:

Simon Cross

unread,
Aug 16, 2022, 10:29:40 AM8/16/22
to qu...@googlegroups.com
Hi Gozde,

The lines:

u0 = np.array([np.random.rand(len(times)) * 2 * pi * 0.005 for _ in
range(len(H_ops))])
u0 = [np.convolve(np.ones(10)/10, u0[idx,:], mode='same') for idx in
range(len(H_ops))]

Give the initial pulse to start the optimization from. The first line
creates small random pulse values for each time point, scaled so that
they have an amplitude that is a small fraction of 2 pi. You can
rescale these however makes sense for your problem. The second line
applies a rolling average that smooths out the random pulse.

Regards,
Simon
Reply all
Reply to author
Forward
0 new messages