Skip to content

Commit c2ad9ff

Browse files
committed
Move other native mode examples to the new network configuration format
1 parent 93089c3 commit c2ad9ff

27 files changed

Lines changed: 232 additions & 173 deletions

examples/nativeMode/WARNINIG

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/nativeMode/corrRNG/aliceTest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def remote_test(self):
114114
# main
115115
#
116116
def main():
117-
118117
myName = "Alice" # we are Alice
119118

120119
# This file defines the network of virtual quantum nodes and the network used for classical communication
Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#!/usr/bin/env sh
2-
TEST_PIDS=$(ps aux | grep python | grep -E "Test" | awk {'print $2'})
3-
if [ "$TEST_PIDS" != "" ]
4-
then
5-
kill -9 $TEST_PIDS
6-
fi
7-
sh run.sh
1+
#!/usr/bin/env bash
2+
3+
./terminate.sh
4+
./run.sh

examples/nativeMode/corrRNG/run.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

33
# Check if SimulaQron is already running
44
if [ ! -f ~/.simulaqron_pids/simulaqron_network_default.pid ]; then
5-
simulaqron start --nodes=Alice,Bob --network-config-file classicalNet.json
5+
if ! simulaqron start --nodes=Alice,Bob --network-config-file classicalNet.json
6+
then
7+
echo "SimulaQron could not start correctly!"
8+
exit 1
9+
fi
610
fi
711

812
python3 bobTest.py &
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env sh
1+
#!/usr/bin/env bash
22
TEST_PIDS=$(ps aux | grep python | grep -E "Test" | awk {'print $2'})
33
if [ "$TEST_PIDS" != "" ]
44
then
@@ -7,6 +7,10 @@ fi
77

88
# Check if SimulaQron is running
99
if [ -f ~/.simulaqron_pids/simulaqron_network_default.pid ]; then
10-
cat $HOME/.simulaqron_pids/simulaqron_network_default.pid | xargs kill -9
10+
if ! simulaqron stop
11+
then
12+
# Kill the process, only if simulaqron could not be stopped gracefully
13+
cat $HOME/.simulaqron_pids/simulaqron_network_default.pid | xargs kill -9
14+
fi
1115
fi
1216

examples/nativeMode/extendGHZ/aliceTest.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2828
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
import os
3130
import logging
3231

3332
from simulaqron.local.setup import setup_local
3433
from simulaqron.general.host_config import SocketsConfig
35-
from simulaqron.settings import simulaqron_settings
34+
from simulaqron.settings import network_config
3635
from twisted.internet.defer import inlineCallbacks
3736
from twisted.spread import pb
3837
from twisted.internet import reactor
@@ -71,7 +70,7 @@ def runClientNode(qReg, virtRoot, myName, classicalNet):
7170
# Send qubit B to Bob
7271
# Instruct the virtual node to transfer the qubit
7372
remoteNum = yield virtRoot.callRemote("send_qubit", qB, "Bob")
74-
logging.debug("LOCAL {}: Remote qubit is %d.", myName, remoteNum)
73+
logging.debug("LOCAL %s: Remote qubit is %d.", myName, remoteNum)
7574

7675
# Tell Bob the number of the virtual qubit so the can use it locally
7776
# and extend it to a GHZ state with Charlie
@@ -120,15 +119,12 @@ def main():
120119
# In this example, we are Alice.
121120
myName = "Alice"
122121

123-
# This file defines the network of virtual quantum nodes
124-
network_file = simulaqron_settings.network_config_file
122+
# This file defines the network of virtual quantum nodes and the network used for classical communication
123+
network_config.read_from_file("classicalNet.json")
125124

126-
# This file defines the nodes acting as servers in the classical communication network
127-
classicalFile = os.path.join(os.path.dirname(__file__), "classicalNet.cfg")
128-
129-
# Read configuration files for the virtual quantum, as well as the classical network
130-
virtualNet = SocketsConfig(network_file)
131-
classicalNet = SocketsConfig(classicalFile)
125+
# Using the config, we then get the right sockets configuration type
126+
virtualNet = SocketsConfig(network_config, network_name="default", config_type="vnode")
127+
classicalNet = SocketsConfig(network_config, network_name="default", config_type="app")
132128

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

examples/nativeMode/extendGHZ/bobTest.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2828
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
import os
3130
import logging
3231

3332
from simulaqron.local.setup import setup_local
3433
from simulaqron.general.host_config import SocketsConfig
35-
from simulaqron.settings import simulaqron_settings
34+
from simulaqron.settings import network_config
3635
from twisted.internet.defer import inlineCallbacks
3736
from twisted.spread import pb
3837

@@ -116,26 +115,23 @@ def remote_receive_epr(self, virtualNum):
116115

117116
# Measure our qubit
118117
outcome = yield eprB.callRemote("measure")
119-
print("Bob's outcome was: {}".format(outcome))
118+
print(f"Bob's outcome was: {outcome}")
120119

121120

122121
#####################################################################################################
123122
#
124123
# main
125124
#
126125
def main():
127-
# In this example, we are Charlie.
126+
# In this example, we are Bob.
128127
myName = "Bob"
129128

130-
# This file defines the network of virtual quantum nodes
131-
network_file = simulaqron_settings.network_config_file
129+
# This file defines the network of virtual quantum nodes and the network used for classical communication
130+
network_config.read_from_file("classicalNet.json")
132131

133-
# This file defines the nodes acting as servers in the classical communication network
134-
classicalFile = os.path.join(os.path.dirname(__file__), "classicalNet.cfg")
135-
136-
# Read configuration files for the virtual quantum, as well as the classical network
137-
virtualNet = SocketsConfig(network_file)
138-
classicalNet = SocketsConfig(classicalFile)
132+
# Using the config, we then get the right sockets configuration type
133+
virtualNet = SocketsConfig(network_config, network_name="default", config_type="vnode")
134+
classicalNet = SocketsConfig(network_config, network_name="default", config_type="app")
139135

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

examples/nativeMode/extendGHZ/charlieTest.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2828
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
import os
3130
import logging
3231

3332
from simulaqron.local.setup import setup_local
3433
from simulaqron.general.host_config import SocketsConfig
35-
from simulaqron.settings import simulaqron_settings
34+
from simulaqron.settings import network_config
3635
from twisted.internet.defer import inlineCallbacks
3736
from twisted.spread import pb
3837

@@ -102,26 +101,25 @@ def remote_receive_ghz(self, virtualNum):
102101

103102
# Measure it
104103
outcome = yield q.callRemote("measure")
105-
print("Charlie's outcome was: {}".format(outcome))
104+
print(f"Charlie's outcome was: {outcome}")
106105

107106

108107
#####################################################################################################
109108
#
110109
# main
111110
#
112111
def main():
113-
# In this example, we are Bob.
112+
# In this example, we are Charlie.
114113
myName = "Charlie"
115114

116-
# This file defines the network of virtual quantum nodes
117-
network_file = simulaqron_settings.network_config_file
115+
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.DEBUG)
118116

119-
# This file defines the nodes acting as servers in the classical communication network
120-
classicalFile = os.path.join(os.path.dirname(__file__), "classicalNet.cfg")
117+
# This file defines the network of virtual quantum nodes and the network used for classical communication
118+
network_config.read_from_file("classicalNet.json")
121119

122-
# Read configuration files for the virtual quantum, as well as the classical network
123-
virtualNet = SocketsConfig(network_file)
124-
classicalNet = SocketsConfig(classicalFile)
120+
# Using the config, we then get the right sockets configuration type
121+
virtualNet = SocketsConfig(network_config, network_name="default", config_type="vnode")
122+
classicalNet = SocketsConfig(network_config, network_name="default", config_type="app")
125123

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

examples/nativeMode/extendGHZ/classicalNet.cfg

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[
2+
{
3+
"name": "default",
4+
"nodes": [
5+
{
6+
"Alice": {
7+
"app_socket": ["localhost", 8821],
8+
"qnodeos_socket": ["localhost", 8822],
9+
"vnode_socket": ["localhost", 8823]
10+
}
11+
},
12+
{
13+
"Bob": {
14+
"app_socket": ["localhost", 8831],
15+
"qnodeos_socket": ["localhost", 8832],
16+
"vnode_socket": ["localhost", 8833]
17+
}
18+
},
19+
{
20+
"Charlie": {
21+
"app_socket": ["localhost", 8841],
22+
"qnodeos_socket": ["localhost", 8842],
23+
"vnode_socket": ["localhost", 8843]
24+
}
25+
}
26+
],
27+
"topology": null
28+
}
29+
]

0 commit comments

Comments
 (0)