-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathdicke_initialstate.py
More file actions
183 lines (137 loc) · 4.96 KB
/
dicke_initialstate.py
File metadata and controls
183 lines (137 loc) · 4.96 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
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):
"""
Dicke initial state.
Subclass of the `InitialState` class. Creates a circuit representing a Dicke state with Hamming weight k.
Attributes:
k (int): The Hamming weight of the Dicke states.
N_qubits (int): The number of qubits in the register (>= k).
Methods:
create_circuit(): Creates the circuit to prepare the Dicke states.
"""
def __init__(self, k: int, N: int | None = None, label: str | None = None) -> None:
"""
Args:
k (int): The Hamming weight of the Dicke states.
N (int | None): The number of qubits in the register. Must be
>= k. When omitted, defaults to k (the minimum register
needed for k excitations). Can still be overridden later
via ``setNumQubits()``.
label (str | None): Optional annotation label. Defaults to
``"Dicke"``.
"""
super().__init__(label=label)
self.k = k
self.N_qubits = N if N is not None else 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