I think it is a bug but I'm not really sure. Basically, what I'm trying to do is the following: I have an Oracle Instruction which I want to append to my QuantumCircuit, looks as follows:

# initialising registers for readability
[control, train_register] = circ.qregs


# create and append oracle
oracle = create_oracle(train_register, control)  # returns an Instruction
circ.append(oracle, [train_register, control])

If my train_register and control are both QuantumRegisters with length 1, this works perfectly fine. But I want to make this work for variable length of these registers, I get the error qiskit.circuit.exceptions.CircuitError: 'The amount of qubit arguments does not match the instruction expectation.'.

This is logical, since this error occurs because qiskit checks the length of my provided qargs in QuantumCircuit.append(), and I provided two registers in a list with both one qubit, so the length of the list happens to be the same as the number of qubits.

However, I want this to work for variable length. If I know what the length of my QuantumRegisters are, say len(train_register) is 3 and len(control) is 1 I can use

circ.append(oracle, [0, 1, 2, 3])

Or to make it work for unspecified lengths, I can write something like:

indices_to_append_to = list(np.arange(len(train_register) + len(control)))
circ.append(oracle, indices_to_append_to)

But I just really like the idea of just plugging in the names of the qregs as qargs. Is there something to make this work like that?


If you pass a list of qubits instead of a list of register this works. For this do

circ.append(oracle, train_register[:] + control[:])

where train_register and control are QuantumRegisters.

| improve this answer | |
  • $\begingroup$ Thank you very much. I was almost a hundred percent certain I checked that possibility, but I think the way I did it was [train_register[:] + control[:]], which doens't work. $\endgroup$ – GroenteLepel Jun 19 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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