passing in several time dependent coef with same function

18 views
Skip to first unread message

Andrew Dawes

unread,
Nov 17, 2017, 12:44:52 AM11/17/17
to qu...@googlegroups.com
TLDR; is there an elegant way to pass several time-dependent coefficients based on the same function (but with different arguments) into mesolve?

I’m working on a problem with multiple time-dependent coefficients and using the form where

H = [H0,[H1,H1_coeff],[H2,H2_coeff]]

but in reality H1_coeff and H2_coeff are the same function but with different arguments. For the sake of simplicity say they are:

def H1_coeff(t, args):
return args[“A”] * cos(args[“k”] * t)

It seems duplicitous to have to write this twice just to pass in different args:

def H1_coeff(t, args):
return args[“A”] * cos(args[“k”] * t)

def H2_coeff(t, args):
return args[“A2”] * cos(args[“k2”] * t)

but I can’t seem to think of a better way to do it since ultimately the args have to be passed in to mesolve as one big dict.

This example is somewhat trivial since I can manage two functions just fine, but four, five or more and it gets unwieldy. I’d like to see about allowing a format like:

H = [H0,[H1,H1_coeff, H1_args],[H2,H2_coeff, H2_args]]

Tracking this possibility through the code, I see there is potential issue in drho_list_td where L_list is being assembled from all the elements in H:

L = L_list[n][0]
L_td = L_list[n][1]
if L_list[n][2]:
spmvpy_csr(L.data, L.indices, L.indptr,
rho, L_td(t, args)**2, out)

There already appears to be something handling the case of a three-element list (to deal with c_square?). I don’t know if there are other dealbreakers for trying to implement something like this, or perhaps I’m missing a simpler way forward.

Hope this makes some sense, and thanks for any insight.
Andy





Paul Nation

unread,
Nov 17, 2017, 10:16:41 AM11/17/17
to QuTiP Group
I would use the string format, as it is easier to do what you want.  However, what you are thinking about seems about right.  I would rather do a list of dicts, or something similar, for the args rather than messing with the H lists.  They have been abused for several corner cases in the BR solver.

-P

--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Dawes

unread,
Nov 17, 2017, 10:48:00 AM11/17/17
to qu...@googlegroups.com
Thanks Paul, I hadn’t looked at the BR solver that closely so I see what you mean. I’ll mess around with the string format and see how that comes out.
-Andy

To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages