-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathxy_mixer.py
40 lines (28 loc) · 1.07 KB
/
xy_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
36
37
38
39
40
from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit import Parameter
from qiskit.circuit.library import XXPlusYYGate
from .base_mixer import Mixer
import math
import itertools
import numpy as np
class XY(Mixer):
def __init__(self, topology=None) -> None:
self.topology = topology
self.mixer_param = Parameter("x_beta")
def create_circuit(self):
if not self.topology:
print('No topology specified for the XY-mixer, assuming "ring" topology')
self.topology = XY.generate_pairs(self.N_qubits)
q = QuantumRegister(self.N_qubits)
self.circuit = QuantumCircuit(q)
for i, e in enumerate(self.topology):
self.circuit.append(XXPlusYYGate(0.5 * self.mixer_param), e)
@staticmethod
def generate_pairs(n, case="ring"):
# default ring, otherwise "chain"
if n < 2:
return [] # Not enough elements to form any pairs
pairs = [[i, i + 1] for i in range(n - 1)]
if case == "ring":
pairs.append([n - 1, 0])
return pairs