-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstates.py
68 lines (61 loc) · 1.93 KB
/
states.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
57
58
59
60
61
62
63
64
65
66
67
68
#Define functions to generate various sets of states
from util import *
from unitaries import *
#Uniformly-random product states
def pauli_product_states(N,n):
D = []
for i in range(N):
rho = [1]
indices = np.random.randint(0,6,n)
for i in range(n):
rho = np.kron(rho,pauli_states[indices[i]])
D.append(rho)
return D
#Maximally mixed state
def max_mixed_state(n):
return np.eye(2**n)/2**n
#GHZ State
def ghz_state(n):
rho = np.zeros((2**n,2**n), dtype = complex)
rho[0][0] = rho[2**n-1][2**n-1] = rho[2**n-1][0] = rho[0][2**n-1] = 0.5
return rho
#Haar-random states
def haar_states(N,n):
D = []
zero_state = np.zeros((2**n,2**n))
zero_state[0,0] = 1
for i in range(N):
haar = haar_unitary(2**n)
rho = haar @ zero_state @ haar.conjugate().transpose()
D.append(rho)
return D
#All n-qubit computational basis states
def classical_states(n):
D = []
for i in range(2**n):
rho = np.zeros((2**n,2**n),dtype = complex)
rho[i,i] = 1
D.append(rho)
return D
#LWE Sample states -> 1/(root(q^n)) \Sum (|a>|a.s+e_a>)
def lwe_samples(num_states, s , n , q, error_distr):
# (n+1)-qudit states
# a.s + e_a
states = []
for i in range(num_states):
statevector = np.zeros(q**(n+1), dtype = complex)
for input in range(q**n):
inp = input
a = np.zeros(n, dtype = int)
for index in range(n):
a[-index] = inp%q
inp = int(inp%q)
dot = 0
for index in range(n):
dot += int(s[index])*a[index]
out = (dot + np.random.choice(range(q),p = error_distr))%q
state = input*q+out
statevector[state] = 1
statevector/= np.sqrt(q**n)
states.append(statevector)
return density_matrix(states)