Skip to content

Commit d27aa31

Browse files
Added to this branch
1 parent d6f8d8c commit d27aa31

File tree

6 files changed

+81
-33
lines changed

6 files changed

+81
-33
lines changed

examples/nativeMode/corrRNG/README.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ Bob proceeds to recover the teleported qubit.
1010

1111
In this example, we simply print out the initial state to be teleported, as well as the final state received by
1212
Bob to check whether the teleportation worked correctly.
13+
14+
15+
To start run:
16+
- simulaqron start --nodes=Alice,Bob --keep
17+
18+
sh run.sh
19+
20+
To terminate run:
21+
sh terminate.sh

examples/nativeMode/corrRNG/aliceTest.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,24 @@ def remote_test(self):
115115
#
116116
def main():
117117

118-
# In this example, we are Alice.
119-
myName = "Alice"
118+
myName = "Alice" # we are Alice
120119

121120
# This file defines the network of virtual quantum nodes
122-
network_file = simulaqron_settings.network_config_file
121+
virtualNet = SocketsConfig(str(simulaqron_settings.network_config_file), network_name="default", config_type="vnode")
123122

124-
# This file defines the nodes acting as servers in the classical communication network
125-
classicalFile = "classicalNet.cfg"
123+
# This file defines the network used for classical communication
124+
classicalNet = SocketsConfig("classicalNet.json", network_name="default", config_type="app")
126125

127-
# Read configuration files for the virtual quantum, as well as the classical network
128-
virtualNet = SocketsConfig(network_file)
129-
classicalNet = SocketsConfig(classicalFile)
130-
131-
# Check if we should run a local classical server. If so, initialize the code
132-
# to handle remote connections on the classical communication network
126+
# Check if we should run a server (if this node is listed in classicalNet)
133127
if myName in classicalNet.hostDict:
134-
lNode = localNode(classicalNet.hostDict[myName], classicalNet)
128+
# Create the local classical server
129+
logging.debug("LOCAL %s: Creating classical server.", myName)
130+
myNode = localNode(virtualNet.hostDict[myName], classicalNet)
135131
else:
136-
lNode = None
137-
138-
# Set up the local classical server if applicable, and connect to the virtual
139-
# node and other classical servers. Once all connections are set up, this will
140-
# execute the function runClientNode
141-
setup_local(myName, virtualNet, classicalNet, lNode, runClientNode)
132+
myNode = None
142133

134+
# Connect and run
135+
setup_local(myName, virtualNet, classicalNet, myNode, runClientNode)
143136

144137
##################################################################################################
145138
logging.basicConfig(format="%(asctime)s:%(levelname)s:%(message)s", level=logging.DEBUG)

examples/nativeMode/corrRNG/bobTest.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from twisted.internet.defer import inlineCallbacks
3737
from twisted.spread import pb
3838

39+
from qutip import Qobj
40+
3941

4042
#####################################################################################################
4143
#
@@ -103,6 +105,18 @@ def remote_process_qubit(self, virtualNum):
103105

104106
print("BOB: My Random Number is ", x, "\n")
105107

108+
def assemble_qubit(self, realM, imagM):
109+
"""
110+
Reconstitute the qubit as a qutip object from its real and imaginary components given as a list.
111+
We need this since Twisted PB does not support sending complex valued object natively.
112+
"""
113+
M = realM
114+
for s in range(len(M)):
115+
for t in range(len(M)):
116+
M[s][t] = realM[s][t] + 1j * imagM[s][t]
117+
118+
return Qobj(M)
119+
106120

107121
#####################################################################################################
108122
#
@@ -113,27 +127,25 @@ def main():
113127
# In this example, we are Bob.
114128
myName = "Bob"
115129

116-
# This file defines the network of virtual quantum nodes
117-
network_file = simulaqron_settings.network_config_file
118130

119-
# This file defines the nodes acting as servers in the classical communication network
120-
classicalFile = "classicalNet.cfg"
131+
logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=logging.DEBUG)
132+
133+
# This file defines the network of virtual quantum nodes
134+
virtualNet = SocketsConfig(str(simulaqron_settings.network_config_file), network_name="default", config_type="vnode")
121135

122-
# Read configuration files for the virtual quantum, as well as the classical network
123-
virtualNet = SocketsConfig(network_file)
124-
classicalNet = SocketsConfig(classicalFile)
136+
# This file defines the network used for classical communication
137+
classicalNet = SocketsConfig("classicalNet.json", network_name="default", config_type="app")
125138

126-
# Check if we should run a local classical server. If so, initialize the code
127-
# to handle remote connections on the classical communication network
139+
# Check if we should run a server (if this node is listed in classicalNet)
128140
if myName in classicalNet.hostDict:
129-
lNode = localNode(classicalNet.hostDict[myName], classicalNet)
141+
# Create the local classical server
142+
myNode = localNode(virtualNet.hostDict[myName], classicalNet)
130143
else:
131-
lNode = None
144+
myNode = None
145+
146+
# Connect and run
147+
setup_local(myName, virtualNet, classicalNet, myNode, runClientNode)
132148

133-
# Set up the local classical server if applicable, and connect to the virtual
134-
# node and other classical servers. Once all connections are set up, this will
135-
# execute the function runClientNode
136-
setup_local(myName, virtualNet, classicalNet, lNode, runClientNode)
137149

138150

139151
##################################################################################################
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"default": {
3+
"nodes": {
4+
"Alice": {
5+
"app_socket": ["localhost", 8821],
6+
"qnodeos_socket": ["localhost", 8822],
7+
"vnode_socket": ["localhost", 8823]
8+
},
9+
"Bob": {
10+
"app_socket": ["localhost", 8831],
11+
"qnodeos_socket": ["localhost", 8832],
12+
"vnode_socket": ["localhost", 8833]
13+
}
14+
},
15+
"topology": null
16+
}
17+
}

examples/nativeMode/corrRNG/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/bin/sh
22

3+
# Check if SimulaQron is already running
4+
if [ ! -f ~/.simulaqron_pids/simulaqron_network_default.pid ]; then
5+
simulaqron start --nodes=Alice,Bob --force
6+
fi
7+
38
python3 bobTest.py &
49
python3 aliceTest.py
510

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
8+
# Check if SimulaQron is running
9+
if [ -f ~/.simulaqron_pids/simulaqron_network_default.pid ]; then
10+
cat $HOME/.simulaqron_pids/simulaqron_network_default.pid | xargs kill -9
11+
fi
12+

0 commit comments

Comments
 (0)