2
$\begingroup$

It's creating a real confusion for me especially the parameterized circuit which I have to create. Can anybody please solve this for me? I want to create this circuit.

enter image description here

$\endgroup$
2
  • $\begingroup$ Please clarify what is your confusion and what are you trying to solve. $\endgroup$
    – KAJ226
    Feb 22 at 6:16
  • $\begingroup$ See I edited the question. $\endgroup$
    – sohamb172
    Feb 22 at 6:20
3
$\begingroup$

Assuming that you are not trying to keep $|\psi \rangle$ and $|\phi\rangle$ for further computation after measuring the ancilla qubit then you can do it as follows:

Let's suppose $|\phi\rangle = |111\rangle$ amd $|\psi \rangle = |000\rangle$ , then you can execute it as:

enter image description here

where $I$ is the identity operator. It doesn't need to be there because the qubits start in the state $|0\rangle$. I just put them there as a place holder.

Now this can be done with qiskit as:

import numpy as np
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister

num_qubits = 3
circuit1 = QuantumCircuit(num_qubits)
for i in range(num_qubits):
    circuit1.x(i)

circuit2 = QuantumCircuit(num_qubits)
for i in range(num_qubits):
    circuit2.id(i)
    
swap_test_circuit = QuantumCircuit(2*num_qubits + 1,1)
swap_test_circuit.compose(circuit1, qubits=[1,2,3], inplace=True )
swap_test_circuit.compose(circuit2, qubits=[4,5,6], inplace=True )
swap_test_circuit.h(0)
for i in range(num_qubits):
    swap_test_circuit.cswap(0,i+1,i+4)
swap_test_circuit.h(0)
swap_test_circuit.measure([0],[0])
$\endgroup$
1
  • $\begingroup$ Thank you, I understood. $\endgroup$
    – sohamb172
    Feb 22 at 7:09

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.