quimb.gen.rand

Functions for generating random quantum objects and states.

Functions

choice(*args, **kwargs)

gen_rand_haar_states(d, reps[, dtype])

Generate many random Haar states, recycling a random unitary operator by using all of its columns (not a good idea?).

phase_to_complex(x)

rand([shape, dtype, scale, loc, …])

Fast multithreaded generation of random normally distributed data using randomgen.

rand_haar_state(d[, dtype])

Generate a random state of dimension d according to the Haar distribution.

rand_herm(d[, sparse, density, dtype])

Generate a random hermitian operator of order d with normally distributed entries.

rand_iso(n, m[, dtype])

Generate a random isometry of shape (n, m).

rand_ket(d[, sparse, stype, density, dtype])

Generates a ket of length d with normally distributed entries.

rand_matrix(d[, scaled, sparse, stype, …])

Generate a random matrix of order d with normally distributed entries.

rand_matrix_product_state(n, bond_dim[, …])

Generate a random matrix product state (in dense form, see MPS_rand_state() for tensor network form).

rand_mera(n[, invariant, dtype])

Generate a random mera state of n qubits, which must be a power of 2.

rand_mix(d[, tr_d_min, tr_d_max, mode, dtype])

Constructs a random mixed state by tracing out a random ket where the composite system varies in size between 2 and d.

rand_mps(n, bond_dim[, phys_dim, dtype, …])

Generate a random matrix product state (in dense form, see MPS_rand_state() for tensor network form).

rand_phase(shape[, scale, dtype])

Generate random complex numbers distributed on the unit sphere.

rand_pos(d[, sparse, density, dtype])

Generate a random positive operator of size d, with normally distributed entries.

rand_product_state(n[, qtype, dtype])

Generates a ket of n many random pure qubits.

rand_rademacher(shape[, scale, dtype])

rand_rho(d[, sparse, density, dtype])

Generate a random positive operator of size d with normally distributed entries and unit trace.

rand_seperable(dims[, num_mix, dtype])

Generate a random, mixed, seperable state.

rand_uni(d[, dtype])

Generate a random unitary operator of size d, distributed according to the Haar measure.

randn([shape, dtype, scale, loc, …])

Fast multithreaded generation of random normally distributed data using randomgen.

random_seed_fn(fn)

Modify fn to take a seed argument (so as to seed the random generators once-only at beginning of function not every randn call).

seed_rand(seed)

See the random number generators, by instantiating a new set of bit generators with a ‘seed sequence’.

set_rand_bitgen(bitgen)

Set the core bit generator type to use, from either numpy or randomgen.

quimb.gen.rand.gen_rand_haar_states(d, reps, dtype=<class '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(shape=(), dtype=<class 'float'>, scale=1.0, loc=0.0, num_threads=None, seed=None, dist='normal')[source]

Fast multithreaded generation of random normally distributed data using randomgen.

Parameters
  • shape (tuple[int]) – The shape of the output random array.

  • dtype ({'complex128', 'float64', 'complex64' 'float32'}, optional) – The data-type of the output array.

  • scale (float, optional) – The width of the distribution (standard deviation if dist='normal').

  • loc (float, optional) – The location of the distribution (lower limit if dist='uniform').

  • num_threads (int, optional) – How many threads to use. If None, decide automatically.

  • dist ({'normal', 'uniform', 'exp'}, optional) – Type of random number to generate.

quimb.gen.rand.rand_haar_state(d, dtype=<class 'complex'>)[source]

Generate a random state of dimension d according to the Haar distribution.

quimb.gen.rand.rand_herm(d, sparse=False, density=None, dtype=<class '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].

quimb.gen.rand.rand_iso(n, m, dtype=<class 'complex'>)[source]

Generate a random isometry of shape (n, m).

quimb.gen.rand.rand_ket(d, sparse=False, stype='csr', density=0.01, dtype=<class 'complex'>)[source]

Generates a ket of length d with normally distributed entries.

quimb.gen.rand.rand_matrix(d, scaled=True, sparse=False, stype='csr', density=None, dtype=<class '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_matrix_product_state(n, bond_dim, phys_dim=2, dtype=<class '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

qarray

quimb.gen.rand.rand_mera(n, invariant=False, dtype=<class 'complex'>)[source]

Generate a random mera state of n qubits, which must be a power of 2. This uses quimb.tensor.

quimb.gen.rand.rand_mix(d, tr_d_min=None, tr_d_max=None, mode='rand', dtype=<class '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_mps(n, bond_dim, phys_dim=2, dtype=<class 'complex'>, cyclic=False, trans_invar=False)

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

qarray

quimb.gen.rand.rand_phase(shape, scale=1, dtype=<class 'complex'>)[source]

Generate random complex numbers distributed on the unit sphere.

quimb.gen.rand.rand_pos(d, sparse=False, density=None, dtype=<class '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].

quimb.gen.rand.rand_product_state(n, qtype=None, dtype=<class 'complex'>)[source]

Generates a ket of n many random pure qubits.

quimb.gen.rand.rand_rademacher(shape, scale=1, dtype=<class 'float'>)[source]
quimb.gen.rand.rand_rho(d, sparse=False, density=None, dtype=<class 'complex'>)[source]

Generate a random positive operator of size d with normally distributed entries and unit trace.

quimb.gen.rand.rand_seperable(dims, num_mix=10, dtype=<class 'complex'>)[source]

Generate a random, mixed, seperable state. E.g rand_seperable([2, 2]) for a mixed two qubit state with no entanglement.

Parameters
  • dims (tuple of int) – The local dimensions across which to be seperable.

  • num_mix (int, optional) – How many individual product states to sum together, each with random weight.

Returns

Mixed seperable state.

Return type

qarray

quimb.gen.rand.rand_uni(d, dtype=<class 'complex'>)[source]

Generate a random unitary operator of size d, distributed according to the Haar measure.

quimb.gen.rand.randn(shape=(), dtype=<class 'float'>, scale=1.0, loc=0.0, num_threads=None, seed=None, dist='normal')[source]

Fast multithreaded generation of random normally distributed data using randomgen.

Parameters
  • shape (tuple[int]) – The shape of the output random array.

  • dtype ({'complex128', 'float64', 'complex64' 'float32'}, optional) – The data-type of the output array.

  • scale (float, optional) – The width of the distribution (standard deviation if dist='normal').

  • loc (float, optional) – The location of the distribution (lower limit if dist='uniform').

  • num_threads (int, optional) – How many threads to use. If None, decide automatically.

  • dist ({'normal', 'uniform', 'exp'}, optional) – Type of random number to generate.

quimb.gen.rand.random_seed_fn(fn)[source]

Modify fn to take a seed argument (so as to seed the random generators once-only at beginning of function not every randn call).

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 or randomgen.

Parameters

bitgen ({'PCG64', 'SFC64', 'MT19937', 'Philox', str}) – Which bit generator to use.