From 5ef92f78de4a2a675339dde43ec7b9aac6a4500b Mon Sep 17 00:00:00 2001 From: Balthazar Casale <balthazar.casale@lis-lab.fr> Date: Thu, 8 Jun 2023 16:02:37 +0200 Subject: [PATCH] Upload New File --- src/samplers/pure.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/samplers/pure.py diff --git a/src/samplers/pure.py b/src/samplers/pure.py new file mode 100644 index 0000000..92a01cb --- /dev/null +++ b/src/samplers/pure.py @@ -0,0 +1,37 @@ +""" +Contain method to sample pure quantum states +""" + +import numpy as np + +from .utils import RandomGinibre, kron, dagger + +class RandomHaar : + """ + Random density matrices sampled from the Haar measure + """ + def __init__(self, product=False): + """ + :param product: if True, the matrices will be of the form A \otimes B + where A, B sampled from the Haar measure + """ + self.product = product + + def states(self, n_states, dims): + """ + sample states from the Haar measure + :param n_states: number of states + :param dims: dimensions of the subsystems + :return: a set of random states (DMStack), a information dictionary (empty) + """ + if self.product : + s1, _ = RandomHaar().states(n_states, [dims[0]]) + s2, _ = RandomHaar().states(n_states, [dims[1]]) + return kron(s1, s2), {} + else : + dim = np.product(dims) + states = RandomGinibre.matrices(n_states, [dim, 1]) + states = states @ dagger(states) + states /= np.trace(states, axis1=1, axis2=2)[:,None,None] + + return states, {} \ No newline at end of file -- GitLab