-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubspace.sage
77 lines (61 loc) · 1.77 KB
/
Subspace.sage
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class Subspace(SpaceCommon):
"""
Represents hilbert space subspace
"""
def __init__(self, index, space):
self.index = index
self.space = space
self.states = []
def AddState(self, state):
"""
Adds state to list of states
"""
state.SetSubspace(self)
self.states.append(state)
def Colors(self):
"""
Returns list of colors, one color for one state
"""
return rainbow(self.Size())
def GetBlock(self, A):
"""
Returns subspace block of A in exc basis
"""
I = J = self.StatesIndices()
return A[I, J]
def GetFull(self, B):
"""
Returns full matrix A given subspace block of A
Sets all elements of A to zero except elements in block B
"""
A = matrix(B.base_ring(), self.space.Size())
I = J = self.StatesIndices()
A[I, J] = B
return A
def Index(self, state):
"""
Returns index of state within its subspace
"""
return self.states.index(state)
def partial_trace_sink11(self, rho):
"""
Returns rho_sink[1,1]
"""
s = 0
for state in self.states:
if state.index % 2: # sink bit is set
i = state.SubspaceIndex()
s += rho[i, i]
return abs(s)
def Show(self):
"""
Shows states
"""
header = ['index_subspace', 'index_e', 'index']
header.extend(self.space.BitsHeader())
rows = []
for state in self.states:
row = [state.SubspaceIndex(), state.TransformedIndex(), state.index]
row.extend(state.Bits())
rows.append(row)
html.table(rows, header = header)