2
$\begingroup$

This is a follow-up question on composing the quantum circuits. Say if I have the following circuit element:

def qc1(a):                      
    quanc1 = QuantumCircuit(2)
    quanc1.x(0)
    quanc1.h(1)
    quanc1.crz(a,1,0)
    quanc1.barrier()
    return quanc1

and circ is a list that contains multiple elements:

circ = []
for i in range (3):
    circ.append(qc1(np.pi+i))

Then using the reduce function, I could combine those 3 circuits and compose them into a larger quantum circuit:

from functools import reduce
qc = QuantumCircuit(5,5)
qc = reduce(lambda x,y: x.compose(y,[2,4]),circ, qc)

The code works to compose the circuits in circ onto qubit 2 and 4 of qc:

enter image description here

However, if I have another set of coordinates:

c = [[2,1],[2,4],[2,3]]

Is it possible for me to compose the circuits in circ onto those pairs of coordinates, separately (instead of the fixed pair [2,4])? Or is there a simpler method than using reduce? Thanks!

$\endgroup$
2
$\begingroup$

We could use the zip function twice:

A = [...]
B = [...]
qc = reduce(lambda x,y: x.compose(y[0],[y[1][0],y[1][1]]),zip(circ,zip(A,B)), qc)

Where A and B are two lists that contain the information about which qubits we want to compose. enter image description here

$\endgroup$

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.