# How to convert states |0011⟩, |1100⟩, |0101⟩ to |1111⟩?

How can I use X gate (quantum not) to convert each of the pure states |0011⟩, |1100⟩, |0101⟩ to |1111⟩ with Qiskit?

My programming assignment is

Using the idea of a multi-controlled phase gate, now use X-gates (quantum not) to convert each of the pure states ||0011⟩,||1100⟩,||0101⟩ each to ||1111⟩ and use MCP gate above to mark the phase. Remember to use X-gates to convert the inputs back.

I have found the way to invert to -||1111⟩ part but still not able to find away to convert ||0011⟩,||1100⟩,||0101⟩ to ||1111>

Here are the code.

from qiskit import QuantumRegister, QuantumCircuit, AncillaRegister
from numpy import pi
def mark_pure_states(qc, b0 , b1, b2, b3):
# mark the components corresponding to the pure states |0011> , |1100>, |0101>
# your code here
bits = [b0,b1,b2,b3]

# TODO: convert |0011> , |1100>, |1010> to |1111>
qc.x(b0)
qc.x(b1)
qc.mcx([b0,b1,b2],b3)
qc.barrier()
qc.x(b1)
qc.x(b3)
qc.mcx([b0,b1,b2],b3)
qc.barrier()
qc.x(b2)
qc.x(b3)
qc.mcx([b0,b1,b2],b3)
qc.barrier()
qc.mcx([b0,b1,b2],b3)

# Use Multi-controlled phase gate to convert |1111> to -|1111>
qc.mcp(pi,[b0,b1,b2], b3)

# Use X gate from -|1111> back to |1111>
for b in bits:
qc.x(b)

b = QuantumRegister(4, 'b')
qc = QuantumCircuit(b)
# create uniform super position
qc.h(b[0])
qc.h(b[1])
qc.h(b[2])
qc.h(b[3])
qc.barrier()
mark_pure_states(qc, b[0], b[1], b[2], b[3])
display(qc.draw('mpl', style='iqp'))
# use a state vector simulator to obain the marked states
backend = Aer.get_backend('statevector_simulator')
job = execute(qc, backend)
result = job.result()
state_vector = result.get_statevector()
print(state_vector)
for i in range(16):
if i == 3 or i == 10 or i == 12: # are we marking the correct basis states
assert abs(state_vector[i] +0.25) <= 0.001
else:
assert abs(state_vector[i]-0.25) <= 0.001


My output right now is:

Statevector([-0.25+3.061617e-17j,  0.25+0.000000e+00j,  0.25+0.000000e+00j,
0.25+0.000000e+00j,  0.25+0.000000e+00j,  0.25+0.000000e+00j,
0.25+0.000000e+00j,  0.25+0.000000e+00j,  0.25+0.000000e+00j,
0.25+0.000000e+00j,  0.25+0.000000e+00j,  0.25+0.000000e+00j,
0.25+0.000000e+00j,  0.25+0.000000e+00j,  0.25+0.000000e+00j,
0.25+0.000000e+00j],
dims=(2, 2, 2, 2))
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[241], line 22
20     assert abs(state_vector[i] +0.25) <= 0.001
21 else:
---> 22     assert abs(state_vector[i]-0.25) <= 0.001

AssertionError:


My result should have 3rd, 10th, 12th value of state vector arrays being minus 0.25

• Just apply X gate on qubits in state 0. Commented May 24 at 9:51
• Please explain what you have tried and why you expect your solution to work. As is, this question looks like you are looking for people to complete your assignement for you.
– AG47
Commented May 24 at 12:36
• You're on the right track, but have plenty of mistakes. I would recommend you start by trying to mark just one of the three elements on your assignment and see what is going wrong. A few pointers: 1) Why are you using mcx gates? you know elements get marked with the mcp gate. 2) The assignment says "Remember to use X-gates to convert the inputs back". You are applying the X-gates to all qubits, why? 3) What are the last mcx and mcp gates at the end of the circuit supposed to do? Commented May 26 at 10:59

## 1 Answer

Unitary quantum circuits are reversible. For a computational operation to be logically reversible, its output can be computed from the input, and vice versa.

In your case if the output is $$|1111\rangle$$, how to figure out what is the input? So, we can't have a unitary quantum circuit that maps the three states $$|0011⟩, |1100\rangle$$, and $$|0101\rangle$$ to $$|1111\rangle$$ without adding ancilla qubits.

A simple solution for your problem is to construct for each one of these states a circuit that marks that state and does nothing for the other states. Now, if you combine these circuits together you should get what you want.

Note that, Qiskit has some features that make building such circuits a lot easier (for example, PhaseOracle). However, it is a good learning experience for a beginner to build it using elementary gates.