Skip to content

Commit 29c482d

Browse files
authored
Merge pull request #10 from tqsd/homework_check_eqsn
added reading out the statevector
2 parents 315ba50 + 197482f commit 29c482d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

eqsn/gates.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import numpy as np
44
from eqsn.qubit_thread import SINGLE_GATE, MERGE_SEND, MERGE_ACCEPT, MEASURE,\
5-
MEASURE_NON_DESTRUCTIVE, DOUBLE_GATE, \
5+
MEASURE_NON_DESTRUCTIVE, GIVE_STATEVECTOR, DOUBLE_GATE, \
66
CONTROLLED_GATE, NEW_QUBIT, ADD_MERGED_QUBITS_TO_DICT
77
from eqsn.shared_dict import SharedDict
88
from eqsn.worker_process import WorkerProcess
@@ -210,6 +210,13 @@ def cphase_gate(self, q_id1, q_id2):
210210
q = self.shared_dict.get_queues_for_ids([q_id1])[0]
211211
q.put([CONTROLLED_GATE, x, q_id1, q_id2])
212212

213+
def give_statevector_for(self, q_id):
214+
ret = self.manager.Queue()
215+
q = self.shared_dict.get_queues_for_ids([q_id])[0]
216+
q.put([GIVE_STATEVECTOR, q_id, ret])
217+
qubits, vector = ret.get()
218+
return qubits, vector
219+
213220
def custom_two_qubit_gate(self, q_id1, q_id2, gate):
214221
self.merge_qubits(q_id1, q_id2)
215222
q = self.shared_dict.get_queues_for_ids([q_id1])[0]

eqsn/qubit_thread.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
MEASURE_NON_DESTRUCTIVE = 7
1414
NEW_QUBIT = 8
1515
ADD_MERGED_QUBITS_TO_DICT = 9
16+
GIVE_STATEVECTOR = 10
1617
DOUBLE_GATE = 11
1718

1819

@@ -60,6 +61,9 @@ def apply_single_gate(self, mat, q_id):
6061
apply_mat = np.kron(apply_mat, np.eye(2 ** after))
6162
self.qubit = np.dot(apply_mat, self.qubit)
6263

64+
def give_statevector(self, channel):
65+
channel.put((dp(self.qubits), dp(self.qubit)))
66+
6367
def apply_controlled_gate(self, mat, q_id1, q_id2):
6468
"""
6569
Apply a controlled gate to
@@ -278,6 +282,8 @@ def run(self):
278282
return
279283
elif item[0] == MEASURE_NON_DESTRUCTIVE:
280284
self.measure_non_destructive(item[1], item[2])
285+
elif item[0] == GIVE_STATEVECTOR:
286+
self.give_statevector(item[1])
281287
elif item[0] == DOUBLE_GATE:
282288
self.apply_two_qubit_gate(item[1], item[2], item[3])
283289
else:

eqsn/worker_process.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from queue import Queue
55
from eqsn.shared_dict import SharedDict
66
from eqsn.qubit_thread import SINGLE_GATE, MERGE_SEND, MERGE_ACCEPT, MEASURE,\
7-
MEASURE_NON_DESTRUCTIVE, \
7+
MEASURE_NON_DESTRUCTIVE, GIVE_STATEVECTOR, \
88
CONTROLLED_GATE, NEW_QUBIT, ADD_MERGED_QUBITS_TO_DICT, \
99
DOUBLE_GATE, QubitThread
1010

@@ -43,6 +43,8 @@ def run(self):
4343
self.measure_non_destructive(item[1], item[2])
4444
elif item[0] == ADD_MERGED_QUBITS_TO_DICT:
4545
self.add_merged_qubits_to_thread(item[1], item[2])
46+
elif item[0] == GIVE_STATEVECTOR:
47+
self.give_statevector_for(item[1], item[2])
4648
elif item[0] == DOUBLE_GATE:
4749
self.apply_two_qubit_gate(item[1], item[2], item[3])
4850
else:
@@ -99,6 +101,10 @@ def apply_single_gate(self, gate, q_id):
99101
q = self.shared_dict.get_queues_for_ids([q_id])[0]
100102
q.put([SINGLE_GATE, gate, q_id])
101103

104+
def give_statevector_for(self, q_id, channel):
105+
q = self.shared_dict.get_queues_for_ids([q_id])[0]
106+
q.put([GIVE_STATEVECTOR, channel])
107+
102108
def apply_controlled_gate(self, gate, q_id1, q_id2):
103109
"""
104110
Applies a controlled gate, where the gate is applied to

0 commit comments

Comments
 (0)