I'll start with the problem I have relative to the multiplexer, I built a simple 2*1 Mux using just CX, but from what I understood Qiskit has the gate UCGate that can be used as multiplexer so I am trying to implement a multiplexer with n controls, 2^n inputs and one output so that once an input is chosen with control qubits its state 0 or 1 is passed to the output, the code I have is this
def multiplexer(n_controls):
num_inputs = 2 ** n_controls
total_qubits = n_controls + num_inputs + 1
qc = QuantumCircuit(total_qubits)
identity = np.eye(2)
unitary_list = [identity] * num_inputs
uc_gate = UCGate(unitary_list)
qc.x(3)
#This is the part that gives most problems i cant figure out how to set it up
qc.append(uc_gate.control(n_controls), list(range(n_controls)) + [total_qubits - 1])
qc.measure_all()
return qc
qc = multiplexer(3)
qc.draw('mpl')
But I can't get to assign it the right controls, inputs and outputs, can you help?
For the Quantum full Adder I have a simple one working and my question is just how I can build a n-bit one, for the 2 bit I have this simple code:
from qiskit import QuantumCircuit
qc = QuantumCircuit(4)
qc.ccx(0,1,3)
qc.cx(0,1)
qc.ccx(1,2,3)
qc.cx(1,2)
qc.cx(0,1)
qc.measure_all()
qc.draw("mpl")
Thanks for the help
