Commit 1a037c9b authored by Tobias Hangleiter's avatar Tobias Hangleiter
Browse files

Add random module

We could add functions that uniformly sample the bloch sphere, randomly
generate unitaries, etc.
parent 2f7743e7
......@@ -35,3 +35,6 @@ for i in qutil.ui.progressbar(range(n)):
## qutil.qi
In this module there are some quantities and functions related to quantum information, like the Pauli matrices in different data types.
## qutil.random
Here we collect functions for random numbers like `random_hermitian` to generate random Hermitian matrices.
from . import const, linalg, matlab, plotting, ui, qi
from . import const, linalg, matlab, plotting, ui, qi, random
__version__ = '0.1'
__all__ = ['const', 'linalg', 'matlab', 'ui', 'plotting', 'qi']
__all__ = ['const', 'linalg', 'matlab', 'ui', 'plotting', 'qi', 'random']
"""
This module contains random functions
"""
import numpy as np
from numpy import ndarray
def random_hermitian(d: int = 2, n: int = 1, std: float = 1,
mean: float = 0) -> ndarray:
r"""
Generate *n* random Hermitian matrices of dimension *d* drawn from a
Gaussian ensemble :math:`~\mathcal{N}(\mu, \sigma^2)`.
"""
H_ii = np.random.randn(n, d)*std
H_ij = np.random.randn(2, n, (d**2 - d)//2)*std/np.sqrt(2)
H = np.empty((n, d, d), dtype=complex)
H[:, range(d), range(d)] = H_ii
H[:, ~np.tri(d, k=0, dtype=bool)] = H_ij[0] + 1j*H_ij[1]
H[:, np.tri(d, k=-1, dtype=bool)] = H_ij[0] - 1j*H_ij[1]
return H.squeeze() + mean
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment