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)
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)
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.