I have two (unrelated) questions when I run circuits on IBM Q Expierence.

The first one is encountered, when I run the built-in function VQE (for H2 molecule). It seems two circuits were run, and the resultant histograms seem to be different. See the first screenshot attached. I try to look up on the doc, but have no clue. May I know why is that?

The second one is encountered, when I try to create a circuit where the 0th qubit is controlled by the 5th one. This is run on ibm_16_melbourne. The compiled circuit is pretty strange, see the second screenshot attached, where the number of qubits does not seem to match (q0-q3, q8-q14 are not involved), and I am not sure if the desired property (described above) is respected. Any help would be greatly appreciated!

In both cases, the results seem to be correct/acceptable, so I think it is just a question of visualization on the IBM Q Expierence.

enter image description here

enter image description here

  • 2
    $\begingroup$ For the future, two unrelated questions should be split in two questions $\endgroup$
    – luciano
    Dec 5 '20 at 15:01

Answer to question 1: There are two circuits being executed because you are trying to find the expectation value of the Hamiltonian, $\langle \psi |H|\psi\rangle$ = $\langle \psi | \sum_i \alpha_i P_i | \psi \rangle = \sum_i \alpha_i \langle \psi|P_i|\psi\rangle $. So naively each circuit is representing one of the calculation of $\langle \psi|P_i|\psi\rangle $. For example, the electronic Hamiltonian for $H_2$ at bond distance 1.5 Angstrom under Parity Mapping with two-qubit reduction can be written as:

$$H = -1.009II + 0.1291IZ + -0.1291ZI -0.0041ZZ + 0.2295XX $$

but since $II, IZ, ZI, ZZ$ are in the same tensor product basis, they can be evaluated as single quantum circuit, and you just need to do some post processing calculations... that is you don't have to run 4 different quantum circuits, one for each. But $\langle XX \rangle$ need to have its own circuit. Hence the reason why you see two circuits here.

Regarding to question 2: I don't see how you do the transpilation process so I can't say much. When I see your orginial circuit:

enter image description here

and look at ibmq_16_device which has qubit layout as enter image description here

I would map $q_0 \to 1, q_5 \to 2, q_1 \to 3, q_2 \to 4, q_3 \to 5, q_4 \to 6 $ then this way your circuit can be executed in just depth of 2. There are other mapping you could do, of course. When I run the original circuit with optimization_level = 3 in Qiskit, I have the following transpiled circuit:

enter image description here


Regarding to OP comment on create a parametrized Ansatze for his work on VQE. An Ansatze is just a a parametrized quantum circuit, and you can create parametetrized quantum circuit pretty easy. Here is an example of how to do that with the circuit you have in mind:

%matplotlib inline
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit import QuantumCircuit, ParameterVector
from qiskit.compiler import transpile, assemble
from qiskit.visualization import *
provider = IBMQ.load_account()

var_form = QuantumCircuit(6)
params = ParameterVector('a', 6)
for i in range(6):

This will give you the following parametrized circuit:

enter image description here

You can now pass this into your VQE function! Hope this helps. :)

Also note that Qiskit does offer a few Heuristic Ansatze, like EfficientSU2 or ExcitationPreserving, TwoLocal, etc...

  • $\begingroup$ Thanks for the answering question 1, I should have realized that. Thanks. For question 2, I didn't do the transpilation. It is clear that the circuit is a closed circle with 6 sites, so on ibm_16_melbourne, I would expect to use qubits, say 0,1,2,12,13,14, isn't it? $\endgroup$
    – fagd
    Dec 5 '20 at 0:39
  • $\begingroup$ following your answer for question 1, since I am writing my own VQE, how to tell qiskit explicitly that I will need to measure two circuits in a single job submission? For example, if I will have to write a VQE for H2, and measure XX and ZZ, naively I will have to submit two jobs because their circuits differ by two H-gates at the end. How to explicitly do what the built-in VQE does here? Thanks! $\endgroup$
    – fagd
    Dec 5 '20 at 0:44
  • $\begingroup$ @fagd I think this answer will be helpful : quantumcomputing.stackexchange.com/a/12210/9858 $\endgroup$
    – KAJ226
    Dec 5 '20 at 1:46
  • $\begingroup$ @fagd Just out of curiosity, are you writing your own VQE function because you are just tired of Qiskit keep changing? I have heard several people saying that they are creating their own VQE function because of this reason. $\endgroup$
    – KAJ226
    Dec 5 '20 at 1:47
  • 1
    $\begingroup$ Yes, I figured out how to do it, thanks! $\endgroup$
    – fagd
    Dec 5 '20 at 23:02

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