-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmachine_state.py
56 lines (49 loc) · 1.9 KB
/
machine_state.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
This class is used to represent a snapshot of machine state and manipulate that state
Machine state at a given point is
which qubits are sitting in which traps --> self.trap_ions
which qubits are sitting in which segments --> self.seg_ions
'''
from utils import *
class MachineState:
def __init__(self, ts, trap_ions, seg_ions):
self.ts = ts #timestamp
self.trap_ions = trap_ions
self.seg_ions = seg_ions
#Given a trap and a connected segment, and a set of ions in this trap,
#remove ions from the trap and add it to the segment
#analogous operations in merge and move
def process_split(self, trap, seg, ions):
if not seg in self.seg_ions:
self.seg_ions[seg] = []
for ion in ions:
self.trap_ions[trap].remove(ion)
self.seg_ions[seg].append(ion)
def process_merge(self, trap, seg, ions):
if not trap in self.trap_ions:
self.trap_ions[trap] = []
for ion in ions:
self.trap_ions[trap].append(ion)
self.seg_ions[seg].remove(ion)
def process_move(self, seg1, seg2, ions):
if not seg2 in self.seg_ions:
self.seg_ions[seg2] = []
for ion in ions:
self.seg_ions[seg1].remove(ion)
self.seg_ions[seg2].append(ion)
def find_trap_id_by_ion(self, ion_id):
for trap_id in self.trap_ions.keys():
if ion_id in self.trap_ions[trap_id]:
return trap_id
return -1
def check_ion_in_a_trap(self, ion_id):
if self.find_trap_id_by_ion(ion_id) != -1:
return 1
else:
return 0
def print_state(self):
print("Machine State")
for t in self.trap_ions.keys():
print(trap_name(t), len(self.trap_ions[t]), self.trap_ions[t])
#for s in self.seg_ions.keys():
# print(seg_name(s), len(self.seg_ions[s]), self.seg_ions[s])