-
Notifications
You must be signed in to change notification settings - Fork 365
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 AerBackend issues caused by upgrading BackendV2 #1995
Changes from 21 commits
4587384
45cde5b
b94fd93
c20f91b
55b635b
acda947
e8f43bf
06f2fe1
dbb87b4
5ea99e3
8d14345
a463e1d
e08fc84
2162ea8
6c0dc2e
0d62961
d68601b
a2c336e
e8cf4e7
5151558
4b4d466
c88bdff
3b0543a
28e2f06
8afde0b
c3f0cc4
9618e31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
from qiskit.pulse import Schedule, ScheduleBlock | ||
from qiskit.qobj import QasmQobj, PulseQobj | ||
from qiskit.result import Result | ||
from qiskit.transpiler import CouplingMap | ||
from ..aererror import AerError | ||
from ..jobs import AerJob, AerJobSet, split_qobj | ||
from ..noise.noise_model import NoiseModel, QuantumErrorLocation | ||
|
@@ -48,7 +49,7 @@ class AerBackend(Backend, ABC): | |
"""Aer Backend class.""" | ||
|
||
def __init__( | ||
self, configuration, properties=None, defaults=None, backend_options=None, provider=None | ||
self, configuration, properties=None, provider=None, target=None, backend_options=None | ||
): | ||
"""Aer class for backends. | ||
|
||
|
@@ -59,8 +60,8 @@ def __init__( | |
Args: | ||
configuration (BackendConfiguration): backend configuration. | ||
properties (BackendProperties or None): Optional, backend properties. | ||
defaults (PulseDefaults or None): Optional, backend pulse defaults. | ||
provider (Provider): Optional, provider responsible for this backend. | ||
target (Target): initial target for backend | ||
backend_options (dict or None): Optional set custom backend options. | ||
|
||
Raises: | ||
|
@@ -76,22 +77,24 @@ def __init__( | |
backend_version=configuration.backend_version, | ||
) | ||
|
||
# Initialize backend properties and pulse defaults. | ||
# Initialize backend properties | ||
self._properties = properties | ||
self._defaults = defaults | ||
self._configuration = configuration | ||
|
||
# Custom option values for config, properties, and defaults | ||
# Custom option values for config, properties | ||
self._options_configuration = {} | ||
self._options_defaults = {} | ||
self._options_properties = {} | ||
self._target = None | ||
self._target = target | ||
self._mapping = NAME_MAPPING | ||
|
||
# Set options from backend_options dictionary | ||
if backend_options is not None: | ||
self.set_options(**backend_options) | ||
|
||
# build coupling map | ||
if self.configuration().coupling_map is not None: | ||
self._coupling_map = CouplingMap(self.configuration().coupling_map) | ||
|
||
def _convert_circuit_binds(self, circuit, binds, idx_map): | ||
parameterizations = [] | ||
|
||
|
@@ -330,18 +333,6 @@ def properties(self): | |
setattr(properties, key, val) | ||
return properties | ||
|
||
def defaults(self): | ||
"""Return the simulator backend pulse defaults. | ||
|
||
Returns: | ||
PulseDefaults: The backend pulse defaults or ``None`` if the | ||
backend does not support pulse. | ||
""" | ||
defaults = copy.copy(self._defaults) | ||
for key, val in self._options_defaults.items(): | ||
setattr(defaults, key, val) | ||
return defaults | ||
|
||
@property | ||
def max_circuits(self): | ||
if hasattr(self.configuration(), "max_experiments"): | ||
|
@@ -351,17 +342,16 @@ def max_circuits(self): | |
|
||
@property | ||
def target(self): | ||
self._target = convert_to_target( | ||
self.configuration(), self.properties(), self.defaults(), self._mapping | ||
) | ||
return self._target | ||
if self._target is not None: | ||
return self._target | ||
|
||
return convert_to_target(self.configuration(), self.properties(), None, NAME_MAPPING) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just a minor comment. Previously, converted There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because if target is cached and used for transpilation to multiple circuits, basis gates for the first circuit is reused that can be a problem if the second circuit has gate that the first one does not have |
||
|
||
def clear_options(self): | ||
"""Reset the simulator options to default values.""" | ||
self._options = self._default_options() | ||
self._options_configuration = {} | ||
self._options_properties = {} | ||
self._options_defaults = {} | ||
|
||
def status(self): | ||
"""Return backend status. | ||
|
@@ -702,8 +692,6 @@ def set_option(self, key, value): | |
self._set_configuration_option(key, value) | ||
elif hasattr(self._properties, key): | ||
self._set_properties_option(key, value) | ||
elif hasattr(self._defaults, key): | ||
self._set_defaults_option(key, value) | ||
else: | ||
if not hasattr(self._options, key): | ||
raise AerError(f"Invalid option {key}") | ||
|
@@ -735,15 +723,15 @@ def _set_properties_option(self, key, value): | |
elif key in self._options_properties: | ||
self._options_properties.pop(key) | ||
|
||
def _set_defaults_option(self, key, value): | ||
"""Special handling for setting backend defaults options.""" | ||
if value is not None: | ||
self._options_defaults[key] = value | ||
elif key in self._options_defaults: | ||
self._options_defaults.pop(key) | ||
|
||
def __repr__(self): | ||
"""String representation of an AerBackend.""" | ||
name = self.__class__.__name__ | ||
display = f"'{self.name}'" | ||
return f"{name}({display})" | ||
|
||
def get_translation_stage_plugin(self): | ||
"""use custom translation method to avoid gate exchange""" | ||
if self._target is None: | ||
return "aer_backend_plugin" | ||
else: | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barrier typically isn't needed in a target because qiskit always assumes barrier is valid for a backend since it's primarily a compiler directive. Was there something specific that was failing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed barrier and add barrier inside plugin.
Adding barrier is needed because barrier can not be found in any name mapping and plugin returns with unsupported operation