Skip to content

Commit 6cb20bd

Browse files
author
Axel Dahlberg
committed
Fixed some old tests and improved Network.running property
1 parent 3697c29 commit 6cb20bd

File tree

6 files changed

+59
-73
lines changed

6 files changed

+59
-73
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ For more details refer to the [documentation](https://softwarequtech.github.io/S
66
Upcoming
77
--------
88

9+
2020-02-23 (v3.0.14)
10+
-------------------
11+
- Fixed some old tests and improved how a network checks if it's running or not.
12+
913
2020-02-23 (v3.0.13)
1014
-------------------
1115
- Fixed bug in the Boolean Gaussian elimination in stabilizer formalism.

simulaqron/cqc_backend/cqcMessageHandler.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def cmd_measure(self, cqc_header, cmd, xtra, inplace=False):
422422
msg = hdr.pack()
423423
self.return_messages[cqc_header.app_id].append(msg)
424424
# self.protocol.transport.write(msg)
425-
logging.debug("CQC %s: Notify %s", self.name, hdr.printable())
425+
logging.debug("CQC %s: Notify %s", self.name, hdr)
426426

427427
if not inplace:
428428
# Remove from active mapped qubits
@@ -482,7 +482,7 @@ def cmd_send(self, cqc_header, cmd, xtra):
482482
# Lookup the name of the remote node used within SimulaQron
483483
target_name = self.factory.lookup(xtra.remote_node, xtra.remote_port)
484484
if target_name is None:
485-
logging.warning("CQC %s: Remote node not found %s", self.name, xtra.printable())
485+
logging.warning("CQC %s: Remote node not found %s", self.name, xtra)
486486
err_msg = self.create_return_message(cqc_header.app_id, CQC_ERR_UNSUPP, cqc_version=cqc_header.version)
487487
self.return_messages[cqc_header.app_id].append(err_msg)
488488
return False
@@ -654,7 +654,7 @@ def cmd_recv(self, cqc_header, cmd, xtra):
654654
hdr.setVals(qubit_id=q_id)
655655
msg = hdr.pack()
656656
# self.protocol.transport.write(msg)
657-
logging.debug("CQC %s: Notify %s", self.name, hdr.printable())
657+
logging.debug("CQC %s: Notify %s", self.name, hdr)
658658
self.return_messages[cqc_header.app_id].append(msg)
659659
return True
660660

@@ -677,7 +677,7 @@ def cmd_epr(self, cqc_header, cmd, xtra):
677677
# Lookup the name of the remote node used within SimulaQron
678678
target_name = self.factory.lookup(remote_node, remote_port)
679679
if target_name is None:
680-
logging.warning("CQC %s: Remote node not found %s", self.name, xtra.printable())
680+
logging.warning("CQC %s: Remote node not found %s", self.name, xtra)
681681
err_msg = self.create_return_message(cqc_header.app_id, CQC_ERR_UNSUPP, cqc_version=cqc_header.version)
682682
self.return_messages[cqc_header.app_id].append(err_msg)
683683
return False
@@ -914,12 +914,12 @@ def cmd_epr(self, cqc_header, cmd, xtra):
914914
msg = hdr.pack()
915915
self.return_messages[cqc_header.app_id].append(msg)
916916

917-
logging.debug("CQC %s: Notify %s", self.name, hdr.printable())
917+
logging.debug("CQC %s: Notify %s", self.name, hdr)
918918

919919
# Send entanglement info
920920
msg_ent_info = ent_info.pack()
921921
self.return_messages[cqc_header.app_id].append(msg_ent_info)
922-
logging.debug("CQC %s: Entanglement information %s", self.name, ent_info.printable())
922+
logging.debug("CQC %s: Entanglement information %s", self.name, ent_info)
923923

924924
logging.debug("CQC %s: EPR Pair ID %d qubit id %d", self.name, cqc_header.app_id, cmd.qubit_id)
925925
return True
@@ -941,7 +941,7 @@ def send_epr_half(self, cqc_header, cmd, xtra, ent_info):
941941
# Lookup the name of the remote node used within SimulaQron
942942
target_name = self.factory.lookup(xtra.remote_node, xtra.remote_port)
943943
if target_name is None:
944-
logging.debug("CQC %s: Remote node not found %s", self.name, xtra.printable())
944+
logging.debug("CQC %s: Remote node not found %s", self.name, xtra)
945945
return False
946946

947947
# Prepare update raw entanglement information header
@@ -1064,18 +1064,18 @@ def cmd_epr_recv(self, cqc_header, cmd, xtra):
10641064
if cqc_header.version < 2:
10651065
hdr = CQCNotifyHeader()
10661066
hdr.setVals(q_id, 0, 0, 0, 0, 0)
1067-
logging.debug("CQC %s: Notify %s", self.name, hdr.printable())
1067+
logging.debug("CQC %s: Notify %s", self.name, hdr)
10681068
else:
10691069
hdr = CQCXtraQubitHeader()
10701070
hdr.setVals(qubit_id=q_id)
1071-
logging.debug("CQC %s: %s", self.name, hdr.printable())
1071+
logging.debug("CQC %s: %s", self.name, hdr)
10721072
msg = hdr.pack()
10731073
self.return_messages[cqc_header.app_id].append(msg)
10741074

10751075
# Send entanglement info
10761076
ent_info_msg = ent_info.pack()
10771077
self.return_messages[cqc_header.app_id].append(ent_info_msg)
1078-
logging.debug("CQC %s: Entanglement information %s", self.name, ent_info.printable())
1078+
logging.debug("CQC %s: Entanglement information %s", self.name, ent_info)
10791079

10801080
logging.debug("CQC %s: EPR Pair ID %d qubit id %d", self.name, cqc_header.app_id, cmd.qubit_id)
10811081
return True
@@ -1149,11 +1149,11 @@ def cmd_new(self, cqc_header, cmd, xtra, return_q_id=False, ignore_max_qubits=Fa
11491149
if cqc_header.version < 2:
11501150
hdr = CQCNotifyHeader()
11511151
hdr.setVals(q_id, 0, 0, 0, 0, 0)
1152-
logging.info("CQC %s: Notify %s", self.name, hdr.printable())
1152+
logging.info("CQC %s: Notify %s", self.name, hdr)
11531153
else:
11541154
hdr = CQCXtraQubitHeader()
11551155
hdr.setVals(qubit_id=q_id)
1156-
logging.info("CQC %s: %s", self.name, hdr.printable())
1156+
logging.info("CQC %s: %s", self.name, hdr)
11571157
msg = hdr.pack()
11581158
self.return_messages[cqc_header.app_id].append(msg)
11591159
finally:

simulaqron/network.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,17 @@ def running(self):
124124
"""
125125
Is the network up and running?
126126
"""
127+
if self._running:
128+
return True
127129
for node in self.nodes:
128130
try:
129131
cqc = CQCConnection(node, retry_connection=False, network_name=self.name)
130132
except ConnectionRefusedError:
131133
self._running = False
132134
break
135+
except Exception as err:
136+
logging.exception(f"Got unexpected exception when trying to connect: {err}")
137+
raise err
133138
else:
134139
cqc.close()
135140
else:

simulaqron/tests/unittests/quick/general/test_hostConfig.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from simulaqron.general.hostConfig import NetworksConfigConstructor, socketsConfig
55

6+
PATH_TO_HERE = os.path.abspath(os.path.dirname(__file__))
7+
68

79
class TestNetworkConfig(unittest.TestCase):
810
def test_read_write(self):
@@ -13,7 +15,7 @@ def test_read_write(self):
1315
network_config.add_node("Charlie", network_name="test")
1416

1517
dct1 = network_config.to_dict()
16-
file_path = os.path.join("resources", "test.json")
18+
file_path = os.path.join(PATH_TO_HERE, "resources", "test.json")
1719
network_config.write_to_file(file_path)
1820

1921
network_config2 = NetworksConfigConstructor(file_path=file_path)
@@ -27,10 +29,10 @@ def test_read_write(self):
2729

2830
class TestSocketsConfig(unittest.TestCase):
2931
def test_load_file(self):
30-
file_path1 = os.path.join("resources", "sockets.cfg")
32+
file_path1 = os.path.join(PATH_TO_HERE, "resources", "sockets.cfg")
3133
conf1 = socketsConfig(file_path1)
3234

33-
file_path2 = os.path.join("resources", "network.json")
35+
file_path2 = os.path.join(PATH_TO_HERE, "resources", "network.json")
3436
conf2 = socketsConfig(file_path2, config_type="cqc")
3537

3638
for node_name, host in conf1.hostDict.items():

simulaqron/tests/unittests/slow/merges/configs/network.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,39 @@
88
],
99
"cqc_socket": [
1010
"localhost",
11-
8005
11+
8003
1212
],
1313
"vnode_socket": [
1414
"localhost",
15-
8006
15+
8004
1616
]
1717
},
1818
"Bob": {
1919
"app_socket": [
2020
"localhost",
21-
8011
21+
8008
2222
],
2323
"cqc_socket": [
2424
"localhost",
25-
8012
25+
8014
2626
],
2727
"vnode_socket": [
2828
"localhost",
29-
8015
29+
8017
3030
]
3131
},
3232
"Charlie": {
3333
"app_socket": [
3434
"localhost",
35-
8036
35+
8026
3636
],
3737
"cqc_socket": [
3838
"localhost",
39-
8044
39+
8029
4040
],
4141
"vnode_socket": [
4242
"localhost",
43-
8045
43+
8036
4444
]
4545
}
4646
},

0 commit comments

Comments
 (0)