Skip to content

Commit

Permalink
Merge branch 'main' into restore_arm64_macos
Browse files Browse the repository at this point in the history
  • Loading branch information
doichanj authored Jul 8, 2024
2 parents af684c8 + 9fe6be7 commit 93163ca
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
39 changes: 35 additions & 4 deletions qiskit_aer/aerprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Provider for Aer backends."""


from qiskit.providers import ProviderV1 as Provider
from qiskit.providers import QiskitBackendNotFoundError
from qiskit.providers.providerutils import filter_backends

from .backends.aer_simulator import AerSimulator
Expand All @@ -23,10 +23,11 @@
from .backends.unitary_simulator import UnitarySimulator


class AerProvider(Provider):
class AerProvider:
"""Provider for Aer backends."""

_BACKENDS = None
version = 1

@staticmethod
def _get_backends():
Expand Down Expand Up @@ -64,10 +65,40 @@ def _get_backends():
return AerProvider._BACKENDS

def get_backend(self, name=None, **kwargs):
return super().get_backend(name=name, **kwargs)
"""Return a single Aer backend matching the specified filtering.
Args:
name (str): name of the Aer backend.
**kwargs: dict used for filtering.
Returns:
Backend: an Aer backend matching the filtering.
Raises:
QiskitBackendNotFoundError: if no backend could be found or
more than one backend matches the filtering criteria.
"""
backends = self.backends(name, **kwargs)
if len(backends) > 1:
raise QiskitBackendNotFoundError("More than one backend matches the criteria")
if not backends:
raise QiskitBackendNotFoundError("No backend matches the criteria")

return backends[0]

def backends(self, name=None, filters=None, **kwargs):
# pylint: disable=arguments-differ
"""Return a list of backends matching the specified filtering.
Args:
name (str): name of the backend.
filters (callable): filtering conditions as a callable.
**kwargs: dict used for filtering.
Returns:
list[Backend]: a list of Backends that match the filtering
criteria.
"""
# pylint: disable=unused-argument
# Instantiate a new backend instance so if config options
# are set they will only last as long as that backend object exists
backends = []
Expand Down
4 changes: 3 additions & 1 deletion qiskit_aer/backends/aer_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,9 @@ def from_backend(cls, backend, **options):
open_pulse=False,
memory=False,
max_shots=int(1e6),
coupling_map=list(backend.coupling_map.get_edges()),
coupling_map=(
None if backend.coupling_map is None else list(backend.coupling_map.get_edges())
),
max_experiments=backend.max_circuits,
description=description,
)
Expand Down
5 changes: 4 additions & 1 deletion qiskit_aer/primitives/estimator_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def __init__(
def from_backend(cls, backend, **options):
"""make new sampler that uses external backend"""
estimator = cls(**options)
estimator._backend = AerSimulator.from_backend(backend)
if isinstance(backend, AerSimulator):
estimator._backend = backend
else:
estimator._backend = AerSimulator.from_backend(backend)
return estimator

@property
Expand Down
5 changes: 4 additions & 1 deletion qiskit_aer/primitives/sampler_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def __init__(
def from_backend(cls, backend, **options):
"""make new sampler that uses external backend"""
sampler = cls(**options)
sampler._backend = AerSimulator.from_backend(backend)
if isinstance(backend, AerSimulator):
sampler._backend = backend
else:
sampler._backend = AerSimulator.from_backend(backend)
return sampler

@property
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/fix_from_backend-a885d43caf390873.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
fixes:
- |
`from_backend` function of V2 primitives are fixed to accept AerSimulator
objects as input so that user can define simulator objects outside of
primitives
5 changes: 5 additions & 0 deletions releasenotes/notes/providerABC-61311d8e5ae56d71.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
The class :class:`.AerProvider` does not implement Qiskit's ``Provider``, as it is now deprecated.
This fix removes the raising of the warning from Qiskit.

0 comments on commit 93163ca

Please sign in to comment.