# QuantumCircuit with list of qbits as an argument

How to create a variable qbit QuantumCirciut like this ? I need to put v list on QuantumCircuit() method

n = 4 #number of vector to encode
v = list() #list of register qbits to encode 4 vectors
a = QuantumRegister(1,"a") #ancilla qbit
for i in range(n):
v.append(QuantumRegister(2,"v"+str(i))) #creates n QuantumRegister
b = ClassicalRegister(1,"b") #classical bit
c = QuantumCircuit(a,?,b)


You can use QuantumCircuit.add_register() to add a new register (classical or quantum) whenever there is a need:

a = QuantumRegister(1, "a") #ancilla qbit
b = ClassicalRegister(1, "b") #classical bit

c = QuantumCircuit(a, b)

v0 = QuantumRegister(2, "v0")
c.x(v0)

# You can add more registers even if the circuit already contains some gates:
v1 = QuantumRegister(2, "v1")

# You can use registers the same way regardless of how they added to the circuit:
c.cx(v1, a)

• Thank you very much! Jun 6 at 8:46

If I am understanding the question correctly, this would be one approach:

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister

n = 4 # number of vectors to encode

# list of 2 qubit quantum registers to encode n vectors
v = [QuantumRegister(2, 'v'+str(i)) for i in range(n)]

a = QuantumRegister(1, 'a') # ancilla qbit

b = ClassicalRegister(1, 'b') # classical bit

c = QuantumCircuit(*v, a, b)