Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error early when shots is set to a float in the primitives #1844

Closed
garrison opened this issue Jun 12, 2023 · 2 comments
Closed

Error early when shots is set to a float in the primitives #1844

garrison opened this issue Jun 12, 2023 · 2 comments
Assignees
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@garrison
Copy link
Member

garrison commented Jun 12, 2023

Informations

  • Qiskit Aer version: 0.12.0
  • Python version: 3.9
  • Operating system: Linux

What is the current behavior?

Setting the shots of a Sampler to a float results in it failing, but not until the job is executed.

Traceback (most recent call last):
  File "/home/garrison/serverless/aer-fail.py", line 10, in <module>
    job.result()
  File "/home/garrison/serverless/.direnv/python-3.9.7/lib/python3.9/site-packages/qiskit/primitives/primitive_job.py", line 55, in result
    return self._future.result()
  File "/home/garrison/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 445, in result
    return self.__get_result()
  File "/home/garrison/miniconda3/lib/python3.9/concurrent/futures/_base.py", line 390, in __get_result
    raise self._exception
  File "/home/garrison/miniconda3/lib/python3.9/concurrent/futures/thread.py", line 52, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/garrison/serverless/.direnv/python-3.9.7/lib/python3.9/site-packages/qiskit_aer/primitives/sampler.py", line 106, in _call
    result = self._backend.run(
  File "/home/garrison/serverless/.direnv/python-3.9.7/lib/python3.9/site-packages/qiskit_aer/backends/aerbackend.py", line 218, in run
    return self._run_circuits(circuits, parameter_binds, **run_options)
  File "/home/garrison/serverless/.direnv/python-3.9.7/lib/python3.9/site-packages/qiskit_aer/backends/aerbackend.py", line 237, in _run_circuits
    config = generate_aer_config(circuits, self.options, **run_options)
  File "/home/garrison/serverless/.direnv/python-3.9.7/lib/python3.9/site-packages/qiskit_aer/backends/aer_compiler.py", line 363, in generate_aer_config
    setattr(config, key, value)
TypeError: (): incompatible function arguments. The following argument types are supported:
    1. (self: qiskit_aer.backends.controller_wrappers.AerConfig, arg0: int) -> None

Invoked with: <qiskit_aer.backends.controller_wrappers.AerConfig object at 0x7f921dac88b0>, 1.5

Steps to reproduce the problem

from qiskit import QuantumCircuit
from qiskit_aer.primitives import Sampler

qc = QuantumCircuit(1, 1)
qc.x(0)
qc.measure(0, 0)

sampler = Sampler(run_options={"shots": 1.5})
job = sampler.run(qc)
job.result()

What is the expected behavior?

The code above fails on the final line, but it could fail sooner, when the Sampler is created with shots set to a float.

This is creating a usability issue for us in the circuit-knitting-toolbox, where users often do some math to determine a suitable shots count. If they forget to round the value and convert it to an int, they currently get the above error when they go to execute the circuit using the toolbox. We've found that because the error comes then from deep inside the circuit-knitting-toolbox, the user is typically unaware that their own error caused it.

Suggested solutions

Check the type of shots when the sampler is constructed. Don't wait until result() is called on the job. Provide a clear error message when it is a float.

@garrison garrison added the bug Something isn't working label Jun 12, 2023
@hhorii hhorii self-assigned this Jun 13, 2023
@hhorii
Copy link
Collaborator

hhorii commented Jun 13, 2023

I believe 0.12.1 resolved this issue. This is same with #1754.

@hhorii hhorii added the duplicate This issue or pull request already exists label Jun 13, 2023
@hhorii
Copy link
Collaborator

hhorii commented Jun 13, 2023

I confirmed this code works with 0.12.1.

from qiskit import QuantumCircuit
from qiskit_aer.primitives import Sampler

qc = QuantumCircuit(1, 1)
qc.x(0)
qc.measure(0, 0)

sampler = Sampler(run_options={"shots": 1.5})
job = sampler.run(qc)
job.result()

@hhorii hhorii closed this as completed Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants