TransWikia.com

Qiskit job not giving the right result after execution

Quantum Computing Asked on May 23, 2021

Here is my code

import numpy as np
import qiskit
from qiskit import *


number_of_qubits = 3
backend_sim = Aer.get_backend('qasm_simulator')

#Generate a circuit in qiskit
input_circuit = QuantumCircuit(number_of_qubits, number_of_qubits)
input_circuit.x(0)
input_circuit.h(1)
input_circuit.cx(0,1)
input_circuit.i(1) 
input_circuit.x(1)

job_sim = execute(input_circuit, backend_sim, shots=1024)
result_sim = job_sim.result()
counts = result_sim.get_counts(input_circuit)
print(counts)

No matter what gates I try (e.g. I can remove the last X gate), the result is always '000': 1024. What am I doing wrong?

One Answer

Your current circuit looks like this:

example circuit without measurements

In order to get the "counts", you need to measure at the end of the circuit, before execute.

input_circuit.measure(range(number_of_qubits), range(number_of_qubits))

Example circuit with measurements

Correct answer by luciano on May 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP