qiskit-community / qiskit-ionq

Qiskit provider for IonQ backends
https://qiskit-community.github.io/qiskit-ionq/
Apache License 2.0
42 stars 24 forks source link

Simulator results where the output probability is exactly 1 cause numpy casting issues #66

Closed ColemanCollins closed 3 years ago

ColemanCollins commented 3 years ago

Information

What is the current behavior?

Steps to reproduce the problem

minimal repro program:

from qiskit import QuantumCircuit
from qiskit_ionq import IonQProvider
provider = IonQProvider("token")
sim = provider.get_backend("ionq_simulator")
qc = QuantumCircuit(2,2)
qx.x(0)
qc.measure(0,0)
job = sim.run(qc, shots=10000)
counts = job.result().get_counts()
print(counts)

produces

    103         # just in case the sum isn't exactly 1 — sometimes the API returns
    104         #   e.g. 0.499999 due to floating point error
--> 105         weights /= weights.sum()
    106         rand_values = rand.choice(outcomes, shots, p=weights)
    107 
TypeError: No loop matching the specified signature and casting was found for ufunc true_divide

which I believe is numpy freaking out about dividing ints (specifically 1).

What is the expected behavior?

no errors!

Suggested solutions

casting the output array to floats before normalizing should fix this.

ColemanCollins commented 3 years ago

addressed in #67