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

Fix init of EstimatorV2 and SamplerV2 #2120

Merged
merged 9 commits into from
May 28, 2024
9 changes: 7 additions & 2 deletions qiskit_aer/primitives/estimator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ def __init__(
the runtime options (``run_options``).
"""
self._options = Options(**options) if options else Options()
method = "density_matrix" if "noise_model" in self.options.backend_options else "automatic"
self._backend = AerSimulator(method=method, **self.options.backend_options)
if "method" not in self.options.backend_options:
method = (
"density_matrix" if "noise_model" in self.options.backend_options else "automatic"
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this line necessary? Shouldn't we just let AerSimulator set the method if it's not specified? It should default to automatic, which should be smart enough to choose density_matrix if noise_model is specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this so now method=automatic is set by default and #2117 is fixed

ops = dict(method=method)
self.options.backend_options.update(ops)
self._backend = AerSimulator(**self.options.backend_options)

def from_backend(self, backend, **options):
"""use external backend"""
Expand Down
6 changes: 6 additions & 0 deletions qiskit_aer/primitives/sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def __init__(
self._seed = seed

self._options = Options(**options) if options else Options()
if "method" not in self.options.backend_options:
method = (
"density_matrix" if "noise_model" in self.options.backend_options else "automatic"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean that noise simulation always use "density_matrix" in sampler?

)
ops = dict(method=method)
self.options.backend_options.update(ops)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.options.backend_options.update({method: method})

may be simpler.

self._backend = AerSimulator(**self.options.backend_options)

def from_backend(self, backend, **options):
Expand Down
5 changes: 5 additions & 0 deletions releasenotes/notes/fix_primitiveV2_init-afe7b331ddbef538.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
Fixed init function of EstimatorV2 and SamplerV2 to set `method` in
its option property if there is no `method` in input parameter
Loading