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

error in noisy simulation of a single S-gate #180

Open jagunther opened 4 months ago

jagunther commented 4 months ago

qiskit-environment:

qiskit 1.0.2 qiskit-aer 0.14.2 qiskit-experiments 0.6.1 qiskit-ibm-experiment 0.4.7 qiskit-ionq 0.5.2

python version: python 3.12

OS: Mac OS 14.5

What is the current behavior?

Not able to get counts of simulation of a single S-gate with noise. There is no error without the noise-model or if another Hadamard-gate is added. The problem exists also in qiskit-ionq 0.5.1

Steps to reproduce the problem

from qiskit_ionq import IonQProvider
from qiskit import QuantumCircuit
import os
import qiskit_ionq

api_key = os.getenv('IONQ_API_KEY')

def main():
    print(qiskit_ionq.__version__)

    provider = IonQProvider(token=api_key)
    backend = provider.get_backend("simulator")
    backend.set_options(noise_model="aria-2")

    qc = QuantumCircuit(1, 1)
    qc.s(0)
    # qc.h(0)   # no error when uncommented
    qc.measure([0], [0])

    job = backend.run(qc, shots=1024)
    print(job.get_counts())

if __name__ == '__main__':
    main()

error message:

Traceback (most recent call last):
  File "/Users/vrn738/PycharmProjects/hardware_benchmark/ionq/test.py", line 25, in <module>
    main()
  File "/Users/vrn738/PycharmProjects/hardware_benchmark/ionq/test.py", line 21, in main
    print(job.get_counts())
          ^^^^^^^^^^^^^^^^
  File "/Users/vrn738/PycharmProjects/hardware_benchmark/.venv/lib/python3.12/site-packages/qiskit_ionq/ionq_job.py", line 228, in get_counts
    return self.result().get_counts(circuit)
           ^^^^^^^^^^^^^
  File "/Users/vrn738/PycharmProjects/hardware_benchmark/.venv/lib/python3.12/site-packages/qiskit_ionq/ionq_job.py", line 286, in result
    self._result = self._format_result(response)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/vrn738/PycharmProjects/hardware_benchmark/.venv/lib/python3.12/site-packages/qiskit_ionq/ionq_job.py", line 494, in _format_result
    (counts, probabilities) = _build_counts(
                              ^^^^^^^^^^^^^^
  File "/Users/vrn738/PycharmProjects/hardware_benchmark/.venv/lib/python3.12/site-packages/qiskit_ionq/ionq_job.py", line 109, in _build_counts
    raise exceptions.IonQJobError("Cannot remap counts without data!")
qiskit_ionq.exceptions.IonQJobError: IonQJobError('Cannot remap counts without data!')

What is the expected behavior?

job.get_counts() should return the measurement counts

Suggested solutions

Cynocracy commented 1 month ago

ty for the bug report! I suspect this is a bug in the recent change to logic where we filter down the results to only those qubits measured.

Cynocracy commented 1 month ago

No longer able to reproduce on 0.5.* versions.

A couple of possiblities:

Happy to keep this open if we suspect the first of the two is in play, otherwise, this should be resolve :crossed_fingers: