quairkit.database.random

The library of random data generation functions

quairkit.database.random.random_pauli_str_generator(num_qubits, terms=3)

Generate a random observable in list form.

An observable \(O=0.3X\otimes I\otimes I+0.5Y\otimes I\otimes Z\)’s list form is [[0.3, 'x0'], [0.5, 'y0,z2']]. Such an observable is generated by random_pauli_str_generator(3, terms=2)

Parameters:
num_qubits : int

Number of qubits.

terms : int | None

Number of terms in the observable. Defaults to 3.

Returns:

The Hamiltonian of randomly generated observable.

Return type:

List

quairkit.database.random.random_state(num_systems, rank=None, is_real=False, size=1, system_dim=2)

Generate a random quantum state.

Parameters:
num_systems : int

The number of qubits contained in the quantum state.

rank : int | None

The rank of the density matrix. Defaults to None which means full rank.

is_real : bool | None

If the quantum state only contains the real number. Defaults to False.

size : List[int] | int | None

Batch size. Defaults to 1

system_dim : List[int] | int

dimension of systems. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.

Raises:

NotImplementedError – If the backend is wrong or not implemented.

Returns:

The generated quantum state.

Return type:

State

quairkit.database.random.random_hamiltonian_generator(num_qubits, terms=3)

Generate a random Hamiltonian.

Parameters:
num_qubits : int

Number of qubits.

terms : int | None

Number of terms in the Hamiltonian. Defaults to 3.

Returns:

The randomly generated Hamiltonian.

Return type:

Hamiltonian

quairkit.database.random.random_hermitian(num_qubits)

randomly generate a \(2^n \times 2^n\) hermitian matrix

Parameters:
num_qubits : int

number of qubits \(n\)

Returns:

a \(2^n \times 2^n\) hermitian matrix

Return type:

Tensor

quairkit.database.random.random_orthogonal_projection(num_qubits)

randomly generate a \(2^n \times 2^n\) rank-1 orthogonal projector

Parameters:
num_qubits : int

number of qubits \(n\)

Returns:

a \(2^n \times 2^n\) orthogonal projector

Return type:

Tensor

quairkit.database.random.random_density_matrix(num_qubits)

randomly generate an num_qubits-qubit state in density matrix form

Parameters:
num_qubits : int

number of qubits \(n\)

Returns:

a \(2^n \times 2^n\) density matrix

Return type:

Tensor

quairkit.database.random.random_unitary(num_systems, size=1, system_dim=2)

randomly generate a \(d \times d\) unitary

Parameters:
num_systems : int

number of systems in this unitary. Alias of num_qubits.

size : List[int] | int | None

batch size. Defaults to 1

system_dim : List[int] | int

dimension of systems. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.

Returns:

  1. \(d \times d\) unitary matrix

Return type:

Tensor

quairkit.database.random.random_unitary_hermitian(num_qubits)

randomly generate a \(2^n \times 2^n\) hermitian unitary

Parameters:
num_qubits : int

number of qubits \(n\)

Returns:

a \(2^n \times 2^n\) hermitian unitary matrix

Return type:

Tensor

quairkit.database.random.random_unitary_with_hermitian_block(num_qubits, is_unitary=False)

randomly generate a unitary \(2^n \times 2^n\) matrix that is a block encoding of a \(2^{n/2} \times 2^{n/2}\) Hermitian matrix

Parameters:
num_qubits : int

number of qubits \(n\)

is_unitary : bool

whether the hermitian block is a unitary divided by 2 (for tutorial only)

Returns:

a \(2^n \times 2^n\) unitary matrix that its upper-left block is a Hermitian matrix

Return type:

Tensor

quairkit.database.random.haar_orthogonal(dim)

randomly generate an orthogonal matrix following Haar random, referenced by arXiv:math-ph/0609050v2

Parameters:
dim : int

dimension of orthogonal matrix

Returns:

a \(2^n \times 2^n\) orthogonal matrix

Return type:

Tensor

quairkit.database.random.haar_unitary(dim)

randomly generate a unitary following Haar random, referenced by arXiv:math-ph/0609050v2

Parameters:
dim : int

dimension of unitary

Returns:

a \(d \times d\) unitary

Return type:

Tensor

quairkit.database.random.haar_state_vector(dim, is_real=False)

randomly generate a state vector following Haar random

Parameters:
dim : int

dimension of density matrix

is_real : bool | None

whether the vector is real, default to be False

Returns:

a \(2^n \times 1\) state vector

Return type:

Tensor

quairkit.database.random.haar_density_operator(dim, rank, is_real=False)

randomly generate a density matrix following Haar random

Parameters:
dim : int

dimension of density matrix

rank : int

rank of density matrix, default to be None refering to full ranks

is_real : bool | None

whether the density matrix is real, default to be False

Returns:

a \(2^n \times 2^n\) density matrix

Return type:

Tensor

quairkit.database.random.random_channel(num_systems, rank=None, target='kraus', size=1, system_dim=2)

Generate a random channel from its Stinespring representation

Parameters:
num_systems : int

number of systems

rank : int

rank of this Channel. Defaults to be random sampled from \([1, d]\)

target : str

target representation, should to be 'choi', 'kraus' or 'stinespring'

size : int | None

batch size. Defaults to 1

system_dim : List[int] | int

dimension of systems. Can be a list of system dimensions or an int representing the dimension of all systems. Defaults to be qubit case.

Returns:

the target representation of a random channel.

Return type:

Tensor