4

I'm trying to implement an modular adder mentioned here with qiskit. I have already built the $\Phi ADD$ gate. But in order to build a modular adder like in figure 5 in the paper, I need to build a doubly-controlled $\Phi ADD$ gate. Qiskit offers a method to transfer a circuit to a controlled gate, but now I need a doubly controlled gate. I know I can use something like this, but that need an additional qubit, which is undesired. I also know that I can use this method, but I don't know how to implement the square root of $\Phi ADD$ gate. Is there any other method to do this (creating a doubly-controlled gate from the $\Phi ADD$ gate I built without adding any additional qubits)?

Frank Wang
  • 99
  • 4

1 Answers1

2

Here is an example of creating a doubly controlled version of the simplest circuit with one gate (Qiskit's $u1$ gate).

from qiskit import *
from qiskit.aqua.utils.controlled_circuit import get_controlled_circuit
import numpy as np

q_reg = QuantumRegister(3, 'q')
qc_u1 = QuantumCircuit(q_reg)
qc_cu1 = QuantumCircuit(q_reg)
qc_ccu1 = QuantumCircuit(q_reg)

qc_u1.u1(np.pi/2, q_reg[0])

qc_cu1 = get_controlled_circuit(qc_u1, q_reg[1])

qc_ccu1 = get_controlled_circuit(qc_cu1, q_reg[2])

print(qc_cu1.qasm())
print(qc_ccu1.qasm())

And yes, even for this simplest gate, the printed result looks horrible XD (a lot of gates), because it uses generic procedures to create the controlled version of the given circuit. Maybe optimizing the circuit at the end will reduce the gate number and make it a more readable circuit.

Just an answer about the doubly controlled circuit, don't know much about the links and the problem that you have introduced.

Davit Khachatryan
  • 4,481
  • 1
  • 11
  • 23