Skip to content

Commit cedbebd

Browse files
committed
Add example for distributed teleport
1 parent ee7067f commit cedbebd

File tree

5 files changed

+164
-2
lines changed

5 files changed

+164
-2
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"default": {
3+
"nodes": {
4+
"Alice": {
5+
"app_socket": [
6+
"192.168.0.160",
7+
8001
8+
],
9+
"qnodeos_socket": [
10+
"192.168.0.160",
11+
8005
12+
],
13+
"vnode_socket": [
14+
"192.168.0.160",
15+
8020
16+
]
17+
},
18+
"Bob": {
19+
"app_socket": [
20+
"192.168.20.249",
21+
8032
22+
],
23+
"qnodeos_socket": [
24+
"192.168.20.249",
25+
8037
26+
],
27+
"vnode_socket": [
28+
"192.168.20.249",
29+
8050
30+
]
31+
}
32+
},
33+
"topology": null
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"default": {
3+
"nodes": {
4+
"Alice": {
5+
"app_socket": [
6+
"localhost",
7+
8001
8+
],
9+
"qnodeos_socket": [
10+
"localhost",
11+
8005
12+
],
13+
"vnode_socket": [
14+
"localhost",
15+
8020
16+
]
17+
},
18+
"Bob": {
19+
"app_socket": [
20+
"localhost",
21+
8032
22+
],
23+
"qnodeos_socket": [
24+
"localhost",
25+
8037
26+
],
27+
"vnode_socket": [
28+
"localhost",
29+
8050
30+
]
31+
}
32+
},
33+
"topology": null
34+
}
35+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from pathlib import Path
2+
3+
from netqasm.runtime.settings import set_simulator
4+
from netqasm.runtime.application import default_app_instance
5+
6+
from simulaqron.run.run import run_applications
7+
8+
set_simulator("simulaqron")
9+
10+
from netqasm.sdk.external import NetQASMConnection # noqa: E402
11+
from netqasm.sdk import Qubit, EPRSocket # noqa: E402
12+
13+
14+
def run_alice():
15+
epr_socket: EPRSocket = EPRSocket("Bob")
16+
with NetQASMConnection("Alice", epr_sockets=[epr_socket]) as alice:
17+
# Create a qubit
18+
q = Qubit(alice)
19+
q.H()
20+
21+
# Create entanglement
22+
epr = epr_socket.create_keep()[0]
23+
24+
# Teleport
25+
q.cnot(epr)
26+
q.H()
27+
m1 = q.measure()
28+
m2 = epr.measure()
29+
return m1, m2
30+
31+
32+
if __name__ == "__main__":
33+
apps = default_app_instance(
34+
[
35+
("Alice", run_alice)
36+
]
37+
)
38+
network_cfg_path = Path() / "network-alice.json"
39+
raw_results = run_applications(
40+
apps, use_app_config=False, enable_logging=False, network_cfg=network_cfg_path.resolve()
41+
)
42+
43+
results = {}
44+
45+
for name, raw_result in raw_results[0].items():
46+
if isinstance(raw_result, tuple):
47+
results[name] = tuple(int(result) for result in raw_result)
48+
else:
49+
results[name] = int(raw_result)
50+
51+
print(results)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from pathlib import Path
2+
3+
from netqasm.runtime.settings import set_simulator
4+
5+
from netqasm.runtime.application import default_app_instance
6+
7+
from simulaqron.run.run import run_applications
8+
9+
set_simulator("simulaqron")
10+
from netqasm.sdk.external import NetQASMConnection # noqa: E402
11+
from netqasm.sdk import EPRSocket # noqa: E402
12+
13+
14+
def run_bob():
15+
epr_socket: EPRSocket = EPRSocket("Alice")
16+
with NetQASMConnection("Bob", epr_sockets=[epr_socket]):
17+
entangled_qubit = epr_socket.recv_keep()[0]
18+
meas = entangled_qubit.measure()
19+
return meas
20+
21+
22+
if __name__ == "__main__":
23+
apps = default_app_instance(
24+
[
25+
("Bob", run_bob)
26+
]
27+
)
28+
network_cfg_path = Path() / "network-alice.json"
29+
raw_results = run_applications(
30+
apps, use_app_config=False, enable_logging=False, network_cfg=network_cfg_path.resolve()
31+
)
32+
33+
results = {}
34+
35+
for name, raw_result in raw_results[0].items():
36+
if isinstance(raw_result, tuple):
37+
results[name] = tuple(int(result) for result in raw_result)
38+
else:
39+
results[name] = int(raw_result)
40+
41+
print(results)

simulaqron/run/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from os import PathLike
66
from pathlib import Path
77
from time import sleep
8-
from typing import Callable, Optional, Any, Dict, List
8+
from typing import Callable, Optional, Any, Dict, List, Union
99

1010
from netqasm.logging.glob import get_netqasm_logger
1111
from netqasm.logging.output import (reset_struct_loggers,
@@ -79,7 +79,7 @@ def run_sim_backend(node_names: List[str], sim_backend: SimBackend, network_conf
7979
def run_applications(
8080
app_instance: ApplicationInstance,
8181
num_rounds: int = 1,
82-
network_cfg: str = None, # WARNING - The type of this argument *cannot* be harmonized
82+
network_cfg: Union[str, PathLike, Path] = None, # WARNING - The type of this argument *cannot* be harmonized
8383
nv_cfg: Any = None, # Unused; it's here for harmonization with squidasm "simulate_application"
8484
log_cfg: LogConfig = None,
8585
formalism: Formalism = Formalism.KET,

0 commit comments

Comments
 (0)