Skip to content

Commit c2a6df9

Browse files
committed
Merge branch 'Rework_network_config' into release4.0.0-preview
2 parents d27aa31 + b2d9300 commit c2a6df9

36 files changed

+1559
-1240
lines changed
Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
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-
]
1+
[
2+
{
3+
"name": "default",
4+
"nodes": [
5+
{
6+
"Alice": {
7+
"app_socket": [
8+
"192.168.0.160",
9+
8001
10+
],
11+
"qnodeos_socket": [
12+
"192.168.0.160",
13+
8005
14+
],
15+
"vnode_socket": [
16+
"192.168.0.160",
17+
8020
18+
]
19+
}
1720
},
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-
]
21+
{
22+
"Bob": {
23+
"app_socket": [
24+
"192.168.20.249",
25+
8032
26+
],
27+
"qnodeos_socket": [
28+
"192.168.20.249",
29+
8037
30+
],
31+
"vnode_socket": [
32+
"192.168.20.249",
33+
8050
34+
]
35+
}
3136
}
32-
},
37+
],
3338
"topology": null
3439
}
35-
}
40+
]
Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
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-
]
1+
[
2+
{
3+
"name": "default",
4+
"nodes": [
5+
{
6+
"Alice": {
7+
"app_socket": [
8+
"localhost",
9+
8001
10+
],
11+
"qnodeos_socket": [
12+
"localhost",
13+
8005
14+
],
15+
"vnode_socket": [
16+
"localhost",
17+
8020
18+
]
19+
}
1720
},
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-
]
21+
{
22+
"Bob": {
23+
"app_socket": [
24+
"localhost",
25+
8032
26+
],
27+
"qnodeos_socket": [
28+
"localhost",
29+
8037
30+
],
31+
"vnode_socket": [
32+
"localhost",
33+
8050
34+
]
35+
}
3136
}
32-
},
37+
],
3338
"topology": null
3439
}
35-
}
40+
]

examples/nativeMode/teleport/README.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Description
12

23
In this example, we have only two nodes: Alice and Bob.
34

@@ -10,3 +11,49 @@ Bob proceeds to recover the teleported qubit.
1011

1112
In this example, we simply print out the initial state to be teleported, as well as the final state received by
1213
Bob to check whether the teleportation worked correctly.
14+
15+
16+
# How to run
17+
18+
To run this example, first make sure that the python virtual environment is activated. You can easily check this
19+
with the terminal command prompt, which shows the active python virtual environment in parentheses:
20+
```
21+
(simulaqron) user@machine_name:~$
22+
```
23+
If you don't see the name of the virtual environment, please check the SimulaQron README file to know how to
24+
create and activate it.
25+
26+
Once the environment is active, we need to start the simulaqron network:
27+
```bash
28+
siumulaqron start --nodes Alice,Bob
29+
```
30+
31+
This will read the JSON configuration files and start the SimulaQron virtual nodes for nodes `Alice` and `Bob`.
32+
33+
After this, you can simply run the example by using the `run` script:
34+
```bash
35+
./run.sh
36+
```
37+
38+
# How to stop the execution in case the test execution stalls.
39+
40+
To fully stop the execution, you can use the `doNew` script. This will stop the current execution and run the
41+
example once again:
42+
```bash
43+
./doNew.sh
44+
```
45+
46+
47+
# Troubleshooting
48+
49+
## Trying to start the network gives "Network with name <name> is already running" message
50+
51+
This usually happens when you stopped the network "manually" by killing processes (`kill -9`). If this happens,
52+
please make sure that you kill all related processes (use `ps aux | grep python` to search) and then delete the
53+
PID file for the running network. This file is located in `~/simulaqron_pids` and it is called
54+
`simulaqron_network_<network_name>.pid`:
55+
```bash
56+
rm ~/simulaqron_pids/simulaqron_network_<network_name>.pid
57+
```
58+
59+
After this, you can try to start the network again

examples/nativeMode/teleport/aliceTest.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232

3333
from simulaqron.local.setup import setup_local, assemble_qubit
3434
from simulaqron.general.host_config import SocketsConfig
35+
from simulaqron.settings.network_config import NodeConfigType
3536
from simulaqron.toolbox.stabilizer_states import StabilizerState
36-
from simulaqron.settings import simulaqron_settings
37+
from simulaqron.settings import simulaqron_settings, network_config, LOCAL_SIMULAQRON_SETTINGS, LOCAL_NETWORK_SETTINGS
3738
from twisted.internet.defer import inlineCallbacks
3839
from twisted.spread import pb
3940
from twisted.internet import reactor
@@ -73,7 +74,7 @@ def runClientNode(qReg, virtRoot, myName, classicalNet):
7374
realRho, imagRho = yield q1.callRemote("get_qubit")
7475
state = np.array(assemble_qubit(realRho, imagRho), dtype=complex)
7576
elif simulaqron_settings.sim_backend.value == "projectq":
76-
realvec, imagvec = yield virtRoot.callRemote("get_register_RI", q1)
77+
_, (realvec, imagvec) = yield virtRoot.callRemote("get_register_RI", q1)
7778
state = [r + (1j * j) for r, j in zip(realvec, imagvec)]
7879
elif simulaqron_settings.sim_backend.value == "stabilizer":
7980
array, _ = yield virtRoot.callRemote("get_register_RI", q1)
@@ -148,14 +149,20 @@ def main():
148149
myName = "Alice"
149150

150151
# This file defines the network of virtual quantum nodes
151-
network_file = simulaqron_settings.network_config_file
152+
# network_file = simulaqron_settings.network_config_file
153+
# virtualNet = SocketsConfig(network_file)
152154

153155
# This file defines the nodes acting as servers in the classical communication network
154-
classicalFile = "classicalNet.cfg"
156+
# classicalFile = "classicalNet.cfg"
157+
# classicalNet = SocketsConfig(classicalFile)
158+
159+
# We load the local configuration files
160+
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
161+
network_config.read_from_file(LOCAL_NETWORK_SETTINGS)
155162

156163
# Read configuration files for the virtual quantum, as well as the classical network
157-
virtualNet = SocketsConfig(network_file)
158-
classicalNet = SocketsConfig(classicalFile)
164+
virtualNet = SocketsConfig(network_config, config_type=NodeConfigType.VNODE)
165+
classicalNet = SocketsConfig(network_config, config_type=NodeConfigType.APP)
159166

160167
# Check if we should run a local classical server. If so, initialize the code
161168
# to handle remote connections on the classical communication network

examples/nativeMode/teleport/bobTest.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
from simulaqron.local.setup import setup_local, assemble_qubit
3535
from simulaqron.general.host_config import SocketsConfig
36-
from simulaqron.settings import simulaqron_settings
36+
from simulaqron.settings import simulaqron_settings, network_config, LOCAL_SIMULAQRON_SETTINGS, LOCAL_NETWORK_SETTINGS
37+
from simulaqron.settings.network_config import NodeConfigType
3738
from simulaqron.toolbox.stabilizer_states import StabilizerState
3839
from twisted.internet.defer import inlineCallbacks
3940
from twisted.spread import pb
@@ -116,15 +117,15 @@ def remote_recover_teleport(self, a, b, virtualNum):
116117
(realRho, imagRho) = yield eprB.callRemote("get_qubit")
117118
state = np.array(assemble_qubit(realRho, imagRho), dtype=complex)
118119
elif simulaqron_settings.sim_backend.value == "projectq":
119-
realvec, imagvec = yield self.virtRoot.callRemote("get_register_RI", eprB)
120+
_, (realvec, imagvec) = yield self.virtRoot.callRemote("get_register_RI", eprB)
120121
state = [r + (1j * j) for r, j in zip(realvec, imagvec)]
121122
elif simulaqron_settings.sim_backend.value == "stabilizer":
122123
array, _, = yield self.virtRoot.callRemote("get_register_RI", eprB)
123124
state = StabilizerState(array)
124125
else:
125126
ValueError(f"Unknown backend {simulaqron_settings.sim_backend}")
126127

127-
print(f"Qubit is:\n{state}")
128+
print(f"Qubit is: \n{state}")
128129

129130

130131
#####################################################################################################
@@ -137,14 +138,20 @@ def main():
137138
myName = "Bob"
138139

139140
# This file defines the network of virtual quantum nodes
140-
network_file = simulaqron_settings.network_config_file
141+
# network_file = simulaqron_settings.network_config_file
142+
# virtualNet = SocketsConfig(network_file)
141143

142144
# This file defines the nodes acting as servers in the classical communication network
143-
classicalFile = "classicalNet.cfg"
145+
# classicalFile = "classicalNet.cfg"
146+
# classicalNet = SocketsConfig(classicalFile)
147+
148+
# We load the local configuration files
149+
simulaqron_settings.load_from_file(LOCAL_SIMULAQRON_SETTINGS)
150+
network_config.read_from_file(LOCAL_NETWORK_SETTINGS)
144151

145152
# Read configuration files for the virtual quantum, as well as the classical network
146-
virtualNet = SocketsConfig(network_file)
147-
classicalNet = SocketsConfig(classicalFile)
153+
virtualNet = SocketsConfig(network_config, config_type=NodeConfigType.VNODE)
154+
classicalNet = SocketsConfig(network_config, config_type=NodeConfigType.APP)
148155

149156
# Check if we should run a local classical server. If so, initialize the code
150157
# to handle remote connections on the classical communication network
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[
2+
{
3+
"name": "default",
4+
"nodes": [
5+
{
6+
"Alice": {
7+
"app_socket": [
8+
"localhost",
9+
8001
10+
],
11+
"qnodeos_socket": [
12+
"localhost",
13+
8002
14+
],
15+
"vnode_socket": [
16+
"localhost",
17+
8003
18+
]
19+
}
20+
},
21+
{
22+
"Bob": {
23+
"app_socket": [
24+
"localhost",
25+
8010
26+
],
27+
"qnodeos_socket": [
28+
"localhost",
29+
8011
30+
],
31+
"vnode_socket": [
32+
"localhost",
33+
8012
34+
]
35+
}
36+
}
37+
],
38+
"topology": null
39+
}
40+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"max_qubits": 20,
3+
"max_registers": 1000,
4+
"conn_retry_time": 0.5,
5+
"conn_max_retries": 10,
6+
"recv_timeout": 100,
7+
"recv_retry_time": 0.1,
8+
"recv_max_retries": 10,
9+
"log_level": 30,
10+
"sim_backend": "projectq",
11+
"noisy_qubits": false,
12+
"max_app_waiting_time": -1.0,
13+
"t1": 1.0
14+
}

examples/nativeMode/template/run.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,3 @@
33
# Run the files for Alice, Bob or whatever nodes you construct
44
python3 bobTest.py &
55
python3 aliceTest.py
6-
7-
8-
9-
10-

0 commit comments

Comments
 (0)