1
$\begingroup$

I am looking for some help to understand what I am doing wrong.

I am new to QC and I am trying to create circuit that would be in below state -

$$\frac{1}{\sqrt{8}}(|000,0\rangle + |001,0\rangle + |010,0\rangle + |011,0\rangle + |100,0\rangle + |101,0\rangle + |110,0\rangle + |111,1\rangle)$$

Below is my code:

from qiskit import QuantumCircuit
from qiskit.circuit.library import C4XGate

qc = QuantumCircuit(3+1) # n number of qubits plus one ancilla qubit. 

qc.h(0)
qc.h(1)
qc.h(2)
qc.mct([0, 1, 2], 3, mode="noancilla")
qc.measure_all()

# qc.draw(output="mpl")

from qiskit import Aer, execute, assemble

backend = Aer.get_backend("aer_simulator")
qc.save_statevector()
job = execute(qc, backend, shots=1000)
counts = job.result().get_counts()

print(counts)

I am getting below output.

{'0001': 141, '0010': 120, '0011': 129, '0000': 121, '0101': 122, '1111': 134, '0110': 129, '0100': 104}

My question is 4th qubit should be 1 when qubit 0, 1 and 2 are 1 (which is true), however, 4th qubit should be 0 otherwise, so why do I have output such as 0001 or 0101?

Thanks for the help in advanced!

$\endgroup$

1 Answer 1

2
$\begingroup$

You circuit is correct. The result is not matched with what you expect because Qiskit uses little endian bit ordering.

If you want to get the result in big endian convention, use reverse_bits() method.

$\endgroup$
1
  • $\begingroup$ Thanks a lot! Applying reverse_bits() gave me what I was looking for. $\endgroup$
    – Nihir
    Aug 6 at 12:40

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.