-
Notifications
You must be signed in to change notification settings - Fork 8
/
dicke_initialstate.py
164 lines (121 loc) · 4.12 KB
/
dicke_initialstate.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import numpy as np
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit import Parameter
from qiskit.circuit.library import RYGate
from .base_initialstate import InitialState
class Dicke(InitialState):
def __init__(self, k) -> None:
"""
Args:
k (int): The Hamming weight of the Dicke states.
"""
super().__init__()
self.k = k
def create_circuit(self):
"""
Circuit to prepare Dicke states, following the algorithm from https://arxiv.org/pdf/1904.07358.pdf.
"""
q = QuantumRegister(self.N_qubits)
self.circuit = QuantumCircuit(q)
self.circuit.x(q[-self.k :])
for l in range(self.k + 1, self.N_qubits + 1)[::-1]:
self.circuit.append(
Dicke.getBlock1(self.N_qubits, self.k, l), range(self.N_qubits)
)
for l in range(2, self.k + 1)[::-1]:
self.circuit.append(
Dicke.getBlock2(self.N_qubits, self.k, l), range(self.N_qubits)
)
@staticmethod
def getRYi(n):
"""
Returns gate (i) from section 2.2.
Args:
n (int): The integer parameter for gate (i).
Returns:
QuantumCircuit: Quantum circuit representing gate (i).
"""
qc = QuantumCircuit(2)
qc.cx(0, 1)
theta = 2 * np.arccos(np.sqrt(1 / n))
ry = RYGate(theta).control(ctrl_state="1")
qc.append(ry, [1, 0])
qc.cx(0, 1)
return qc
@staticmethod
def getRYii(l, n):
"""
Returns gate (ii)_l from section 2.2.
Args:
l (int): The integer parameter for gate (ii)_l.
n (int): The integer parameter for gate (ii)_l.
Returns:
QuantumCircuit: Quantum circuit representing gate (ii)_l.
"""
qc = QuantumCircuit(3)
qc.cx(0, 2)
theta = 2 * np.arccos(np.sqrt(l / n))
ry = RYGate(theta).control(num_ctrl_qubits=2, ctrl_state="11")
qc.append(ry, [2, 1, 0])
qc.cx(0, 2)
return qc
@staticmethod
def getSCS(n, k):
"""
Returns SCS_{n,k} gate from definition 3.
Args:
n (int): The integer parameter for SCS_{n,k}.
k (int): The integer parameter for SCS_{n,k}.
Returns:
QuantumCircuit: Quantum circuit representing SCS_{n,k}.
"""
qc = QuantumCircuit(k + 1)
qc.append(Dicke.getRYi(n), [k - 1, k])
for l in range(2, k + 1):
qc.append(Dicke.getRYii(l, n), [k - l, k - l + 1, k])
return qc
@staticmethod
def getBlock1(n, k, l):
"""
Returns the first block in Lemma 2.
Args:
n (int): The integer parameter for the quantum register size.
k (int): The integer parameter for the Hamming weight.
l (int): The integer parameter for the block.
Returns:
QuantumCircuit: Quantum circuit representing the first block in Lemma 2.
"""
qr = QuantumRegister(n)
qc = QuantumCircuit(qr)
first = l - k - 1
last = n - l
index = list(range(n))
if first != 0:
index = index[first:]
if last != 0:
index = index[:-last]
qc.append(Dicke.getSCS(l, k), index)
else:
qc.append(Dicke.getSCS(l, k), index)
return qc
@staticmethod
def getBlock2(n, k, l):
"""
Returns the second block from Lemma 2.
Args:
n (int): The integer parameter for the quantum register size.
k (int): The integer parameter for the Hamming weight.
l (int): The integer parameter for the block.
Returns:
QuantumCircuit: Quantum circuit representing the second block in Lemma 2.
"""
qr = QuantumRegister(n)
qc = QuantumCircuit(qr)
last = n - l
index = list(range(n))
if last != 0:
index = index[:-last]
qc.append(Dicke.getSCS(l, l - 1), index)
else:
qc.append(Dicke.getSCS(l, l - 1), index)
return qc