quimb.gen.rand¶
Functions for generating random quantum objects and states.
Attributes¶
Classes¶
Private object that handles pool of random number generators for |
Functions¶
|
See the random number generators, by instantiating a new set of bit |
|
Set the core bit generator type to use, from either |
|
|
|
Fast multithreaded generation of random normally distributed data. |
|
|
|
Modify |
|
|
|
|
|
|
|
Generate random complex numbers distributed on the unit sphere. |
|
Get a callable with the given random distribution and parameters, that |
|
Generate a random matrix of order d with normally distributed |
|
Generate a random hermitian operator of order d with normally |
|
Generate a random positive operator of size d, with normally |
|
Generate a random positive operator of size d with normally |
|
Generate a random unitary operator of size d, distributed according to |
|
Generates a ket of length d with normally distributed entries. |
|
Generate a random state of dimension d according to the Haar |
|
Generate many random Haar states, recycling a random unitary operator |
|
Constructs a random mixed state by tracing out a random ket |
|
Generates a ket of n many random pure qubits. |
|
Generate a random matrix product state (in dense form, see |
|
Generate a random, mixed, seperable state. E.g rand_seperable([2, 2]) |
|
Generate a random isometry of shape |
|
Generate a random mera state of |
Module Contents¶
- class quimb.gen.rand._RGenHandler(initial_seed=None, initial_bitgen=None)[source]¶
Private object that handles pool of random number generators for parallel number generation - seeding them & changing the underlying bit generators.
- rgs = []¶
- set_bitgen(bitgen)[source]¶
Set the core underlying bit-generator.
- Parameters:
bitgen ({None, str}) – Which bit generator to use, either from numpy or randomgen - https://bashtage.github.io/randomgen/bit_generators/index.html.
- set_seed(seed=None)[source]¶
Set the seed for the bit generators.
- Parameters:
seed ({None, int}, optional) – Seed supplied to numpy.random.SeedSequence. None will randomly the generators (default).
- get_rgens(num_threads)[source]¶
Get a list of the
numpy.random.Generator
instances, having made sure there are at leastnum_threads
.- Parameters:
num_threads (int) – The number of generators to return.
- Return type:
- quimb.gen.rand._RG_HANDLER¶
- quimb.gen.rand.seed_rand(seed)[source]¶
See the random number generators, by instantiating a new set of bit generators with a ‘seed sequence’.
- quimb.gen.rand.set_rand_bitgen(bitgen)[source]¶
Set the core bit generator type to use, from either
numpy
orrandomgen
.- Parameters:
bitgen ({'PCG64', 'SFC64', 'MT19937', 'Philox', str}) – Which bit generator to use.
- quimb.gen.rand.randn(shape=(), dtype=float, scale=1.0, loc=0.0, num_threads=None, seed=None, dist='normal')[source]¶
Fast multithreaded generation of random normally distributed data.
- Parameters:
dtype ({'complex128', 'float64', 'complex64' 'float32'}, optional) – The data-type of the output array.
scale (float, optional) – A multiplicative scale for the random numbers.
loc (float, optional) – An additive location for the random numbers.
num_threads (int, optional) – How many threads to use. If
None
, decide automatically.dist ({'normal', 'uniform', 'rademacher', 'exp'}, optional) – Type of random number to generate.
- quimb.gen.rand.random_seed_fn(fn)[source]¶
Modify
fn
to take aseed
argument (so as to seed the random generators once-only at beginning of function not everyrandn
call).
- quimb.gen.rand.rand_phase(shape, scale=1, dtype=complex)[source]¶
Generate random complex numbers distributed on the unit sphere.
- quimb.gen.rand.get_rand_fill_fn(dist='normal', loc=0.0, scale=1.0, seed=None, dtype='float64')[source]¶
Get a callable with the given random distribution and parameters, that has signature
fill_fn(shape) -> array
.- Parameters:
dist ({'normal', 'uniform', 'rademacher', 'exp'}, optional) – Type of random number to generate, defaults to ‘normal’.
loc (float, optional) – An additive offset to add to the random numbers.
scale (float, optional) – A multiplicative factor to scale the random numbers by.
seed (int, optional) – A random seed.
dtype ({'float64', 'complex128', 'float32', 'complex64'}, optional) – The underlying data type.
- Return type:
callable
- quimb.gen.rand.rand_matrix(d, scaled=True, sparse=False, stype='csr', density=None, dtype=complex, seed=None)[source]¶
Generate a random matrix of order d with normally distributed entries. If scaled is True, then in the limit of large d the eigenvalues will be distributed on the unit complex disk.
- Parameters:
d (int) – Matrix dimension.
scaled (bool, optional) – Whether to scale the matrices values such that its spectrum approximately lies on the unit disk (for dense matrices).
sparse (bool, optional) – Whether to produce a sparse matrix.
stype ({'csr', 'csc', 'coo', ...}, optional) – The type of sparse matrix if
sparse=True
.density (float, optional) – Target density of non-zero elements for the sparse matrix. By default aims for about 10 entries per row.
dtype ({complex, float}, optional) – The data type of the matrix elements.
- Returns:
mat – Random matrix.
- Return type:
qarray or sparse matrix
- quimb.gen.rand.rand_herm(d, sparse=False, density=None, dtype=complex)[source]¶
Generate a random hermitian operator of order d with normally distributed entries. In the limit of large d the spectrum will be a semi-circular distribution between [-1, 1].
See also
- quimb.gen.rand.rand_pos(d, sparse=False, density=None, dtype=complex)[source]¶
Generate a random positive operator of size d, with normally distributed entries. In the limit of large d the spectrum will lie between [0, 1].
See also
- quimb.gen.rand.rand_rho(d, sparse=False, density=None, dtype=complex)[source]¶
Generate a random positive operator of size d with normally distributed entries and unit trace.
See also
- quimb.gen.rand.rand_uni(d, dtype=complex)[source]¶
Generate a random unitary operator of size d, distributed according to the Haar measure.
See also
- quimb.gen.rand.rand_ket(d, sparse=False, stype='csr', density=0.01, dtype=complex)[source]¶
Generates a ket of length d with normally distributed entries.
- quimb.gen.rand.rand_haar_state(d, dtype=complex)[source]¶
Generate a random state of dimension d according to the Haar distribution.
- quimb.gen.rand.gen_rand_haar_states(d, reps, dtype=complex)[source]¶
Generate many random Haar states, recycling a random unitary operator by using all of its columns (not a good idea?).
- quimb.gen.rand.rand_mix(d, tr_d_min=None, tr_d_max=None, mode='rand', dtype=complex)[source]¶
Constructs a random mixed state by tracing out a random ket where the composite system varies in size between 2 and d. This produces a spread of states including more purity but has no real meaning.
- quimb.gen.rand.rand_product_state(n, qtype=None, dtype=complex)[source]¶
Generates a ket of n many random pure qubits.
- quimb.gen.rand.rand_matrix_product_state(n, bond_dim, phys_dim=2, dtype=complex, cyclic=False, trans_invar=False)[source]¶
Generate a random matrix product state (in dense form, see
MPS_rand_state()
for tensor network form).- Parameters:
n (int) – Number of sites.
bond_dim (int) – Dimension of the bond (virtual) indices.
phys_dim (int, optional) – Physical dimension of each local site, defaults to 2 (qubits).
cyclic (bool (optional)) – Whether to impose cyclic boundary conditions on the entanglement structure.
trans_invar (bool (optional)) – Whether to generate a translationally invariant state, requires cyclic=True.
- Returns:
ket – The random state, with shape (phys_dim**n, 1)
- Return type: