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)?
Asked
Active
Viewed 400 times
1 Answers
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,301
- 1
- 10
- 21
-
Yes, this method is far from optimal. For example, to build a toffoli gate (CCNOT) with the double get_controlled_circuit method described above results in a circuit depth of 41! – thespaceman Oct 09 '20 at 19:04
-
Follow up question, is there an equation for a multi-controlled, multi-target arbitrary U gate? – thespaceman Oct 09 '20 at 19:06
-
1@thespaceman, what you mean by saying "equation"? Do you mean an "algorithm"? If yes then
get_controlled_circuitimplements an algorithm that is described in the comments of the question. Also, Figure 4.6. and Figure 4.8 in this textbook might be interesting. – Davit Khachatryan Oct 12 '20 at 09:20 -
I am looking for a general equation which represents a multi-control U-gate for unitary U. For example, for a single-control gate I could use the equation $CU = I\bigotimes |0><0| + U\bigotimes |1><1|$. I am looking to extend this for a multi-control U-gate. Additionally, thank you for the references from Nielsen. I have already constructed a circuit from Figure 4.10 of Nielsen, but this is sub-optimal since it requires ancillary qubits. I am hoping that a general equation could help me to construct a multi-control gate without ancillary qubits. – thespaceman Oct 13 '20 at 16:54
-
1@thespaceman, this answer about doubly controlled $H$ gate and this answer about $CU$ for not adjacent qubits might be interesting. But I am not sure how this kind of equations can help to construct more optimal circuits. – Davit Khachatryan Oct 13 '20 at 17:08
- it takes your given circuit
- changes your gates to Qiskit's basis gates (u1, u2, u3, cx).
- for each given basis gate it modifies and replaces it with the controlled version of it (it has a "dictionary of methods" that implements the controlled circuits for all basis gates). I have used it for implementing phase estimation algo and it worked))
– Davit Khachatryan Mar 04 '20 at 17:06