rand.random_states¶
Generates random quantum states using Qiskit.
Functions¶
|
Generate a list of random quantum states. |
Module Contents¶
- rand.random_states.random_states(n, d, seed=None)¶
Generate a list of random quantum states.
This function generates a list of quantum states, each of a specified dimension. The states are valid quantum states distributed according to the Haar measure.
Examples
Generating three quantum states each of dimension 4.
from toqito.rand import random_states states = random_states(3, 4) print(f"length of states is {len(states)}") print(f"Shape of each state vector: {states[0].shape}") for idx, state in enumerate(states): print(f"\nState {idx}:") print(state)
length of states is 3 Shape of each state vector: (4, 1) State 0: [[-0.3911973 -0.2439141j ] [-0.40019527+0.13556597j] [ 0.04182829+0.15055571j] [ 0.29554738+0.70510376j]] State 1: [[-0.16955403-0.17896464j] [ 0.08536334+0.50378187j] [-0.31602644-0.57031278j] [ 0.29099813+0.41028128j]] State 2: [[ 0.06835308-0.41898005j] [-0.12370692-0.77946159j] [ 0.01926438-0.21155522j] [ 0.13519676-0.36539691j]]
It is also possible to pass a seed to this function for reproducibility.
from toqito.rand import random_states states = random_states(3, 4, seed=42) for idx, state in enumerate(states): print(f"\nState {idx}:") print(state)
State 0: [[ 0.13830446+0.0299699j ] [-0.47202619+0.51163029j] [ 0.34061349+0.21219233j] [ 0.42690188-0.39001418j]] State 1: [[-0.71489214+0.1351165j ] [-0.47714049-0.35135073j] [ 0.04684288+0.32187898j] [-0.11587661-0.01829369j]] State 2: [[-0.00827473-0.0910465j ] [-0.42013238-0.33536439j] [ 0.43311201+0.60211343j] [ 0.38307005-0.07610726j]]
- Parameters:
n (int) – int The number of random states to generate.
d (int) – int The dimension of each quantum state.
seed (int | None) – int | None A seed used to instantiate numpy’s random number generator.
- Returns:
list[numpy.ndarray] A list of n numpy arrays, each representing a d-dimensional quantum state as a column vector.
- Return type:
list[numpy.ndarray]