Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.15k stars 2.35k forks source link

qasm_simulator no results from a circuit for histogram #6791

Open jgermain48 opened 3 years ago

jgermain48 commented 3 years ago

Information

What is the current behavior?

Simulation fails to produce results. Simulation worked on my circuit yesterday...but today it fails. I don't think I've made any changes. Will run on real hardware fine.

Errors produced:

/Users/juliegermain/opt/anaconda3/envs/QuantumResearch/bin/python "/Users/juliegermain/Library/Application Support/JetBrains/PyCharmCE2020.3/scratches/QuantumResearch/scratch_5.py" [] Simulation failed and returned the following error message: ERROR: Failed to load qobj: Unable to cast Python instance to C++ type (compile in debug mode for details) Traceback (most recent call last): File "/Users/juliegermain/Library/Application Support/JetBrains/PyCharmCE2020.3/scratches/QuantumResearch/scratch_5.py", line 45, in hist = plot_histogram(result.get_counts()) File "/Users/juliegermain/opt/anaconda3/envs/QuantumResearch/lib/python3.8/site-packages/qiskit/visualization/counts_visualization.py", line 219, in plot_histogram all_vals = np.concatenate(all_pvalues).ravel() File "<__array_function__ internals>", line 5, in concatenate ValueError: need at least one array to concatenate

Process finished with exit code 1

Steps to reproduce the problem

Here is a scaled back version of the circuit that shows the issue:

from qiskit.tools.visualization import plot_histogram from qiskit import * from qiskit.extensions import Initialize import matplotlib.pyplot as plt

def draw_circuit(qc): qc.draw(output='mpl') plt.show()

sim_on = 1

qd0 = QuantumRegister(1,'qd0') qa0 = QuantumRegister(1,'qa0') qa1 = QuantumRegister(1,'qa1') qd1 = QuantumRegister(1,'qd1') qd2 = QuantumRegister(1,'qd2') crr = ClassicalRegister(1) shor_qc = QuantumCircuit(qd0,qd1,qd2,qa0,qa1,crr)

initial_value = 1

end-to-end circuit initialization method

if initial_value == 1: initial_data = '1' elif initial_value == 0: initial_data = '0'

init_gate = Initialize(initial_data) init_gate.label = "init" inverse_init_gate = init_gate.gates_to_uncompute() shor_qc.append(init_gate,qd0)

shor_qc.barrier()

shor_qc.measure(qd0,crr)

draw_circuit(shor_qc)

if sim_on == 1:

simulator = Aer.get_backend('aer_simulator')

simulator = Aer.get_backend('qasm_simulator')
result = execute(shor_qc, backend=simulator).result()
count = result.get_counts()
print(count)
hist = plot_histogram(result.get_counts())
plt.show()

What is the expected behavior?

produce a histogram with results. Note: I can run on real hardware and it works fine. Circuit is created and drawn. I had been running yesterday on qasm_simulator. I tried running on aer_simulator as a test...and issue still present.

Suggested solutions

No idea.

jgermain48 commented 3 years ago

looking at the code further the issue doesn't happen if I comment out this line...reason this method isn't compatible with the simulator (again thought this version of the circuit worked yesterday)

shor_qc.append(init_gate,qd0)