0
$\begingroup$

I have created a circuit and I don't know how to plot a histogram. I tried to plot a histogram but it gives me output for 0000 case only, how to get to know the probability for all of the cases. The below is the plot I got,

This is the plot I got

qc = QuantumCircuit(4, 4)
qc.cx(3, 1)
qc.cx(1, 0)
qc.cx(0, 1)
qc.ccx(3, 2, 1)
qc.cx(1, 2)
qc.cx(3, 2)
qc.measure(0, 0)
qc.measure(1, 1)
qc.measure(2, 2)
qc.measure(3, 3)
job = execute(qc, backend = Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()
count = result.get_counts()
plot_histogram(count) 

How to get the plot histogram not only for 0000 case but also all of the other cases?

$\endgroup$
1
$\begingroup$

What you did is right. However, the reason for the result you observe is because your output state is in the state $|000\rangle$ with 100% certainty. To see this, note that your circuit has the form:

enter image description here

That is, it starts in the state $|0000\rangle$, then all those control operations don't do anything since all the controlled qubits are in the state $|0\rangle$.


However, if you instead consider the following circuit:

qc = QuantumCircuit(4, 4)
for i in range(4):
    qc.h(i)
qc.cx(3, 1)
qc.cx(1, 0)
qc.cx(0, 1)
qc.ccx(3, 2, 1)
qc.cx(1, 2)
qc.cx(3, 2)
qc.measure(0, 0)
qc.measure(1, 1)
qc.measure(2, 2)
qc.measure(3, 3)
     ┌───┐     ┌───┐          ┌─┐                   
q_0: ┤ H ├─────┤ X ├──■───────┤M├───────────────────
     ├───┤┌───┐└─┬─┘┌─┴─┐┌───┐└╥┘          ┌─┐      
q_1: ┤ H ├┤ X ├──■──┤ X ├┤ X ├─╫───■───────┤M├──────
     ├───┤└─┬─┘     └───┘└─┬─┘ ║ ┌─┴─┐┌───┐└╥┘┌─┐   
q_2: ┤ H ├──┼──────────────■───╫─┤ X ├┤ X ├─╫─┤M├───
     ├───┤  │              │   ║ └───┘└─┬─┘ ║ └╥┘┌─┐
q_3: ┤ H ├──■──────────────■───╫────────■───╫──╫─┤M├
     └───┘                     ║            ║  ║ └╥┘
c: 4/══════════════════════════╩════════════╩══╩══╩═
                               0            1  2  3 


job = execute(qc, backend = Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()
count = result.get_counts()
plot_histogram(count)

then your histogram would be

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you for the clarification. Can you please describe the histogram plot? Like 0000 input has the output 0.047 what is it describe? and why the output probability is not constant $\endgroup$
    – Nagaveni
    Jul 16 at 10:20
  • $\begingroup$ The histogram describes the frequency or number of times that you measured that particular state. The total number of time you run a particular circuit to extract the measurement statistics is called shots. For example, suppose you run the circuit with 1000 shots (run the circuit 1000 time) and 47 of those run give you the state $|0000\rangle$ upon measurement, then this tells you that you have roughly the probability of $47/1000 = 0.047 $ of observing the state $|0000\rangle$ when you measure the circuit. $\endgroup$
    – KAJ226
    Jul 16 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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