# Can I keep composing a series of quantum circuits into a large quantum circuit?

Suppose I have a series of quantum circuits, each of them has 2 qubits:

qc = QuantumCircuit(2)
qc.h(0)
qc.crz(np.pi/2,0,1)
circ_list = [...say this is a list with 10 elements, each of them has the same structure above...]


If I also have a larger quantum circuit:

qcl = QuantumCircuit(8,8)


I want to compose each of the 10 'small circuits' onto the large circuit, I think a standard method would be:

qcom = qcl.compose(circ_list[i],[2,3]) # [2,3] is a random choice


However, if I want to simultaneously compose 10 circuits, it looks like I need to repeat the argument 10 times. I'm wondering is there a simpler way I can do that? An analogy I can think of is the reduce function:

n = [4,3,2,1]
a = reduce(lambda x,y: x*y, n)


Can I do something similar to the reduce function to compose everything at once? Thanks!!

Sure, you can do this with reduce but your list needs to also have the information about which registers you are composing onto.

So if your circ_list was a list of tuples where the first component was the circuit object and the second component was a list indicating which registers this circuit will be composed onto like [2,3]

Then you should be able to use reduce as:

reduce(lambda x,y: x.compose(y,y),circ_list, qcl)


See the docs on reduce for more description: https://docs.python.org/3/library/functools.html#functools.reduce

• Thanks for the answer! What's the function of circ_list and qcl here?
– ZR-
Feb 19 at 16:08
• circ_list is the list of things you are reducing just like in the example you gave the list n. qcl is the initial value which we start from, if we didnt specify qcl as the initial value i think the first element of the list circ_list would have been chosen instead. thats what happens in the example you gave, we dont have to specify 1 as the initial value because its ok if the list just takes the initial value as the first value in the list Feb 19 at 16:12
• Thanks, that helps a lot!
– ZR-
Feb 20 at 1:17