def identity(cls, space): if type(space) is int: n = space space = Space((n, n), 'ud') A = cls(space.shape) assert space.is_square(), space for i in range(space.shape[0]): A[i, i] = 1. return A
def random_hermitian(cls, space): if type(space) is int: n = space space = Space((n, n), 'ud') assert space.is_square() A = Qu.random(space.shape, space.valence) A = A.dag() * A A = Gate.promote(A) return A
def random_unitary(cls, space): vs = [] if type(space) is int: n = space space = Space((n, n), 'ud') assert space.is_square() n = space.shape[0] U = Gate(space.shape) for i in range(n): v = Qu.random(n, 'u') for u in vs: r = u.dag() * v v -= r * u #assert abs((u.transpose() * v)) < 1e-10 v.normalize() vs.append(v) U[i, :] = v return U