1
$\begingroup$

I am trying to run the following code:

import numpy as np
from qiskit import *
from qiskit_ibm_runtime import Options   
from qiskit_ibm_runtime import QiskitRuntimeService, Estimator
from qiskit.algorithms.optimizers import NFT
from qiskit.circuit.library import TwoLocal
from qiskit.quantum_info import SparsePauliOp
from qiskit.algorithms.minimum_eigensolvers import VQE
from qiskit.opflow import X, Y, Z, I  
from qiskit.opflow import PauliSumOp


service = QiskitRuntimeService(token="YOUR-TOKEN",channel="ibm_quantum")
 
options = Options()
options.optimization_level=3 
options.execution.shots=100

#backend = service.backend("ibm_lagos")
backend = service.backend("ibmq_qasm_simulator")
estimator = Estimator(session=backend,options=options) 


hamiltonian_0= SparsePauliOp(['IIII'] ) 

hamiltonian_1=PauliSumOp(SparsePauliOp(['IIII', 'IIIZ', 'IIZI', 'IIZZ', 'IZII', 'IZIZ', 
'IZZI', 'IZZZ', 'ZIII', 'ZIIZ', 'ZIZI', 'ZIZZ', 'ZZII', 'ZZIZ', 'ZZZI', 'ZZZZ'],
              coeffs=[ 1.+0.j,  1.+0.j, 1.+0.j, 1.+0.j,  1.+0.j, 1.+0.j,
  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j,
  1.+0.j,  1.+0.j, 1.+0.j,  1.+0.j]), coeff=1.0)


dim=hamiltonian_0.num_qubits
ansatz = TwoLocal(dim, rotation_blocks=["ry"],entanglement='reverse_linear',entanglement_blocks="cx", reps=1)
optimizer = NFT(maxiter=100)


vqe = VQE(estimator=estimator, ansatz=ansatz, optimizer=optimizer )
result = vqe.compute_minimum_eigenvalue(hamiltonian_0) 

In this code I want to compare the time it takes to compute the eigenvalue for the two Hamiltonians.

If I understand correctly, the VQE algorithm calculates a circuit for each of the PauliStrings, then sums the different expectation values and finally changes the parameters and repeats the whole process. So for the hamiltonian_0 $(H_0=I\otimes I\otimes I \otimes I )$ the VQE shall make $1\times 100$ calculations and for hamiltonian_1 that has 16 Paulistrings $(H_1=\sum_{i=0}^{15} P_i )$ , the VQE shall make $16\times 100$ calculations.

Whenever I run it , the optimizer_time of the VQEResult is the same for both hamiltonian_0 and hamiltonian_1 , roughly $1000~s$ .I would expect (maybe naively) , for the hamiltonian_0 to be 16 times faster than hamiltonian_1 .

I have also made several tests with similar, up to 8 qubit Hamiltonians using the primitives, but with qasm_simulator. I get the same optimizer_time for Hamiltonians with $1$ term and with $2^8$ terms.

Does anyone know why this happens? Is it because the estimator primitive has a parallelization procedure?

$\endgroup$

1 Answer 1

0
$\begingroup$

The Runtime Estimator you used groups Paulis into commuting groups that can be measured simultaneously which is why you are seeing that result since the operator you have the paulis will group together. The Estimator from Aer has an abelian_grouping parameter where for local simulation that grouping can be disabled, but the Runtime has no such option since if you can measure them simultaneously it's more performant to do so.

I will observe that maxiter on the optimizer just limits how many iterations it can do. If it finds a minimum before that, according to its tolerances etc. it will stop, but the result will say how many iterations it did so you can factor that into account if needed.

$\endgroup$
1
  • $\begingroup$ Thank you very much ! To be honest , I do not know how to set the tolerances in NFT, unlike the SLSQP that is straightforward. $\endgroup$ 2 days ago

Your Answer

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

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