Skip to content

Commit 761bf60

Browse files
committed
added reading out the statevector
1 parent 7b21e55 commit 761bf60

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, \
5+
MEASURE_NON_DESTRUCTIVE, GIVE_STATEVECTOR, \
66
CONTROLLED_GATE, NEW_QUBIT, ADD_MERGED_QUBITS_TO_DICT
77
from eqsn.shared_dict import SharedDict
88
from eqsn.worker_process import WorkerProcess
@@ -203,6 +203,13 @@ def cphase_gate(self, q_id1, q_id2):
203203
q = self.shared_dict.get_queues_for_ids([q_id1])[0]
204204
q.put([CONTROLLED_GATE, x, q_id1, q_id2])
205205

206+
def give_statevector_for(self, q_id):
207+
ret = self.manager.Queue()
208+
q = self.shared_dict.get_queues_for_ids([q_id])[0]
209+
q.put([GIVE_STATEVECTOR, q_id, ret])
210+
qubits, vector = ret.get()
211+
return qubits, vector
212+
206213
def measure(self, q_id, non_destructive=False):
207214
"""
208215
Measures a qubit with an id. If non_destructive is False, the qubit

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

1718

1819
class QubitThread(object):
@@ -59,6 +60,9 @@ def apply_single_gate(self, mat, q_id):
5960
apply_mat = np.kron(apply_mat, np.eye(2 ** after))
6061
self.qubit = np.dot(apply_mat, self.qubit)
6162

63+
def give_statevector(self, channel):
64+
channel.put((dp(self.qubits), dp(self.qubit)))
65+
6266
def apply_controlled_gate(self, mat, q_id1, q_id2):
6367
"""
6468
Apply a controlled gate to
@@ -235,5 +239,7 @@ def run(self):
235239
return
236240
elif item[0] == MEASURE_NON_DESTRUCTIVE:
237241
self.measure_non_destructive(item[1], item[2])
242+
elif item[0] == GIVE_STATEVECTOR:
243+
self.give_statevector(item[1])
238244
else:
239245
raise ValueError("Command does not exist!")

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, QubitThread
99

1010

@@ -42,6 +42,8 @@ def run(self):
4242
self.measure_non_destructive(item[1], item[2])
4343
elif item[0] == ADD_MERGED_QUBITS_TO_DICT:
4444
self.add_merged_qubits_to_thread(item[1], item[2])
45+
elif item[0] == GIVE_STATEVECTOR:
46+
self.give_statevector_for(item[1], item[2])
4547
else:
4648
raise ValueError("Command does not exist!")
4749

@@ -91,6 +93,10 @@ def apply_single_gate(self, gate, q_id):
9193
q = self.shared_dict.get_queues_for_ids([q_id])[0]
9294
q.put([SINGLE_GATE, gate, q_id])
9395

96+
def give_statevector_for(self, q_id, channel):
97+
q = self.shared_dict.get_queues_for_ids([q_id])[0]
98+
q.put([GIVE_STATEVECTOR, channel])
99+
94100
def apply_controlled_gate(self, gate, q_id1, q_id2):
95101
"""
96102
Applies a controlled gate, where the gate is applied to

0 commit comments

Comments
 (0)