python - Why does my 'instance' turn into an 'ndarray' when I use Scipy optimize? -


i have written function using quantum simulation class qutip returns float. next, called scipy.optimize.fmin_cg on function. keep getting error:

attributeerror: 'numpy.ndarray' object has no attribute 'expm' 

on line:

u_sq = h_sq.expm 

but h_sq instance of qobj, not ndarray. if run function outside of scipy.optimize.fmin_cg, returns type 'instance'; when runs inside of fmin_cg returns type 'ndarray'.

why this? there optimization function in python respect using instances this?

here code:

from qutip import * numpy import * import scipy.optimize   def sq_fidelity(eps,n=7):     h_sq = squeez(n,eps);     print type(h_sq);     one_ph = basis(n,1);     u_sq = h_sq.expm();     squ = u_sq*one_ph;     fidelity = expect(fock_dm(n,1),squ);     return float(fidelity)   if __name__=='__main__':     print sq_fidelity(0.2);     eps = scipy.optimize.fmin_cg(sq_fidelity, x0=0.2, args=(7,)); 

the issue here fmin_cg passing ndarray (of length 1) objective function. can extract scalar value changing first line of sq_fidelity to:

h_sq = squeez(n, float(eps)) 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -