1
$\begingroup$

I had generate Bell State, $\frac{1}{\sqrt{2}}(|01\rangle - |10\rangle)$ now when I measured that in $Z$ basis how can I get the state of individual qubit separately and not the probability of the combined state of the system.

from qiskit.quantum_info import DensityMatrix, partial_trace
qc1 = QuantumCircuit(2,2)
qc1.x(0)
qc1.x(1)
qc1.h(0)
qc1.cx(0,1)

qc1.measure(0,0, basis='X')
job1 = execute(qc1, backend, shots= 1024 ,**options_without_noise)
result1 = job1.result()
prob = result1.get_counts()
print(prob)

The above code had been written in qiskit using dm simualator developed by IISC whose git repo is https://github.com/indian-institute-of-science-qc/qiskit-aakash.git The counts method is not working saying no counts and when trying to display to density matrix using the code below

prob = result1.results[0].data.densitymatrix

it result into the combined density matrix using the code after measurement

$\endgroup$

1 Answer 1

1
$\begingroup$

Here is an example with the 0th qubit only; one can similarly get counts for 1st qubit only.

from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram

qc1 = QuantumCircuit(2,1)
qc1.x(0)
qc1.x(1)
qc1.h(0)
qc1.cx(0,1)
qc1.measure([0],[0])

sim = Aer.get_backend('aer_simulator')
counts = execute(qc1, sim).result().get_counts()
plot_histogram(counts, figsize=(9,5))

histogram of the measurement results for qubit 0

$\endgroup$
2
  • $\begingroup$ This is using aer simulator i asked dm simulator of qsim...through aer its straight forward use shots = 1 u would get exactly 0 or 1 once $\endgroup$ Jul 30, 2023 at 6:59
  • $\begingroup$ Apologies, I have missed that. If I understand correctly, you can dig out the probabilities for the state of the full system of 2 qubits in your example, i.e., p(final state=|00>), p(final state=|01>), etc. Let us say that you are interested in computing the probability of the rightmost qubit being in the state |0>. To do this you simply need to add p(final state=|00>) + p(final state=|10>). I hope this helps. $\endgroup$
    – rafexiap
    Jul 30, 2023 at 10:24

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.