Esempio n. 1
0
 def construct_unitary(self) -> np.ndarray:
     return np.diag([1, 1, 1, -1]).astype(DTYPES.get('NPTYPECPX'))
Esempio n. 2
0
 def construct_unitary(self) -> np.ndarray:
     return np.diag([1, 1, 1, np.exp(1j * self.parameter)
                     ]).astype(DTYPES.get('NPTYPECPX'))
Esempio n. 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'))
Esempio n. 4
0
 def _prepare(self):
     with tf.device(self.device):
         self.matrix = tf.constant(np.exp(1j * self.parameter),
                                   dtype=DTYPES.get('DTYPECPX'))
Esempio n. 5
0
 def _prepare(self):
     with tf.device(self.device):
         self.matrix = tf.constant(self.construct_unitary(),
                                   dtype=DTYPES.get('DTYPECPX'))
Esempio n. 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)
Esempio n. 7
0
 def construct_unitary(self) -> np.ndarray:
     return (np.array([[1, 1], [1, -1]], dtype=DTYPES.get('NPTYPECPX')) /
             np.sqrt(2))
Esempio n. 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
Esempio n. 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"))
Esempio n. 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'))
Esempio n. 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)
Esempio n. 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'))
Esempio n. 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'))
Esempio n. 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'))
Esempio n. 15
0
 def construct_unitary(self) -> np.ndarray:
     return np.array([[0, -1j], [1j, 0]], dtype=DTYPES.get('NPTYPECPX'))
Esempio n. 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
Esempio n. 17
0
 def construct_unitary(self) -> np.ndarray:
     dim = 2**len(self.target_qubits)
     return np.eye(dim, dtype=DTYPES.get('NPTYPECPX'))
Esempio n. 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')))
Esempio n. 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'))
Esempio n. 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
Esempio n. 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'))
Esempio n. 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])
Esempio n. 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))