I was curious about the various ways of generating code for MCX when there are multiple controls. I saw that qiskit provided multiple algorithms for generating code, depending on the number of ancilla qubits provided.
I tried the following experiment:
circuit = QuantumCircuit(7) circuit.mcx([0, 1, 2, 3, 4], 5, ancilla_qubits=, mode='recursion') circuit.decompose().draw()
I got the circuit shown below with four gates
- The first and second gates perform the operating and put the result into q5.
- The third is the uncomputation to clean up the ancilla qubit.
What is the fourth gate for? I somehow feel like I'm missing some fundamental concept.
Update. I also ran my code through Quirk. To look like a Grover oracle, the input bits were initialized to |+>, the output bit to |->, and the ancilla bit to |0>. I added in excessive "detectors". I could see no difference in state caused by the fourth gate. As expected, only the input |11111> had a negative phase shift.
Update number 2. Quirk program with a time-variant dirty ancilla.