import torch


def init_state(scope="session"):
    """Generates a random initial state"""

    def _init_state(n, torch_device):
        """random initial state"""
        torch.manual_seed(42)
        state = torch.rand([2**n], dtype=torch.complex128) + torch.rand([2**n]) * 1j
        state /= torch.linalg.norm(state)
        return state.to(torch_device)

    return _init_state