Why For loop is not appending the circuit in the first iteration, it only starts executing on the second iteration, due to which the qubit argument is mismatching with the gate expectation?
grover_operator = RemoveBarriers()(grover_operator)
n=3
lg=4
for i in range(n):
Q = circuit_to_gate(grover_operator).control().power(2**((n-1)-i))
j = i+1
qp=list(np.arange(n-j,n+lg+2))
for l in range(len(qp)):
print(qp[l])
print(" ")
qpe.append(Q,qp)
The output error it shows is:
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
---------------------------------------------------------------------------
CircuitError Traceback (most recent call last)
<ipython-input-92-a05ec5674012> in <module>
10 print(qp[l])
11 print(" ")
---> 12 qpe.append(Q,qp)
13
~/.local/lib/python3.7/site-packages/qiskit/circuit/quantumcircuit.py in append(self, instruction, qargs, cargs)
1083
1084 instructions = InstructionSet()
-> 1085 for (qarg, carg) in instruction.broadcast_arguments(expanded_qargs, expanded_cargs):
1086 instructions.add(self._append(instruction, qarg, carg), qarg, carg)
1087 return instructions
~/.local/lib/python3.7/site-packages/qiskit/circuit/gate.py in broadcast_arguments(self, qargs, cargs)
199 if len(qargs) != self.num_qubits or cargs:
200 raise CircuitError(
--> 201 f"The amount of qubit({len(qargs)})/clbit({len(cargs)}) arguments does"
202 f" not match the gate expectation ({self.num_qubits})."
203 )
CircuitError: 'The amount of qubit(8)/clbit(0) arguments does not match the gate expectation (7).'
```