Closed HehnLukas closed 2 years ago
Hi there!
There are multiple questions here so I will try to answer them one by one:
How to get the number of gates in your VQE: You were quite close with ansatz.count_ops()
. You can see already that there are 2 X
gates which likely come from your initial state. The other entry in that dictionary, TwoLocal
is not very informative because the counting is done on the non-decomposed ansatz. If you do ansatz.decompose().count_ops()
instead, you should be getting closer to what you expected to find.
How many measurements are made: The R(\theta)
are parameterized rotation gates. Each entry in the vector \theta
is one optimization parameter for the VQE. However, that does not map exactly to the number of measurements. Instead, the number of measurements is determined by the Hamiltonian (or qubit operator) which your are trying to find the eigenvalue of (whereas above you are looking at the quantum circuit of your Ansatz). What you need to look at here are the number of Pauli terms which are present in your qubit operator. Usually you should be able to simply print the qubit operator to get some basic information about it. If that doesn't suffice, that will usually tell you more information about the operator type based on which you can search for more information. You will also need to look at the number of shots
which are configured in your QuantumInstance
or Backend
. This number determines how often each circuit gets sampled, directly impacting the number of total measurements.
I hope this answers most of your questions. May I also suggest the Qiskit Slack workspace to you? That is usually a faster way of getting answers to more general questions like this one.
Hi, I'm relatively new to QC so I'm sorry if there is something obvious I am missing. I would like to find out how many measurements and gates a VQE takes for the execution. For example when I run the code given in the readme, but with the two_qubit_reduction set to False, I get this ansatz:
If I understand correctly, each R(θ) is a classical parameter optimization which requires a measurement. But I have no idea how to count the measurements and iterations the VQE does. I've tried using ansatz.depth() which gives 2, and ansatz.count_ops() gives this dict: {'x': 2, 'TwoLocal': 1}, but that is not what I'm looking for.