1
$\begingroup$

I am new to quantum computing and was playing with circuits. I came across measurements method in qiskit, and from what I understand is that when measured, each qubit is mapped to different classical bit. I know that might be weird, and I am very new to this topic, but what happens when I map the 2 qubits to the same clasical bit, as in this example:

num_qubits = len(input_data) # input_data is a 2-col array [inputFeature1, inputFeature2]
params = np.random.rand(2) # params is a random array to control gates rotation in the circuit [rand1, rand2]


circuit = QuantumCircuit(num_qubits , num_qubits)

for i, value in enumerate(input_data):
    circuit.rx(value * np.pi, i)

# Apply parameterized Ry rotations
param_index = 0
for i in range(num_qubits):
    circuit.ry(params[param_index], i)
    param_index += 1

# Mapping to classical bits 
circuit.measure([0, 1], [1, 1])

what I used before was just measureing the qubits as in circuit.measure([0, 1], [0, 1]) where my understanding is that means 1st qubit is mapped to classical bit 0 and 2nd qubit is mapped to classical bit 1.

Is measuring it as circuit.measure([0, 1], [1, 1]) going to rewrite the results of the 2nd qubit in classical bit 1 and the results of the 1st qubit are going to be ignored? so I am only getting results for the 2nd qubit?

By running statevector_simulator, I can see a representation of the 2 qubits on Bloch Sphere, and I can also try getting some samples to see the expected outcomes.

The thing is when I run the following code, I can get some results where qubit0 is pointing to |1> on Bloch Sphere, however in the histogram plot the results doesn't show an outcome where qubit0 outcome is |1>. I also noticed that qiskit uses little indian format so results are formatted as "q1q0", unless I got the wrong idea about this?

# Simulate the circuit
backend = Aer.get_backend('statevector_simulator')
job = transpile(circuit, backend)
result = backend.run(job, shots=1000).result()
counts = result.get_counts()
# Extract the final statevector
statevector = result.get_statevector()
# Plot the Bloch sphere
plot_bloch_multivector(statevector)

enter image description here

And here is the histogram plot, as you can see here there is no |1,1> results. But the Bloch Sphere image shows the 2 qubits in |1,1> state.

# Plot the result histogram
plot_histogram(counts)

enter image description here

While writing this question it came to my mind that there is no |1,1> in the results because of how I measured the qubits, and I now assume even when using circuit.measure([0, 1], [1, 1]) the statevector returned from statevector = result.get_statevector() will still return the result for qubit0, however it won't be returned in counts = result.get_counts() since we save both qubits in classical bit 1.

I attempted to test that when we mesure both on classical bit 0 and I got similar results,

Another thing, does the measuerment order matter? if I measure a qubit before another as in the following:

# here I try to check if measuring 2-qubits to the same classical bit will rewrite the results based on the last measured qubit
circuit.measure([0, 1], [1, 1]) # Measuring q0 first
circuit.measure([1, 0], [1, 1]) # Measuring q1 first

This code did not change the results format, where output counts where still '00' and '10', So I also assume that there is no effect on results when measuring qubit before another in the circuit? Unless there is something going on that I did not understand and I have absolotly a wrong idea about quantum so far?

I hope that wasn't messy. Please help me to understand this and if you could refere me to something that explains this it is also apreciated. Thanks in advance and excuse my weird questions as I am really carious about these things.

$\endgroup$

1 Answer 1

2
$\begingroup$

Yes. The command:

circuit.measure([0, 1], [1, 1])

will perform a measurement on qubit $q_0$, causing it to project to either $|0\rangle$ or $|1\rangle$, but the result stored in the classical register will be rewritten by the measurement result of $q_1$.

The reason you see different results between counts and the statevector_simulator simulation is because the counts are the result stored in the classical register, whereas the Statevector is the state of the quantum register.

Here's a simple example. Consider the following circuit: enter image description here

First, $q_0$ is placed in a superposition of $|0\rangle$ and $|1 \rangle$ and measured. This projects the state of $q_0$ to either $|0\rangle$ or $|1\rangle$, and the corresponding value of either 0 or 1 is stored in $c_0$.

Then, $q_1$ is inverted to state $|1\rangle$ and measured. It's value is stored in $c_0$, overwriting the result of $q_0$.

This means you always get a 1 in $c_0$, but the Statevector for the qubits could be either $|10\rangle$ or $|11\rangle$, which is what the statevector simulator will show.

$\endgroup$
1
  • $\begingroup$ Thank you very much for your answer @diemilio. It explained it all for me! I should have noticed that statevector actually relates to quantum states themselves not for the final results in counts. $\endgroup$ Commented Nov 10 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.