Skip to content

Commit 0e16726

Browse files
committed
Make the native teleport example work
1 parent b7445ac commit 0e16726

3 files changed

Lines changed: 29 additions & 15 deletions

File tree

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: 13 additions & 6 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,7 +117,7 @@ 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)
@@ -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

simulaqron/local/setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ def setup_local(myName: str, virtualNet: SocketsConfig, classicalNet: SocketsCon
8080
# If we are listed as a server node for the classical network, start this server
8181
if myName in classicalNet.hostDict:
8282
try:
83-
_logger.debug("LOCAL %s: Starting local classical communication server.", myName)
8483
nb = classicalNet.hostDict[myName]
84+
_logger.debug("LOCAL %s: Starting local classical communication server (%s: %s, %d).", myName, nb.name, nb.hostname, nb.port)
8585
nb.root = lNode
8686
nb.factory = pb.PBServerFactory(nb.root)
8787
reactor.listenTCP(nb.port, nb.factory)
@@ -93,8 +93,8 @@ def setup_local(myName: str, virtualNet: SocketsConfig, classicalNet: SocketsCon
9393
time.sleep(3)
9494

9595
# Connect to the local virtual node simulating the "local" qubits
96-
_logger.debug("LOCAL %s: Connecting to local virtual node.", myName)
9796
node = virtualNet.hostDict[myName]
97+
_logger.debug("LOCAL %s: Connecting to local virtual node (%s: %s, %d).", myName, node.name, node.hostname, node.port)
9898
factory = pb.PBClientFactory()
9999
reactor.connectTCP(node.hostname, node.port, factory)
100100
deferVirtual = factory.getRootObject()
@@ -104,7 +104,7 @@ def setup_local(myName: str, virtualNet: SocketsConfig, classicalNet: SocketsCon
104104
for node in classicalNet.hostDict:
105105
nb = classicalNet.hostDict[node]
106106
if nb.name != myName:
107-
_logger.debug("LOCAL %s: Making classical connection to %s.", myName, nb.name)
107+
_logger.debug("LOCAL %s: Making classical connection to %s (%s: %s, %d).", myName, nb.name, nb.name, nb.hostname, nb.port)
108108
nb.factory = pb.PBClientFactory()
109109
reactor.connectTCP(nb.hostname, nb.port, nb.factory)
110110
dList.append(nb.factory.getRootObject())

0 commit comments

Comments
 (0)