-
Notifications
You must be signed in to change notification settings - Fork 101
Open
Description
The class AzureBackendConfig in azure.quantum.qiskit.backends.backend has a field metadata containing any remaining properties of the class. The __getattr__ method of this class is implemented in such a way that, if the attribute is not found, the metadata dict is checked. However, this leads to a RecursionError: maximum recursion depth exceeded when an instance of the class is copied using copy.deepcopy (which apparently happens sometimes).
class AzureBackendConfig:
...
def __getattr__(self, name: str) -> Any:
if name == "max_experiments":
return 1
try:
return self.__dict__[name]
except KeyError as exc:
if name in self.metadata:
return self.metadata[name]
raise AttributeError(
f"'{type(self).__name__}' object has no attribute '{name}'"
) from excSimplified reproduction of the error:
import copy
from dataclasses import dataclass, field
from typing import Any
@dataclass
class A:
metadata: dict[str, Any] = field(default_factory=dict)
def __getattr__(self, name: str) -> Any:
try:
return self.__dict__[name]
except KeyError as exc:
if name in self.metadata:
return self.metadata[name]
raise AttributeError(
f"'{type(self).__name__}' object has no attribute '{name}'"
) from exc
a = A()
copy.deepcopy(a) # RecursionError: maximum recursion depth exceededA possible solution would be to change the problematic line to:
if "metadata" in self.__dict__ and name in self.metadata:Metadata
Metadata
Assignees
Labels
No labels