My qiskit code's output differ from the Lecturer: Ryan O’Donnell
I am testing the table shown in attached image by using qiskit in python3.8.5 and qiskit version {'qiskit-terra': '0.14.2', 'qiskit-aer': '0.5.2', 'qiskit-ignis': '0.3.3', 'qiskit-ibmq-provider': '0.7.2', 'qiskit-aqua': '0.7.3', 'qiskit': '0.19.6'}
my code is :
from qiskit import QuantumCircuit, assemble
from qiskit import Aer, execute
from qiskit.tools.visualization import plot_histogram
bit = 3
bit_lst = list(range(bit))
circuit = QuantumCircuit(bit, bit)
circuit.reset(0)
circuit.reset(1)
circuit.reset(2)
circuit.x(0)
circuit.x(1)
circuit.ccx(0,1,2)
circuit.barrier()
circuit.measure(bit_lst,bit_lst)
circuit.draw(output='mpl')
backend = Aer.get_backend('statevector_simulator')
statevector=backend.run(assemble(circuit)).result().get_statevector()
print(statevector)
backend = Aer.get_backend('qasm_simulator')
counts1=backend.run(assemble(circuit)).result().get_counts()
print(counts1)
with open('result.txt', 'a') as f:
print(f'011 - {statevector} - {counts1}', file=f)
plot_histogram([counts1], legend=['Simulator'])
result.txt file output is: 011 - [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j] - {'111': 1024}
as per the table the out put must be 011 but the output from the code is 111 is it my code or my knowledge of qubit?
to check wether its just a bit flip i change my code:
from qiskit import QuantumCircuit, assemble
from qiskit import Aer, execute
from qiskit.tools.visualization import plot_histogram
bit = 3
bit_lst = list(range(bit))
circuit = QuantumCircuit(bit, bit)
circuit.reset(0)
circuit.reset(1)
circuit.reset(2)
def bit_000():
pass
def bit_001():
circuit.x(0)
def bit_010():
circuit.x(1)
def bit_011():
circuit.x(0)
circuit.x(1)
def bit_100():
circuit.x(2)
def bit_101():
circuit.x(0)
circuit.x(2)
def bit_110():
circuit.x(1)
circuit.x(2)
def bit_111():
circuit.x(0)
circuit.x(1)
circuit.x(2)
func_lst = [bit_000, bit_001, bit_010, bit_011, bit_100, bit_101, bit_110, bit_111]
for fn in func_lst:
fn()
circuit.ccx(0,1,2)
circuit.barrier()
circuit.measure(bit_lst,bit_lst)
circuit.draw(output='mpl')
backend = Aer.get_backend('statevector_simulator')
statevector=backend.run(assemble(circuit)).result().get_statevector()
print(statevector)
backend = Aer.get_backend('qasm_simulator')
counts1=backend.run(assemble(circuit)).result().get_counts()
print(counts1)
with open('result.txt', 'a') as f:
print(f'{fn} - {statevector} - {counts1}', file=f)
plot_histogram([counts1], legend=['Simulator'])
result file new out put is: <function bit_000 at 0x0000028334B761F0> - [1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] - {'000': 1024}
<function bit_001 at 0x000002833524E820> - [0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] - {'001': 1024}
<function bit_010 at 0x0000028349D6CAF0> - [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j] - {'111': 1024}
<function bit_011 at 0x0000028349D6CB80> - [0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j] - {'100': 1024}
<function bit_100 at 0x0000028349D6CC10> - [1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] - {'000': 1024}
<function bit_101 at 0x0000028349D6CCA0> - [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j] - {'101': 1024}
<function bit_110 at 0x0000028349D6CD30> - [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 1.+0.j] - {'111': 1024}
<function bit_111 at 0x0000028349D6CDC0> - [1.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] - {'000': 1024}
didnt care about a cleaner result, Sorry. and not able to add code in reply sorry.