-
Notifications
You must be signed in to change notification settings - Fork 8
/
grover_mixer.py
35 lines (29 loc) · 1.2 KB
/
grover_mixer.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
from qiskit.circuit import Parameter
from qiskit.circuit.library import PhaseGate
from qaoa.mixers.base_mixer import Mixer
from qaoa.initialstates.base_initialstate import InitialState
class Grover(Mixer):
def __init__(self, subcircuit: InitialState) -> None:
"""
Args:
subcircuit (InitialState): the circuit that is to be tensorised
"""
self.subcircuit = subcircuit
self.mixer_param = Parameter("x_beta")
def create_circuit(self):
# given feasibel states f \in F,
# Let US the circuit that prepares US = 1/|F| \sum_{f\inF} |f>
# The Grover mixer has the form US^\dagger X^n C^{n-1}Phase X^n US,
self.subcircuit.create_circuit()
US = self.subcircuit.circuit
# US^\dagger
self.circuit = US.inverse()
# X^n
self.circuit.x(range(self.subcircuit.N_qubits))
# C^{n-1}Phase
phase_gate = PhaseGate(-self.mixer_param).control(self.subcircuit.N_qubits - 1)
self.circuit.append(phase_gate, self.circuit.qubits)
# X^n
self.circuit.x(range(self.subcircuit.N_qubits))
# US
self.circuit.compose(US, range(self.subcircuit.N_qubits), inplace=True)