-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnode.py
More file actions
76 lines (55 loc) · 2.26 KB
/
Copy pathnode.py
File metadata and controls
76 lines (55 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import annotations
from collections.abc import Callable, Mapping
from typing import Any, TypeVar
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from ..types import UNSET
from ..util.serialization import is_not_none
T = TypeVar("T", bound="Node")
@_attrs_define
class Node:
"""A logical node in the quantum processor's architecture.
The existence of a node in the ISA `Architecture` does not necessarily mean that a given 1Q
operation will be available on the node. This information is conveyed by the presence of the
specific `node_id` in instances of `Instruction`.
Attributes:
node_id (int): An integer id assigned to the computational node. The ids may not be contiguous and will be
assigned based
on the architecture family.
"""
node_id: int
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self, pick_by_predicate: Callable[[str, Any], bool] | None = is_not_none) -> dict[str, Any]:
node_id = self.node_id
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update(
{
"node_id": node_id,
}
)
if pick_by_predicate is not None:
field_dict = {k: v for k, v in field_dict.items() if pick_by_predicate(v)}
else:
field_dict = {k: v for k, v in field_dict.items() if v != UNSET}
return field_dict
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
d = dict(src_dict)
node_id = d.pop("node_id")
node = cls(
node_id=node_id,
)
node.additional_properties = d
return node
@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties