示例#1
0
文件: gates.py 项目: Doomsk/discopy
 def array(self):
     half_theta = np.pi * self.phase
     return np.array([
         1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
         np.exp(-1j * half_theta), 0, 0, 0, 0,
         np.exp(1j * half_theta)
     ])
示例#2
0
 def array(self):
     """
     >>> assert CRz(0).array[-1] == 1
     """
     phase = np.exp(1j * 2 * np.pi * self.phase)
     return np.array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, phase])
示例#3
0
 def array(self):
     half_theta = np.pi * self.phase
     global_phase = np.exp(1j * half_theta)
     sin, cos = np.sin(half_theta), np.cos(half_theta)
     return global_phase * np.array([[cos, -1j * sin], [-1j * sin, cos]])
示例#4
0
 def array(self):
     """
     >>> assert np.allclose(Rz(0.5).array, Z.array)
     """
     theta = 2 * np.pi * self.phase
     return np.array([[1, 0], [0, np.exp(1j * theta)]])
示例#5
0
                complex,
                _dagger=None if np.conjugate(complex) == complex else False)


SWAP = Gate('SWAP',
            2, [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1],
            _dagger=None)
CX = Gate('CX',
          2, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0],
          _dagger=None)
CZ = Gate('CZ',
          2, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1],
          _dagger=None)
H = Gate('H', 1, 1 / np.sqrt(2) * np.array([1, 1, 1, -1]), _dagger=None)
S = Gate('S', 1, [1, 0, 0, 1j])
T = Gate('T', 1, [1, 0, 0, np.exp(1j * np.pi / 4)])
X = Gate('X', 1, [0, 1, 1, 0], _dagger=None)
Y = Gate('Y', 1, [0, -1j, 1j, 0])
Z = Gate('Z', 1, [1, 0, 0, -1], _dagger=None)


def Euler(thetas):
    return Rx(thetas[0]) >> Rz(thetas[1]) >> Rx(thetas[2])


def Hlayer(n):
    layer = H
    for nn in range(1, n):
        layer = layer @ H
    return layer
示例#6
0
文件: gates.py 项目: Doomsk/discopy
 def array(self):
     theta = 2 * np.pi * self.phase
     return np.array(
         [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
          np.exp(1j * theta)])
示例#7
0
文件: gates.py 项目: Doomsk/discopy
 def array(self):
     half_theta = np.pi * self.phase
     return np.array([[np.exp(-1j * half_theta), 0],
                      [0, np.exp(1j * half_theta)]])
示例#8
0
文件: gates.py 项目: Doomsk/discopy
    @property
    def array(self):
        return [self.data**.5]


SWAP = Swap(qubit, qubit)
CX = QuantumGate('CX',
                 2, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0],
                 _dagger=None)
CZ = QuantumGate('CZ',
                 2, [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1],
                 _dagger=None)
H = QuantumGate('H', 1, 1 / np.sqrt(2) * np.array([1, 1, 1, -1]), _dagger=None)
S = QuantumGate('S', 1, [1, 0, 0, 1j])
T = QuantumGate('T', 1, [1, 0, 0, np.exp(1j * np.pi / 4)])
X = QuantumGate('X', 1, [0, 1, 1, 0], _dagger=None)
Y = QuantumGate('Y', 1, [0, -1j, 1j, 0])
Z = QuantumGate('Z', 1, [1, 0, 0, -1], _dagger=None)

GATES = [SWAP, CZ, CX, H, S, T, X, Y, Z]


def sqrt(expr):
    """ Returns a 0-qubit quantum gate that scales by a square root. """
    return Sqrt(expr)


def scalar(expr):
    """ Returns a 0-qubit quantum gate that scales by a complex number. """
    return Scalar(expr)
示例#9
0
 def array(self):
     phase = np.exp(1j * 2 * np.pi * self.phase)
     return np.array([1, 0, 0, 0,
                      0, 1, 0, 0,
                      0, 0, 1, 0,
                      0, 0, 0, phase])