Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:19:47+00:00 2026-06-05T06:19:47+00:00

I have written a function using a quantum simulation class QuTIP that returns a

  • 0

I have written a function using a quantum simulation class QuTIP that returns a float. Next, I called scipy.optimize.fmin_cg on the function. I keep getting the error:

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

on the line:

U_sq = H_sq.expm

But H_sq is an instance of Qobj, not an ndarray. If I run the function outside of scipy.optimize.fmin_cg, it returns the type as ‘instance’; when it runs inside of fmin_cg it returns the type as ‘ndarray’.

Why does it do this? Is there a optimization function in python that will respect using instances like this?

Here is the code:

from qutip import *
from 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,));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:19:49+00:00Added an answer on June 5, 2026 at 6:19 am

    The issue here is that fmin_cg is passing an ndarray (of length 1) to your objective function. You can extract the scalar value by just changing the first line of sq_fidelity to:

    H_sq = squeez(N, float(eps))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function that retrieves a html template, then binds data using
I have written a DLL which exports a function that creates a window using
I am using native function in my java class. I have written C++ function
I have written a function that takes two arguments and returns a SETOF result.
I have written a form using the jQuery .post() function to post the data
I have written a function that positions a tooltip just above a textbox. The
I have written a javascript function that uses setInterval to manipulate a string every
I have written a PHP function to take a video embed code that has
I have written a function which basically hides the complication of using the pySnmp
I have written a function that checks if to files are duplicates or not.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.