def create_pieces(self): """Creates :class:`qibo.core.states.DistributedState` pieces on CPU.""" n = 2**self.nlocal with K.on_cpu(): self.pieces = [ K.cpu_tensor(K.zeros(n)) for _ in range(self.ndevices) ]
def zero_state(cls, circuit): """Creates ``|00...0>`` as a distributed state.""" state = cls(circuit) state.create_pieces() with K.on_cpu(): piece = K.initial_state(nqubits=state.nlocal) state.pieces[0] = K.cpu_tensor(piece, dtype=state.dtype) return state
def plus_state(cls, circuit): """Creates ``|++...+>`` as a distributed state.""" state = cls(circuit) with K.on_cpu(): n = K.cast(2**state.nlocal, dtype=K.dtypes('DTYPEINT')) norm = K.cast(2**float(state.nqubits / 2.0)) state.pieces = [ K.cpu_tensor(K.ones(n) / norm) for _ in range(state.ndevices) ] return state