|
1 | | -from typing import Dict, Tuple |
| 1 | +from __future__ import annotations |
2 | 2 |
|
| 3 | +from dataclasses import dataclass |
| 4 | +from typing import Dict, Tuple, Union |
3 | 5 |
|
4 | | -class GlobalNodeInfo: |
5 | | - pass |
| 6 | +from squidasm.qoala.runtime.config import ( |
| 7 | + GenericQDeviceConfig, |
| 8 | + LinkConfig, |
| 9 | + NVQDeviceConfig, |
| 10 | +) |
6 | 11 |
|
7 | 12 |
|
| 13 | +@dataclass |
| 14 | +class GlobalNodeInfo: |
| 15 | + """Node information available at runtime.""" |
| 16 | + |
| 17 | + name: str |
| 18 | + |
| 19 | + # total number of qubits |
| 20 | + num_qubits: int |
| 21 | + # number of communication qubits |
| 22 | + num_comm_qubits: int |
| 23 | + |
| 24 | + # coherence times for communication qubits |
| 25 | + comm_T1: int |
| 26 | + comm_T2: int |
| 27 | + |
| 28 | + # coherence times for memory (non-communication) qubits |
| 29 | + mem_T1: int |
| 30 | + mem_T2: int |
| 31 | + |
| 32 | + @classmethod |
| 33 | + def from_config( |
| 34 | + cls, name: str, config: Union[GenericQDeviceConfig, NVQDeviceConfig] |
| 35 | + ) -> GlobalNodeInfo: |
| 36 | + if isinstance(config, GenericQDeviceConfig): |
| 37 | + return GlobalNodeInfo( |
| 38 | + name=name, |
| 39 | + num_qubits=config.num_qubits, |
| 40 | + num_comm_qubits=config.num_comm_qubits, |
| 41 | + comm_T1=config.T1, |
| 42 | + comm_T2=config.T2, |
| 43 | + mem_T1=config.T1, |
| 44 | + mem_T2=config.T2, |
| 45 | + ) |
| 46 | + else: |
| 47 | + assert isinstance(config, NVQDeviceConfig) |
| 48 | + return GlobalNodeInfo( |
| 49 | + name=name, |
| 50 | + num_qubits=config.num_qubits, |
| 51 | + num_comm_qubits=1, |
| 52 | + comm_T1=config.electron_T1, |
| 53 | + comm_T2=config.electron_T2, |
| 54 | + mem_T1=config.carbon_T1, |
| 55 | + mem_T2=config.carbon_T2, |
| 56 | + ) |
| 57 | + |
| 58 | + |
| 59 | +@dataclass |
8 | 60 | class GlobalLinkInfo: |
9 | | - pass |
| 61 | + node_name1: str |
| 62 | + node_name2: str |
| 63 | + |
| 64 | + fidelity: float |
| 65 | + |
| 66 | + @classmethod |
| 67 | + def from_config( |
| 68 | + cls, node_name1: str, node_name2: str, config: LinkConfig |
| 69 | + ) -> GlobalLinkInfo: |
| 70 | + if config.typ == "perfect": |
| 71 | + return GlobalLinkInfo( |
| 72 | + node_name1=node_name1, node_name2=node_name2, fidelity=1.0 |
| 73 | + ) |
| 74 | + elif config.typ == "depolarise": |
| 75 | + return GlobalLinkInfo( |
| 76 | + node_name1=node_name1, |
| 77 | + node_name2=node_name2, |
| 78 | + fidelity=config.cfg.fidelity, # type: ignore |
| 79 | + ) |
| 80 | + else: |
| 81 | + raise NotImplementedError |
10 | 82 |
|
11 | 83 |
|
12 | 84 | class GlobalEnvironment: |
13 | | - # node ID -> node info |
14 | | - _nodes: Dict[int, GlobalNodeInfo] = {} |
| 85 | + def __init__(self) -> None: |
| 86 | + # node ID -> node info |
| 87 | + self._nodes: Dict[int, GlobalNodeInfo] = {} |
15 | 88 |
|
16 | | - # (node A ID, node B ID) -> link info |
17 | | - # for a pair (a, b) there exists no separate (b, a) info (it is the same) |
18 | | - _links: Dict[Tuple[int, int], GlobalLinkInfo] = {} |
| 89 | + # (node A ID, node B ID) -> link info |
| 90 | + # for a pair (a, b) there exists no separate (b, a) info (it is the same) |
| 91 | + self._links: Dict[Tuple[int, int], GlobalLinkInfo] = {} |
19 | 92 |
|
| 93 | + def get_nodes(self) -> Dict[int, GlobalNodeInfo]: |
| 94 | + return self._nodes |
20 | 95 |
|
21 | | -class LocalNodeInfo: |
22 | | - pass |
| 96 | + def set_nodes(self, nodes: Dict[int, GlobalNodeInfo]) -> None: |
| 97 | + self._nodes = nodes |
23 | 98 |
|
| 99 | + def add_node(self, id: int, node: GlobalNodeInfo) -> None: |
| 100 | + self._nodes[id] = node |
24 | 101 |
|
25 | | -class LocalLinkInfo: |
26 | | - pass |
| 102 | + def get_links(self) -> Dict[int, GlobalLinkInfo]: |
| 103 | + return self._links |
| 104 | + |
| 105 | + def set_links(self, links: Dict[int, GlobalLinkInfo]) -> None: |
| 106 | + self._links = links |
| 107 | + |
| 108 | + def add_link(self, id: int, link: GlobalLinkInfo) -> None: |
| 109 | + self._links[id] = link |
27 | 110 |
|
28 | 111 |
|
29 | 112 | class LocalEnvironment: |
30 | | - _global_env: GlobalEnvironment |
| 113 | + def __init__(self, global_env: GlobalEnvironment, node_id: int) -> None: |
| 114 | + self._global_env: GlobalEnvironment = global_env |
| 115 | + |
| 116 | + # node ID of self |
| 117 | + self._node_id: int = node_id |
31 | 118 |
|
32 | | - # node ID of self |
33 | | - _node_id: int |
| 119 | + def get_global_env(self) -> GlobalEnvironment: |
| 120 | + return self._global_env |
| 121 | + |
| 122 | + def get_node_id(self) -> int: |
| 123 | + return self._node_id |
34 | 124 |
|
35 | 125 |
|
36 | 126 | class ProgramEnvironment: |
| 127 | + """Environment interface given to a program""" |
| 128 | + |
37 | 129 | pass |
0 commit comments