Skip to content

Commit 7fb0980

Browse files
committed
More reorganizing
1 parent 92a7468 commit 7fb0980

File tree

10 files changed

+215
-219
lines changed

10 files changed

+215
-219
lines changed

squidasm/qoala/arch/qoala-runtime-data.drawio

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<mxfile host="65bd71144e" modified="2022-05-30T17:55:24.076Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.67.2 Chrome/98.0.4758.141 Electron/17.4.1 Safari/537.36" etag="5a1jI3cs00Yb6BDQfzIJ" version="18.1.3" type="embed">
1+
<mxfile host="65bd71144e" modified="2022-06-16T15:40:59.882Z" agent="5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Code/1.67.2 Chrome/98.0.4758.141 Electron/17.4.1 Safari/537.36" etag="ml5gjgR4LqD0JgdyIVhk" version="20.0.1" type="embed">
22
<diagram id="j2bOcpKi6gkglbLQkNI5" name="Page-1">
3-
<mxGraphModel dx="1204" dy="790" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
3+
<mxGraphModel dx="1444" dy="790" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
44
<root>
55
<mxCell id="0"/>
66
<mxCell id="1" parent="0"/>
@@ -19,46 +19,46 @@
1919
<mxCell id="6" value="Setup/Config&lt;br&gt;(real system -&amp;gt; given setup,&lt;br&gt;simulation -&amp;gt; config)&lt;br&gt;&lt;br&gt;- nodes&lt;br&gt;- links&lt;br&gt;- hardware type&lt;br&gt;- noise&lt;br&gt;- latencies" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
2020
<mxGeometry x="650" y="210" width="160" height="190" as="geometry"/>
2121
</mxCell>
22-
<mxCell id="7" value="" style="endArrow=none;dashed=1;html=1;strokeWidth=2;" edge="1" parent="1">
22+
<mxCell id="7" value="" style="endArrow=none;dashed=1;html=1;strokeWidth=2;" parent="1" edge="1">
2323
<mxGeometry width="50" height="50" relative="1" as="geometry">
2424
<mxPoint x="20" y="440" as="sourcePoint"/>
2525
<mxPoint x="850" y="440" as="targetPoint"/>
2626
</mxGeometry>
2727
</mxCell>
28-
<mxCell id="8" value="Offline" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
28+
<mxCell id="8" value="Offline" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
2929
<mxGeometry x="30" y="55" width="60" height="30" as="geometry"/>
3030
</mxCell>
31-
<mxCell id="9" value="Runtime" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
31+
<mxCell id="9" value="Runtime" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
3232
<mxGeometry x="30" y="480" width="60" height="30" as="geometry"/>
3333
</mxCell>
34-
<mxCell id="10" value="Online" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
34+
<mxCell id="10" value="Online" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" parent="1" vertex="1">
3535
<mxGeometry x="30" y="265" width="60" height="30" as="geometry"/>
3636
</mxCell>
37-
<mxCell id="11" value="Binary program" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
37+
<mxCell id="11" value="Binary program" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
3838
<mxGeometry x="160" y="235" width="120" height="60" as="geometry"/>
3939
</mxCell>
40-
<mxCell id="12" value="Process" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
40+
<mxCell id="12" value="Process" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
4141
<mxGeometry x="160" y="490" width="120" height="60" as="geometry"/>
4242
</mxCell>
43-
<mxCell id="13" value="Runtime&lt;br&gt;&lt;br&gt;- (EPR) Sockets&lt;br&gt;- Scheduler" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
43+
<mxCell id="13" value="Runtime&lt;br&gt;&lt;br&gt;- (EPR) Sockets&lt;br&gt;- Scheduler" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
4444
<mxGeometry x="380" y="480" width="180" height="100" as="geometry"/>
4545
</mxCell>
46-
<mxCell id="14" value="(Simulated) hardware&lt;br&gt;&lt;br&gt;- host/qnodeos&lt;br&gt;- classical links&lt;br&gt;- quantum links" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
46+
<mxCell id="14" value="(Simulated) hardware&lt;br&gt;&lt;br&gt;- host/qnodeos&lt;br&gt;- classical links&lt;br&gt;- quantum links" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
4747
<mxGeometry x="640" y="470" width="150" height="130" as="geometry"/>
4848
</mxCell>
49-
<mxCell id="15" value="Hardware type" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
49+
<mxCell id="15" value="HW details needed for compiler" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
5050
<mxGeometry x="655" y="25" width="120" height="60" as="geometry"/>
5151
</mxCell>
52-
<mxCell id="16" value="" style="endArrow=none;dashed=1;html=1;strokeWidth=2;" edge="1" parent="1">
52+
<mxCell id="16" value="" style="endArrow=none;dashed=1;html=1;strokeWidth=2;" parent="1" edge="1">
5353
<mxGeometry width="50" height="50" relative="1" as="geometry">
5454
<mxPoint x="10" y="180" as="sourcePoint"/>
5555
<mxPoint x="840" y="180" as="targetPoint"/>
5656
</mxGeometry>
5757
</mxCell>
58-
<mxCell id="18" value="Global" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
58+
<mxCell id="18" value="Global" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
5959
<mxGeometry x="510" y="340" width="90" height="50" as="geometry"/>
6060
</mxCell>
61-
<mxCell id="19" value="Per node" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
61+
<mxCell id="19" value="Per node" style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
6262
<mxGeometry x="380" y="340" width="90" height="50" as="geometry"/>
6363
</mxCell>
6464
</root>

squidasm/qoala/lang/lhr.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
from netqasm.lang.operand import Template
99
from netqasm.lang.parsing.text import parse_text_subroutine
1010
from netqasm.lang.subroutine import Subroutine
11-
from netqasm.sdk.futures import Future
1211

1312
from squidasm.qoala.runtime.program import ProgramContext, ProgramMeta
1413

15-
LhrValue = Union[int, Template, Future]
14+
LhrValue = Union[int, Template]
1615

1716

1817
class LhrInstructionType(Enum):
@@ -479,15 +478,6 @@ def parse(self) -> LhrProgram:
479478
return LhrProgram(instructions, subroutines)
480479

481480

482-
class SdkProgram(abc.ABC):
483-
@property
484-
def meta(self) -> ProgramMeta:
485-
raise NotImplementedError
486-
487-
def compile(self, context: ProgramContext) -> LhrProgram:
488-
raise NotImplementedError
489-
490-
491481
if __name__ == "__main__":
492482
ops = []
493483
ops.append(SendCMsgOp("my_value"))

squidasm/qoala/lang/target.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class OfflineHardwareInfo:
2+
"""Hardware made available to offline compiler."""
3+
4+
pass

squidasm/qoala/runtime/config.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ class NVQDeviceConfig(BaseModel):
7979
carbon_rot_y: int = 500_000
8080
carbon_rot_z: int = 500_000
8181
electron_init: int = 2_000
82-
electron_rot_x: int = 5
83-
electron_rot_y: int = 5
84-
electron_rot_z: int = 5
82+
electron_rot_x: int = 5_000
83+
electron_rot_y: int = 5_000
84+
electron_rot_z: int = 5_000
8585
ec_controlled_dir_x: int = 500_000
8686
ec_controlled_dir_y: int = 500_000
8787
measure: int = 3_700
@@ -110,6 +110,8 @@ class StackConfig(BaseModel):
110110
name: str
111111
qdevice_typ: str
112112
qdevice_cfg: Any
113+
host_qnos_latency: float = 0.0
114+
instr_latency: float = 0.0
113115

114116
@classmethod
115117
def from_file(cls, path: str) -> StackConfig:
@@ -121,6 +123,8 @@ def perfect_generic_config(cls, name: str) -> StackConfig:
121123
name=name,
122124
qdevice_typ="generic",
123125
qdevice_cfg=GenericQDeviceConfig.perfect_config(),
126+
host_qnos_latency=0.0,
127+
instr_latency=0.0,
124128
)
125129

126130

@@ -166,14 +170,23 @@ class LinkConfig(BaseModel):
166170
stack2: str
167171
typ: str
168172
cfg: Any
173+
host_host_latency: float = 0.0
174+
qnos_qnos_latency: float = 0.0
169175

170176
@classmethod
171177
def from_file(cls, path: str) -> LinkConfig:
172178
return _from_file(path, LinkConfig) # type: ignore
173179

174180
@classmethod
175181
def perfect_config(cls, stack1: str, stack2: str) -> LinkConfig:
176-
return LinkConfig(stack1=stack1, stack2=stack2, typ="perfect", cfg=None)
182+
return LinkConfig(
183+
stack1=stack1,
184+
stack2=stack2,
185+
typ="perfect",
186+
cfg=None,
187+
host_host_latency=0.0,
188+
qnos_qnos_latency=0.0,
189+
)
177190

178191

179192
class StackNetworkConfig(BaseModel):

squidasm/qoala/runtime/context.py

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@
44

55
from netqasm.sdk.network import NetworkInfo
66

7+
from squidasm.qoala.runtime.environment import GlobalEnvironment
8+
79
if TYPE_CHECKING:
810
from squidasm.qoala.sim.host import Host
911

1012

1113
class NetSquidNetworkInfo(NetworkInfo):
14+
_global_env: GlobalEnvironment
15+
1216
@classmethod
1317
def _get_node_id(cls, node_name: str) -> int:
14-
nodes = NetSquidContext.get_nodes()
15-
for id, name in nodes.items():
16-
if name == node_name:
18+
nodes = cls._global_env.get_nodes()
19+
for id, info in nodes.items():
20+
if info.name == node_name:
1721
return id
1822
raise ValueError(f"Node with name {node_name} not found")
1923

2024
@classmethod
2125
def _get_node_name(cls, node_id: int) -> str:
22-
return NetSquidContext.get_nodes()[node_id]
26+
return cls._global_env.get_nodes()[node_id].name
2327

2428
@classmethod
2529
def get_node_id_for_app(cls, app_name: str) -> int:
@@ -28,32 +32,3 @@ def get_node_id_for_app(cls, app_name: str) -> int:
2832
@classmethod
2933
def get_node_name_for_app(cls, app_name: str) -> str:
3034
raise NotImplementedError
31-
32-
33-
class NetSquidContext:
34-
_protocols: Dict[str, Host] = {}
35-
_nodes: Dict[int, str] = {}
36-
37-
@classmethod
38-
def get_nodes(cls) -> Dict[int, str]:
39-
return cls._nodes
40-
41-
@classmethod
42-
def set_nodes(cls, nodes: Dict[int, str]) -> None:
43-
cls._nodes = nodes
44-
45-
@classmethod
46-
def add_node(cls, id: int, node: str) -> None:
47-
cls._nodes[id] = node
48-
49-
@classmethod
50-
def get_protocols(cls) -> Dict[str, Host]:
51-
return cls._protocols
52-
53-
@classmethod
54-
def set_protocols(cls, protocols: Dict[str, Host]) -> None:
55-
cls._protocols = protocols
56-
57-
@classmethod
58-
def add_protocol(cls, name: str, protocol: Host) -> None:
59-
cls._protocols[name] = protocol
Lines changed: 108 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,129 @@
1-
from typing import Dict, Tuple
1+
from __future__ import annotations
22

3+
from dataclasses import dataclass
4+
from typing import Dict, Tuple, Union
35

4-
class GlobalNodeInfo:
5-
pass
6+
from squidasm.qoala.runtime.config import (
7+
GenericQDeviceConfig,
8+
LinkConfig,
9+
NVQDeviceConfig,
10+
)
611

712

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
860
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
1082

1183

1284
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] = {}
1588

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] = {}
1992

93+
def get_nodes(self) -> Dict[int, GlobalNodeInfo]:
94+
return self._nodes
2095

21-
class LocalNodeInfo:
22-
pass
96+
def set_nodes(self, nodes: Dict[int, GlobalNodeInfo]) -> None:
97+
self._nodes = nodes
2398

99+
def add_node(self, id: int, node: GlobalNodeInfo) -> None:
100+
self._nodes[id] = node
24101

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
27110

28111

29112
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
31118

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
34124

35125

36126
class ProgramEnvironment:
127+
"""Environment interface given to a program"""
128+
37129
pass

squidasm/qoala/runtime/program.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from netqasm.sdk.connection import BaseNetQASMConnection
77
from netqasm.sdk.epr_socket import EPRSocket
88

9+
from squidasm.qoala.lang.lhr import LhrProgram
10+
911

1012
class ProgramContext:
1113
def __init__(
@@ -53,3 +55,11 @@ def meta(self) -> ProgramMeta:
5355

5456
def run(self, context: ProgramContext) -> Dict[str, Any]:
5557
raise NotImplementedError
58+
59+
60+
@dataclass
61+
class ProgramInstance:
62+
program: LhrProgram
63+
inputs: Dict[str, Any]
64+
num_iterations: int
65+
deadline: float

0 commit comments

Comments
 (0)