Пример #1
0
 def construct_unitary(self) -> np.ndarray:
     return np.diag([1, 1, 1, -1]).astype(DTYPES.get('NPTYPECPX'))
Пример #2
0
 def construct_unitary(self) -> np.ndarray:
     return np.diag([1, 1, 1, np.exp(1j * self.parameter)
                     ]).astype(DTYPES.get('NPTYPECPX'))
Пример #3
0
 def reprepare(self):
     n = len(self.result)
     result = sum(2**(n - i - 1) * r for i, r in enumerate(self.result))
     self.result_tensor = tf.cast(result, dtype=DTYPES.get('DTYPEINT'))
Пример #4
0
 def _prepare(self):
     with tf.device(self.device):
         self.matrix = tf.constant(np.exp(1j * self.parameter),
                                   dtype=DTYPES.get('DTYPECPX'))
Пример #5
0
 def _prepare(self):
     with tf.device(self.device):
         self.matrix = tf.constant(self.construct_unitary(),
                                   dtype=DTYPES.get('DTYPECPX'))
Пример #6
0
 def construct_unitary(self) -> tf.Tensor:
     t = tf.cast(self.parameters, dtype=DTYPES.get('DTYPECPX'))
     phase = tf.exp(1j * t / 2.0)[tf.newaxis]
     diag = tf.concat([tf.math.conj(phase), phase], axis=0)
     return tf.linalg.diag(diag)
Пример #7
0
 def construct_unitary(self) -> np.ndarray:
     return (np.array([[1, 1], [1, -1]], dtype=DTYPES.get('NPTYPECPX')) /
             np.sqrt(2))
Пример #8
0
 def construct_unitary(self) -> np.ndarray:
     matrix = np.eye(8, dtype=DTYPES.get('NPTYPECPX'))
     matrix[-2, -2], matrix[-2, -1] = 0, 1
     matrix[-1, -2], matrix[-1, -1] = 1, 0
     return matrix
Пример #9
0
 def state_vector_call(self, state: tf.Tensor) -> tf.Tensor:
     shape = tuple(state.shape)
     _state = np.array(self.coefficients).reshape(shape)
     return tf.convert_to_tensor(_state, dtype=DTYPES.get("DTYPECPX"))
Пример #10
0
 def construct_unitary(self) -> np.ndarray:
     matrix = np.diag(
         [1 - self.preset1, self.exp_t2, self.exp_t2, 1 - self.preset0])
     matrix[0, -1] = self.preset1
     matrix[-1, 0] = self.preset0
     return matrix.astype(DTYPES.get('NPTYPECPX'))
Пример #11
0
 def construct_unitary(self) -> np.ndarray:
     phi, lam = self.parameters
     eplus = np.exp(1j * (phi + lam) / 2.0)
     eminus = np.exp(1j * (phi - lam) / 2.0)
     return np.array([[eplus.conj(), -eminus.conj()], [eminus, eplus]],
                     dtype=DTYPES.get('NPTYPECPX')) / np.sqrt(2)
Пример #12
0
 def construct_unitary(self) -> np.ndarray:
     theta = self.parameters
     cos, isin = np.cos(theta / 2.0), -1j * np.sin(theta / 2.0)
     return np.array([[cos, isin], [isin, cos]],
                     dtype=DTYPES.get('NPTYPECPX'))
Пример #13
0
 def density_matrix_call(self, state: tf.Tensor) -> tf.Tensor:
     shape = 2 * self.nqubits * (2, )
     x = tf.einsum(self.traceout, tf.reshape(state, shape))
     return tf.cast(x, dtype=DTYPES.get('DTYPE'))
Пример #14
0
 def construct_unitary(self) -> np.ndarray:
     return np.array(
         [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]],
         dtype=DTYPES.get('NPTYPECPX'))
Пример #15
0
 def construct_unitary(self) -> np.ndarray:
     return np.array([[0, -1j], [1j, 0]], dtype=DTYPES.get('NPTYPECPX'))
Пример #16
0
 def construct_unitary(self) -> np.ndarray:
     unitary, phi = self.parameter
     matrix = np.eye(4, dtype=DTYPES.get('NPTYPECPX'))
     matrix[1:3, 1:3] = np.reshape(unitary, (2, 2))
     matrix[3, 3] = np.exp(-1j * phi)
     return matrix
Пример #17
0
 def construct_unitary(self) -> np.ndarray:
     dim = 2**len(self.target_qubits)
     return np.eye(dim, dtype=DTYPES.get('NPTYPECPX'))
Пример #18
0
 def construct_unitary(self) -> np.ndarray:
     unitary = self.parameter
     if isinstance(unitary, np.ndarray):
         return unitary.astype(DTYPES.get('NPTYPECPX'))
     if isinstance(unitary, tf.Tensor):
         return tf.identity(tf.cast(unitary, dtype=DTYPES.get('DTYPECPX')))
Пример #19
0
 def construct_unitary(self) -> np.ndarray:
     cos, sin = np.cos(self.parameter / 2.0), np.sin(self.parameter / 2.0)
     return np.array([[cos, -sin], [sin, cos]],
                     dtype=DTYPES.get('NPTYPECPX'))
Пример #20
0
 def construct_unitary(self) -> tf.Tensor:
     t = tf.cast(self.parameters, dtype=DTYPES.get('DTYPECPX'))
     return tf.cos(t / 2.0) * matrices.I - 1j * tf.sin(t / 2.0) * matrices.Y
Пример #21
0
 def construct_unitary(self) -> np.ndarray:
     phase = np.exp(1j * self.parameter / 2.0)
     return np.diag([phase.conj(), phase]).astype(DTYPES.get('NPTYPECPX'))
Пример #22
0
 def construct_unitary(self) -> tf.Tensor:
     t = tf.cast(self.parameters, dtype=DTYPES.get('DTYPECPX'))
     phase = tf.exp(1j * t)
     return tf.linalg.diag([1, phase])
Пример #23
0
 def ground_state():
     n = K.cast(2 ** nqubits, dtype=DTYPES.get('DTYPEINT'))
     state = K.ones(n, dtype=DTYPES.get('DTYPECPX'))
     return state / K.math.sqrt(K.cast(n, dtype=state.dtype))