# A Simon's algorithm with secret string b = 01, IBM Quantum experience gives a different result from what I calculate

I try to design the circuit for $$b = 11$$ and succeeded in running. Therefore, I start to think of the circuit for different secret string $$b = 01$$. The circuit I made is down below:

Here is the problem: After the first Hadamard operator, if the input $$x = \left|10\right\rangle$$, the $$f(x)$$ result (That is the measurement of $$q2$$, $$q3$$, which is the last two bits of $$\left|y_1y_2y_3y_4\right\rangle$$ in Computational basis states) according to my circuit, should be $$\left|11\right\rangle$$, the same as the input $$x = \left|11\right\rangle$$. And the output of $$y1, y2$$ should match the condition:$$b\cdot{y} = 0\,(\,mod\,2\,)$$Hence, one of the output I believe is $$\left|1011\right\rangle$$, but the calculator gives me a wired (at least I think it is wired) result. What are the issues?

Measurements are only allowed at the end of the quantum circuit for current machines like those of IBM. Also for Simon's algorithm we don't care about the output of the second register. Thus only first register is measured.

So you have the possibility of observing the state $$|00\rangle$$ or $$|01\rangle$$. But we know that $$|00\rangle$$ is trivial so without much checking $$|01\rangle$$ is what you are looking for...

Here is the code to generate the above circuit and histogram plot in Qiskit:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from numpy import pi
from qiskit import QuantumCircuit, BasicAer, execute
from qiskit.visualization import plot_histogram
%matplotlib inline

qreg_q = QuantumRegister(4, 'q')
creg_c = ClassicalRegister(2, 'c')
circuit = QuantumCircuit(qreg_q, creg_c)

circuit.h(qreg_q[0])
circuit.h(qreg_q[1])
circuit.cx(qreg_q[0], qreg_q[2])
circuit.cx(qreg_q[0], qreg_q[3])
circuit.barrier(range(4))
circuit.h(qreg_q[0])
circuit.h(qreg_q[1])
circuit.barrier(range(4))
circuit.measure(qreg_q[0], creg_c[0])
circuit.measure(qreg_q[1], creg_c[1])
circuit.draw( 'mpl',style={'name': 'bw'}, scale = 1.5, plot_barriers = False)

backend = BasicAer.get_backend('qasm_simulator')
job = execute(circuit, backend, shots = 20000)
plot_histogram(job.result().get_counts(), color='black', title="Result")


A quick note: If I use the statevector_simulator option then I will either get $$|00\rangle$$ or $$|11\rangle$$ as it just a one-shot simulator.

• The measurement in the first register should be 10 or 00, since b = 01 right? Oct 18, 2020 at 9:55
• @KianGao I didn't see your comment until now... so sorry for the late reply. I have edited my answer. Nov 13, 2020 at 16:49
• Perfect thank you! I'd like to comment on another thing is that on Qiskit, the default b=01 circuit is pretty weird(with 3 CNOT). I need to do more learning and gain more intuition on those circuits. THANK YOU! Nov 16, 2020 at 18:55