Skip to content

Commit a29832b

Browse files
committed
fixes missing process list
1 parent 04b9c64 commit a29832b

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

eqsn/gates.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ def __init__(self):
2020
self.manager = multiprocessing.Manager()
2121
self.shared_dict = SharedDict.get_instance()
2222
cpu_count = multiprocessing.cpu_count()
23-
process_queue_list = []
23+
self.process_queue_list = []
2424
for _ in range(cpu_count):
2525
q = multiprocessing.Queue()
2626
new_worker = WorkerProcess(q)
2727
p = multiprocessing.Process(target=new_worker.run, args=())
2828
p.start()
29-
process_queue_list.append((p, q))
29+
self.process_queue_list.append((p, q))
3030
self.process_picker = ProcessPicker.get_instance(
31-
cpu_count, process_queue_list)
31+
cpu_count, self.process_queue_list)
3232

3333
def new_qubit(self, q_id):
3434
"""
@@ -46,8 +46,9 @@ def stop_all(self):
4646
"""
4747
Stops the simulator from running.
4848
"""
49-
self.shared_dict.send_all_threads(None)
50-
self.shared_dict.stop_all_threads()
49+
for p, q in self.process_queue_list:
50+
q.put(None)
51+
p.join()
5152
self.shared_dict.stop_shared_dict()
5253
self.process_picker.stop_process_picker()
5354

eqsn/worker_process.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import threading
3+
import os
34
from queue import Queue
45
from eqsn.shared_dict import SharedDict
56
from eqsn.qubit_thread import SINGLE_GATE, MERGE_SEND, MERGE_ACCEPT, MEASURE,\
@@ -36,7 +37,7 @@ def run(self):
3637
elif item[0] == MERGE_ACCEPT:
3738
self.merge_accept(item[1], item[2])
3839
elif item[0] == MERGE_SEND:
39-
self.merge_send(item[1], item[2])
40+
self.merge_send(item[1], item[2], item[3])
4041
elif item[0] == MEASURE_NON_DESTRUCTIVE:
4142
self.measure_non_destructive(item[1], item[2])
4243
elif item[0] == ADD_MERGED_QUBITS_TO_DICT:

tests/test_merging_qubits.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ def test_merge():
99
q_sim.new_qubit(id2)
1010
q_sim.merge_qubits(id1, id2)
1111
q_sim.stop_all()
12+
print("merging was succesfull")
1213

1314

1415
if __name__ == "__main__":

tests/test_non_destructive_measurement.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def test_non_destructive_measurement():
1212
assert m == m2
1313
print("Test was successfull!")
1414
q_sim.stop_all()
15+
print("Stopped succesfully!")
16+
exit(0)
1517

1618

1719
if __name__ == "__main__":

0 commit comments

Comments
 (0)