1
$\begingroup$

I am trying to understand the usage of vqe.compute_minimum_eigenvalue API of qiskit for the statevector_simulator and qasm_simulator. I am only interested in the eigenstate and eigenvalue. When I run the below code for statevector_simulator, I get the below as shown below:

backend = Aer.get_backend("statevector_simulator")
    quantum_instance = QuantumInstance(backend= backend, 
                                       shots= 1
                                       seed_simulator= 28,    
                                       seed_transpiler= 28, 
                                       basis_gates= None,                                                 
                                       optimization_level=0)

    vqe = VQE(ansatz=ansatz_opt, 
                optimizer= optimizer,
                quantum_instance=quantum_instance,
                initial_point=initial_point_values
                )
    result = vqe.compute_minimum_eigenvalue(H_op)
    print("The value of result is =", result)

The value of result is:

The value of result is = {   'aux_operator_eigenvalues': None,
    'cost_function_evals': 1352,
    'eigenstate': array([0.01715463+0.42191317j, 0.02261512+0.55615892j,
       0.02288142+0.56255103j, 0.01794385+0.44109138j]),
    'eigenvalue': (1.2502114e-10+0j),
    'optimal_circuit': None,
    'optimal_parameters': {   ParameterVectorElement(θ[3]): 1.8871963979619928,
                              ParameterVectorElement(θ[0]): 3.4198843373829284,
                              ParameterVectorElement(θ[2]): 4.2904615454665835,
                              ParameterVectorElement(θ[1]): 0.8448563317717608,
                              ParameterVectorElement(θ[4]): 3.448308970824199,
                              ParameterVectorElement(θ[5]): 3.5108928973122078,
                              ParameterVectorElement(θ[6]): 4.155936156778078,
                              ParameterVectorElement(θ[7]): 5.828853129364108,
                              ParameterVectorElement(θ[8]): 2.717512248330424,
                              ParameterVectorElement(θ[9]): 1.1104402869985177,
                              ParameterVectorElement(θ[10]): 0.35997873578438755,
                              ParameterVectorElement(θ[11]): 5.383757228721264,
                              ParameterVectorElement(θ[12]): 2.2265588674752292,
                              ParameterVectorElement(θ[13]): -0.524391503109095,
                              ParameterVectorElement(θ[14]): 2.721212459791864,
                              ParameterVectorElement(θ[15]): 1.584924993236795,
                              ParameterVectorElement(θ[16]): -0.49539861026959436,
                              ParameterVectorElement(θ[17]): 4.162724464416642,
                              ParameterVectorElement(θ[18]): 3.6325193273490144,
                              ParameterVectorElement(θ[19]): 6.662136048337769},
    'optimal_point': array([ 3.41988434,  0.84485633,  4.29046155,  1.8871964 ,  3.44830897,
        3.5108929 ,  4.15593616,  5.82885313,  2.71751225,  1.11044029,
        0.35997874,  5.38375723,  2.22655887, -0.5243915 ,  2.72121246,
        1.58492499, -0.49539861,  4.16272446,  3.63251933,  6.66213605]),
    'optimal_value': 1.2502114e-10,
    'optimizer_evals': None,
    'optimizer_result': None,
    'optimizer_time': 52.66859722137451}

But when I run the code for qasm_simulator, I get the results as below:

backend = Aer.get_backend("qasm_simulator")
    quantum_instance = QuantumInstance(backend= backend, 
                                       shots= 1000000
                                       seed_simulator= 28,    
                                       seed_transpiler= 28, 
                                       basis_gates= None,                                                 
                                       optimization_level=0)

    vqe = VQE(ansatz=ansatz_opt, 
                optimizer= optimizer,
                quantum_instance=quantum_instance,
                initial_point=initial_point_values
                )
    result = vqe.compute_minimum_eigenvalue(H_op)
    print("The value of result is =", result)

The value of result is

The value of result is = {   'aux_operator_eigenvalues': None,
    'cost_function_evals': 1,
    'eigenstate': {   '00': 0.13272528018429647,
                      '01': 0.3030214513858714,
                      '10': 0.7196895163888384,
                      '11': 0.610417070534565},
    'eigenvalue': (5.67387294600939+0j),
    'optimal_circuit': None,
    'optimal_parameters': {   ParameterVectorElement(θ[2]): 4.224454970398236,
                              ParameterVectorElement(θ[0]): 5.863937784019204,
                              ParameterVectorElement(θ[1]): 3.4455864378670014,
                              ParameterVectorElement(θ[4]): 0.506017439486799,
                              ParameterVectorElement(θ[3]): 2.3690675120103775,
                              ParameterVectorElement(θ[5]): 4.79940129981895,
                              ParameterVectorElement(θ[6]): 0.09967770119784523,
                              ParameterVectorElement(θ[7]): 1.8225430500149276,
                              ParameterVectorElement(θ[8]): 1.1087175676599133,
                              ParameterVectorElement(θ[9]): 2.650606283797435,
                              ParameterVectorElement(θ[10]): 1.932734623597688,
                              ParameterVectorElement(θ[11]): 4.6581354731326785,
                              ParameterVectorElement(θ[12]): 5.42013877739097,
                              ParameterVectorElement(θ[13]): 5.232441413652715,
                              ParameterVectorElement(θ[14]): 0.2577507460800755,
                              ParameterVectorElement(θ[15]): 3.8652580750273775,
                              ParameterVectorElement(θ[16]): 3.133086142322153,
                              ParameterVectorElement(θ[17]): 5.98592177389689,
                              ParameterVectorElement(θ[18]): 2.0935707919171658,
                              ParameterVectorElement(θ[19]): 0.40662390687216604},
    'optimal_point': array([5.86393778, 3.44558644, 4.22445497, 2.36906751, 0.50601744,
       4.7994013 , 0.0996777 , 1.82254305, 1.10871757, 2.65060628,
       1.93273462, 4.65813547, 5.42013878, 5.23244141, 0.25775075,
       3.86525808, 3.13308614, 5.98592177, 2.09357079, 0.40662391]),
    'optimal_value': 5.67387294600939,
    'optimizer_evals': None,
    'optimizer_result': None,
    'optimizer_time': 163.65113639831543}

What I understand looking at statevector values is that they are coefficients, but these values are not unifying (they are completely different results). I am not able to understand the reason? Is I am doing something wrong? Please guide me. Thank for great help.

$\endgroup$

1 Answer 1

2
$\begingroup$

Using statevector simulator will give an ideal result for the computation of the operator expectation value. As the state (ansatz) is varied the value computed for any given point will always be the same. This is not the case with the qasm simulator, which samples (shots number of times) from that ideal result for the counts it gives back. The samples are random so the counts can change and this means the expectation value computed can change. You are using a large number of shots but even so, at any given point, the value will still vary. What optimizer are you using - if its a gradient based one like SLSQP small changes can throw it when it tries to compute a gradient at the local point where by default it uses finite difference with a small eps (epsilon) value where it computes the values around the point. You can try a gradient free optimizer like COBYLA, or SPSA which was designed to work in noisy conditions.

$\endgroup$
2
  • $\begingroup$ Thank you @SteveWood for great help. Which one is a better optimizer COBYLA,SPSA or ADAM? I think, ADAM would take more time? $\endgroup$
    – Manu
    Commented Mar 17 at 21:17
  • $\begingroup$ The SPSA in Qiskit Algorithms has no early termination, but just continues until maxiter. Given the old code you seem to be using I do not even think that SPSA supports a user provided one, which was added at some point. Maybe give COBYLA a try first - see what works for your setup. $\endgroup$
    – Steve Wood
    Commented Mar 17 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.