def proj(self, u, vec): """Returns projection of vectors on a tangen space of the manifold. Args: u: complex valued tensor of shape (..., n, r), a set of points from the manifold. vec: complex valued tensor of shape (..., n, r), a set of vectors to be projected. Returns: complex valued tensor of shape (..., n, r), a set of projected vectors. Note: The complexity is O(nr^2).""" # projection onto the tangent space of ||u||_F = 1 vec_proj = vec - u * tf.reduce_sum( tf.math.conj(u) * vec, axis=(-2, -1))[..., tf.newaxis, tf.newaxis] # projection onto the horizontal space uu = adj(u) @ u Omega = lyap_symmetric(uu, adj(u) @ vec_proj - adj(vec_proj) @ u) return vec_proj - u @ Omega
def proj(self, u, vec): """Returns projection of vectors on a tangen space of the manifold. Args: u: complex valued tensor of shape (..., n ** 2, k), a set of points from the manifold. vec: complex valued tensor of shape (..., n ** 2, k), a set of vectors to be projected. Returns: complex valued tensor of shape (..., n ** 2, k), a set of projected vectors.""" k = u.shape[-1] n = int(math.sqrt(u.shape[-2])) shape = u.shape[:-2] # projection onto the tangent space of the Stiefel manifold vec_mod = tf.reshape(vec, shape + (n, k * n)) vec_mod = tf.linalg.matrix_transpose(vec_mod) u_mod = tf.reshape(u, shape + (n, k * n)) u_mod = tf.linalg.matrix_transpose(u_mod) vec_mod = vec_mod - 0.5 * u_mod @ (adj(u_mod) @ vec_mod +\ adj(vec_mod) @ u_mod) vec_mod = tf.linalg.matrix_transpose(vec_mod) vec_mod = tf.reshape(vec_mod, shape + (n ** 2, k)) # projection onto the horizontal space uu = adj(u) @ u Omega = lyap_symmetric(uu, adj(u) @ vec_mod - adj(vec_mod) @ u) return vec_mod - u @ Omega
def proj(self, u, vec): """Returns projection of vectors on a tangen space of the manifold. Args: u: complex valued tensor of shape (..., m, n, n), a set of points from the manifold. vec: complex valued tensor of shape (..., m, n, n), a set of vectors to be projected. Returns: complex valued tensor of shape (..., m, n, n), a set of projected vectors. Note: The complexity is O(mn^3).""" n = tf.shape(u)[-1] m = tf.shape(u)[-3] shape = tf.shape(u)[:-3] size = tf.size(shape) idx = tf.range(size) # projection onto the tangent space of the Stiefel manifold vec_mod = tf.transpose( vec, shape_conc(idx, (size + 2)[tf.newaxis], size[tf.newaxis], (size + 1)[tf.newaxis])) vec_mod = tf.reshape( vec_mod, shape_conc(shape, (n * m)[tf.newaxis], n[tf.newaxis])) u_mod = tf.transpose( u, shape_conc(idx, (size + 2)[tf.newaxis], size[tf.newaxis], (size + 1)[tf.newaxis])) u_mod = tf.reshape( u_mod, shape_conc(shape, (n * m)[tf.newaxis], n[tf.newaxis])) vec_mod = vec_mod - 0.5 * u_mod @ (adj(u_mod) @ vec_mod +\ adj(vec_mod) @ u_mod) vec_mod = tf.reshape( vec_mod, shape_conc(shape, n[tf.newaxis], m[tf.newaxis], n[tf.newaxis])) vec_mod = tf.transpose( vec_mod, shape_conc(idx, (size + 1)[tf.newaxis], (size + 2)[tf.newaxis], size[tf.newaxis])) # projection onto the horizontal space (POVM element-wise) uu = adj(u) @ u Omega = lyap_symmetric(uu, adj(u) @ vec_mod - adj(vec_mod) @ u) return vec_mod - u @ Omega
def proj(self, u, vec): """Returns projection of vectors on a tangen space of the manifold. Args: u: complex valued tensor of shape (..., n ** 2, k), a set of points from the manifold. vec: complex valued tensor of shape (..., n ** 2, k), a set of vectors to be projected. Returns: complex valued tensor of shape (..., n ** 2, k), a set of projected vectors. Note: The complexity O(kn^3+k^2n^2)""" k = tf.shape(u)[-1] n = tf.cast(tf.math.sqrt(tf.cast(tf.shape(u)[-2], dtype=tf.float32)), dtype=tf.int32) shape = tf.shape(u)[:-2] # projection onto the tangent space of the Stiefel manifold vec_mod = tf.reshape( vec, shape_conc(shape, n[tf.newaxis], (k * n)[tf.newaxis])) vec_mod = tf.linalg.matrix_transpose(vec_mod) u_mod = tf.reshape( u, shape_conc(shape, n[tf.newaxis], (k * n)[tf.newaxis])) u_mod = tf.linalg.matrix_transpose(u_mod) vec_mod = vec_mod - 0.5 * u_mod @ (adj(u_mod) @ vec_mod +\ adj(vec_mod) @ u_mod) vec_mod = tf.linalg.matrix_transpose(vec_mod) vec_mod = tf.reshape( vec_mod, shape_conc(shape, (n**2)[tf.newaxis], k[tf.newaxis])) # projection onto the horizontal space uu = adj(u) @ u Omega = lyap_symmetric(uu, adj(u) @ vec_mod - adj(vec_mod) @ u) return vec_mod - u @ Omega
def proj(self, u, vec): """Returns projection of vectors on a tangen space of the manifold. Args: u: complex valued tensor of shape (..., n, n), a set of points from the manifold. vec: complex valued tensor of shape (..., n, n), a set of vectors to be projected. Returns: complex valued tensor of shape (..., n, n), a set of projected vectors""" # projection onto the tangent space of ||u||_F = 1 vec_proj = vec - u * tf.linalg.trace(adj(u) @ vec)[..., tf.newaxis, tf.newaxis] # projection onto the horizontal space uu = adj(u) @ u Omega = lyap_symmetric(uu, adj(u) @ vec_proj - adj(vec_proj) @ u) return vec_proj - u @ Omega
def proj(self, u, vec): """Returns projection of vectors on a tangen space of the manifold. Args: u: complex valued tensor of shape (..., m, n, n), a set of points from the manifold. vec: complex valued tensor of shape (..., m, n, n), a set of vectors to be projected. Returns: complex valued tensor of shape (..., m, n, n), a set of projected vectors.""" n = u.shape[-1] m = u.shape[-3] shape = u.shape[:-3] size = len(shape) idx = tuple(range(size)) # projection onto the tangent space of the Stiefel manifold vec_mod = tf.transpose(vec, idx + (size + 2, size, size + 1)) vec_mod = tf.reshape(vec_mod, shape + (n * m, n)) u_mod = tf.transpose(u, idx + (size + 2, size, size + 1)) u_mod = tf.reshape(u_mod, shape + (n * m, n)) vec_mod = vec_mod - 0.5 * u_mod @ (adj(u_mod) @ vec_mod +\ adj(vec_mod) @ u_mod) vec_mod = tf.reshape(vec_mod, shape + (n, m, n)) vec_mod = tf.transpose(vec_mod, idx + (size + 1, size + 2, size)) # projection onto the horizontal space (POVM element-wise) uu = adj(u) @ u Omega = lyap_symmetric(uu, adj(u) @ vec_mod - adj(vec_mod) @ u) return vec_mod - u @ Omega