toqito.rand.random_state_vector¶
Generates a random state vector.
Module Contents¶
- toqito.rand.random_state_vector.random_state_vector(dim, is_real=False, k_param=0, seed=None)[source]¶
Generate a random pure state vector.
Randomness model
We sample entries independently from the standard normal distribution using
numpy’sdefault_rng. Ifis_realisFalse(default), the imaginary part is sampled in the same way and added with the factor (i); otherwise the vector is real. The sampled vector is normalized to have unit Euclidean norm. Whenk_paramis strictly positive, the returned state describes a bipartite system of dimensionsdim(or[dim, dim]ifdimis an integer) with Schmidt rank at mostk_param. This is achieved by drawing local factors and combining them with a maximally entangled resource state.Examples
We may generate a random state vector. For instance, here is an example where we can generate a (2)-dimensional random state vector.
```python exec=”1” source=”above” session=”vec_example” from toqito.rand import random_state_vector
vec = random_state_vector(2)
We can verify that this is in fact a valid state vector by computing the corresponding density matrix of the vector and checking if the density matrix is pure.
```python exec=”1” source=”above” session=”vec_example” from toqito.state_props import is_pure
dm = vec @ vec.conj().T
It is also possible to pass a seed for reproducibility.
```python exec=”1” source=”above” session=”vec_example” from toqito.rand import random_state_vector
vec = random_state_vector(2, seed=42)
We can once again verify that this is in fact a valid state vector by computing the corresponding density matrix of the vector and checking if the density matrix is pure.
```python exec=”1” source=”above” session=”vec_example” from toqito.state_props import is_pure
dm = vec @ vec.conj().T
- Parameters:
dim (list[int] | tuple[int, Ellipsis] | int) – Either a positive integer giving the total Hilbert-space dimension, or a length-2 sequence specifying the
sampling. (individual subsystem dimensions for bipartite)
is_real (bool) – Boolean denoting whether the returned vector has real entries. Default is False, which produces
amplitudes. (complex)
k_param (int) – Optional upper bound on the Schmidt rank when
dimdescribes a bipartite system. Set to 0smaller ((default) to ignore the Schmidt rank constraint. Must be non-negative and strictly less than the)
used. (subsystem dimension when)
seed (int | None) – A seed used to instantiate numpy’s random number generator.
- Returns:
A normalized column vector of shape
(total_dim, 1)wheretotal_dimequals dim ifdimis an integer and equals the product of entries indimotherwise.- Return type:
numpy.ndarray