1

I am reading this paper and trying to implement a quantum circuit it has provided in Figure 11. I want to code this circuit using Qiskit. The circuit I am trying to implement is attached.

Circuit

I have coded some parts of the circuit so far. This is my code.

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

n = 3
qr = QuantumRegister(n, 'q')
an = QuantumRegister(1, 'ancilla')

circuit = QuantumCircuit(an, qr)

circuit.h(qr[2])
circuit.cx(qr[2], qr[1])
circuit.cx(qr[1], qr[0])
circuit.x(qr[1])
circuit.swap(qr[0], qr[1])
circuit.cu1("Pi", an[0], qr[1])
circuit.cu1("Pi/3", an[0], qr[0]) 
circuit.swap(qr[0], qr[1])
circuit.x(qr[1])
circuit.cx(qr[1], qr[0])
circuit.cx(qr[2], qr[1])
circuit.h(qr[2])
circuit.draw(output='latex')

This code generates following output. Please help me with this code.

My Circuit

Protik Nag
  • 511
  • 5
  • 20
  • Hi! Is there any specific part of the implementation that you need help with? – met927 Jan 02 '20 at 10:32
  • I want to place those U(pi) gates between those swap gates as shown in the first diagram. @met927 – Protik Nag Jan 02 '20 at 17:21
  • 2
    If it is necessary for them to go in between the swaps, then you can add a `circuit.barrier()` after the first swap, then attach the `u1(pi)` gates, and then put another barrier before the second swap. Though, it seems that the original circuit you posted from the paper uses controlled gates here. So I would assume you could replace the `u1` gates with `cu1` gates. If this is the case, then you would not need the barriers either. – Matthew Stypulkoski Jan 02 '20 at 20:38
  • Thank you so much. I have edited my question. This is the gate looks like now. Please do me one more favour. Can you help me find out how to change the last qubit "q2" into "memory |b>"? – Protik Nag Jan 05 '20 at 19:55
  • And if you think my question can add values to this site and shows enough characteristics to be a good one for others, then please upvote. :) – Protik Nag Jan 05 '20 at 19:58
  • 1
    If you give your QuantumRegister a name when instantiating it, then when you print the circuit the qubits in the register will appear as " |0>". You do this when you call qr = QuantumRegister(n, 'q'), with 'q' being the name you set. If you only want 1 qubit to do this, you need to make a separate QuantumRegister of size 1 with this name, and then add that register to the circuit. – Matthew Stypulkoski Jan 08 '20 at 20:06

1 Answers1

0

I tried to implement the required circuits like this, maybe this is what you want.

import numpy as np # Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer
from qiskit.tools.jupyter import *
from qiskit.visualization import *

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi


an = QuantumRegister(1, 'ancilla')
qreg_q = QuantumRegister(2, 'register')
qreg_mem=QuantumRegister(1, 'memory')
circuit = QuantumCircuit(an, qreg_q,qreg_mem)

circuit.h(qreg_mem[0])
circuit.cx(qreg_mem[0], qreg_q[1])
circuit.cx(qreg_q[1], qreg_q[0])
circuit.x(qreg_q[1])
circuit.swap(qreg_q[0], qreg_q[1])
circuit.cu(pi, pi, pi, pi/2, qreg_q[1], an[0])
circuit.cu(pi/3, pi/3, pi/3, pi/2, qreg_q[0], an[0])
circuit.swap(qreg_q[0], qreg_q[1])
circuit.x(qreg_q[1])
circuit.cx(qreg_q[1], qreg_q[0])
circuit.cx(qreg_mem[0], qreg_q[1])
circuit.h(qreg_mem[0])
circuit.draw(output='latex')

Output Circuit