## Running this script should reproduce the error (but only with some probability, might not work every time. My outputs are included below, which should help since they contain the optimal parameters) from qiskit_acqua import Operator, run_algorithm from qiskit_acqua.input import get_input_instance if __name__ == '__main__': # Needed to run on Windows....... ##### INPUTS ##### ham_name = 'anharmonic_osc.txt' depth = 3 shots = 256 optimizer_name = 'SPSA' backend_name = 'local_qasm_simulator' max_trials = 300 #### Code ##### qubitOp = Operator.load_from_file(ham_name) # Find the exact energy algorithm_cfg = { 'name': 'ExactEigensolver', } params = { 'algorithm': algorithm_cfg } algo_input = get_input_instance('EnergyInput') algo_input.qubit_op = qubitOp result_exact = run_algorithm(params,algo_input) print(result_exact) ## Actual value is 0.54311567 # Use the VQE to find the energy algorithm_cfg = { 'name': 'VQE', 'operator_mode': 'matrix' } optimizer_cfg = { 'name': 'SPSA', 'max_trials': max_trials } var_form_cfg = { 'name': 'RYRZ', 'depth': depth, 'entanglement': 'linear' } backend_cfg = { 'name': backend_name, 'shots': shots } params = { 'algorithm': algorithm_cfg, 'optimizer': optimizer_cfg, 'variational_form': var_form_cfg, 'backend': backend_cfg } result_vqe = run_algorithm(params,algo_input) exact_energy = result_exact['energies'][0] vqe_energy = result_vqe['energy'] print('Exact = {}'.format(exact_energy)) print('VQE = {}'.format(vqe_energy)) print('Percent Error = {:5.2f}%'.format(abs((vqe_energy-exact_energy)/exact_energy)*100)) print('Evaluation Time = {:3.1f} min'.format(result_vqe['eval_time']/60)) print(result_vqe) ## My output when running this and getting the error: #SPSA QASM predicted time to completion: 8.8 min #Exact = 0.5431156684978454 #VQE = 0.11990765693765226 #Percent Error = 77.92% #Evaluation Time = 10.1 min #{'eigvals': array([0.11990766]), 'opt_params': array([-4.18459822, -0.08713891, 2.88980366, -1.70432337, -0.17803248, # -0.549031 , 0.9647214 , -2.71561287, -1.06855397, 3.75464493, # -1.32101058, 0.34751506, 2.99620713, 3.90377648, 0.86911818, # 0.77554301, 0.0427631 , -1.60719434, 1.70698473, -1.48407184, # -3.05888684, 1.10981806, -1.84999036, 3.57947685, -2.66736975, # -1.82249417, 2.41026891, -1.26596999, -0.21984895, -0.52698391, # -2.0564226 , -0.09892224]), 'eigvecs': array([{'0000': 235, '0001': 4, '0010': 15,# '0011': 1, '0110': 1}], # dtype=object), 'energy': 0.11990765693765226, 'eval_count': 651, 'eval_time': 604.6297063827515}