paddle_quantum.linalg
The library of functions in linear algebra.
- paddle_quantum.linalg.abs_norm(mat)
tool for calculation of matrix norm
- Parameters:
mat (ndarray | Tensor | State) – matrix
- Returns:
norm of input matrix
- Return type:
float
- paddle_quantum.linalg.dagger(mat)
tool for calculation of matrix dagger
- Parameters:
mat (ndarray | Tensor) – matrix
- Returns:
The dagger of matrix
- Return type:
ndarray | Tensor
- paddle_quantum.linalg.is_hermitian(mat, eps=1e-06)
verify whether
mat
is Hermitian- Parameters:
mat (ndarray | Tensor) – hermitian candidate
eps (float | None) – tolerance of error
- Returns:
determine whether
- Return type:
bool
- paddle_quantum.linalg.is_positive(mat, eps=1e-06)
verify whether
mat
is a positive semi-definite matrix.- Parameters:
mat (ndarray | Tensor) – positive operator candidate
eps (float | None) – tolerance of error
- Returns:
determine whether
is Hermitian and eigenvalues are non-negative- Return type:
bool
- paddle_quantum.linalg.is_state_vector(vec, eps=None)
verify whether
vec
is a legal quantum state vector- Parameters:
vec (ndarray | Tensor) – state vector candidate
eps (float | None) – tolerance of error, default to be None i.e. no testing for data correctness
- Returns:
determine whether
, and return the number of qubits or an error message- Return type:
Tuple[bool, int]
Note
error message is: *
-1
if the above equation does not hold *-2
if the dimension ofvec
is not a power of 2 *-3
ifvec
is not a vector
- paddle_quantum.linalg.is_density_matrix(rho, eps=None)
verify whether
rho
is a legal quantum density matrix- Parameters:
rho (ndarray | Tensor) – density matrix candidate
eps (float | None) – tolerance of error, default to be None i.e. no testing for data correctness
- Returns:
determine whether
rho
is a PSD matrix with trace 1 and return the number of qubits or an error message.- Return type:
Tuple[bool, int]
Note
error message is: *
-1
ifrho
is not PSD *-2
if the trace ofrho
is not 1 *-3
if the dimension ofrho
is not a power of 2 *-4
ifrho
is not a square matrix
- paddle_quantum.linalg.is_projector(mat, eps=1e-06)
verify whether
mat
is a projector- Parameters:
mat (ndarray | Tensor) – projector candidate
eps (float | None) – tolerance of error
- Returns:
determine whether
- Return type:
bool
- paddle_quantum.linalg.is_unitary(mat, eps=0.0001)
verify whether
mat
is a unitary- Parameters:
mat (ndarray | Tensor) – unitary candidate
eps (float | None) – tolerance of error
- Returns:
determine whether
- Return type:
bool
- paddle_quantum.linalg.hermitian_random(num_qubits)
randomly generate a
hermitian matrix- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
hermitian matrix- Return type:
Tensor
- paddle_quantum.linalg.orthogonal_projection_random(num_qubits)
randomly generate a
rank-1 orthogonal projector- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
orthogonal projector- Return type:
Tensor
- paddle_quantum.linalg.density_matrix_random(num_qubits)
randomly generate an num_qubits-qubit state in density matrix form
- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
density matrix- Return type:
Tensor
- paddle_quantum.linalg.unitary_random(num_qubits)
randomly generate a
unitary- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
unitary matrix- Return type:
Tensor
- paddle_quantum.linalg.unitary_hermitian_random(num_qubits)
randomly generate a
hermitian unitary- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
hermitian unitary matrix- Return type:
Tensor
- paddle_quantum.linalg.unitary_random_with_hermitian_block(num_qubits, is_unitary=False)
randomly generate a unitary
matrix that is a block encoding of a Hermitian matrix- Parameters:
num_qubits (int) – number of qubits
is_unitary (bool) – whether the hermitian block is a unitary divided by 2 (for tutorial only)
- Returns:
a
unitary matrix that its upper-left block is a Hermitian matrix- Return type:
Tensor
- paddle_quantum.linalg.block_enc_herm(mat, num_block_qubits=1)
generate a (qubitized) block encoding of hermitian
mat
- Parameters:
mat (ndarray | Tensor) – matrix to be block encoded
num_block_qubits (int) – ancilla qubits used in block encoding
- Returns:
a unitary that is a block encoding of
mat
- Return type:
ndarray | Tensor
- paddle_quantum.linalg.haar_orthogonal(num_qubits)
randomly generate an orthogonal matrix following Haar random, referenced by arXiv:math-ph/0609050v2
- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
orthogonal matrix- Return type:
Tensor
- paddle_quantum.linalg.haar_unitary(num_qubits)
randomly generate a unitary following Haar random, referenced by arXiv:math-ph/0609050v2
- Parameters:
num_qubits (int) – number of qubits
- Returns:
a
unitary- Return type:
Tensor
- paddle_quantum.linalg.haar_state_vector(num_qubits, is_real=False)
randomly generate a state vector following Haar random
- Parameters:
num_qubits (int) – number of qubits
is_real (bool | None) – whether the vector is real, default to be False
- Returns:
a
state vector- Return type:
Tensor
- paddle_quantum.linalg.haar_density_operator(num_qubits, rank=None, is_real=False)
randomly generate a density matrix following Haar random
- Parameters:
num_qubits (int) – number of qubits
rank (int | None) – rank of density matrix, default to be
None
refering to full ranksis_real (bool | None) – whether the density matrix is real, default to be False
- Returns:
a
density matrix- Return type:
Tensor
- paddle_quantum.linalg.direct_sum(A, B)
calculate the direct sum of A and B
- Parameters:
A (ndarray | Tensor) –
matrixB (ndarray | Tensor) –
matrix
- Returns:
a direct sum of A and B, with shape
- Return type:
ndarray | Tensor
- paddle_quantum.linalg.NKron(matrix_A, matrix_B, *args)
calculate Kronecker product of at least two matrices
- Parameters:
matrix_A (Tensor | ndarray) – matrix, as paddle.Tensor or numpy.ndarray
matrix_B (Tensor | ndarray) – matrix, as paddle.Tensor or numpy.ndarray
*args (Tensor | ndarray) – other matrices, as paddle.Tensor or numpy.ndarray
- Returns:
Kronecker product of matrices, determined by input type of matrix_A
- Return type:
Tensor | ndarray
from paddle_quantum.state import density_op_random from paddle_quantum.linalg import NKron A = density_op_random(2) B = density_op_random(2) C = density_op_random(2) result = NKron(A, B, C)
Note
result
from above code block should be A otimes B otimes C
- paddle_quantum.linalg.herm_transform(fcn, mat, ignore_zero=False)
function transformation for Hermitian matrix
- Parameters:
fcn (Callable[[float], float]) – function
that can be expanded by Taylor seriesmat (Tensor | ndarray | State) – hermitian matrix
ignore_zero (bool | None) – whether ignore eigenspaces with zero eigenvalue, defaults to be
False
- Returns
- paddle_quantum.linalg.pauli_basis_generation(num_qubits)
Generate a Pauli basis.
- Parameters:
num_qubits (int) – the number of qubits
.- Returns:
The Pauli basis of
.- Return type:
List[Tensor]
- paddle_quantum.linalg.pauli_decomposition(mat)
Decompose the matrix by the Pauli basis.
- Parameters:
mat (ndarray | Tensor) – the matrix to be decomposed
- Returns:
The list of coefficients corresponding to Pauli basis.
- Return type:
ndarray | Tensor
- paddle_quantum.linalg.subsystem_decomposition(mat, first_basis, second_basis, inner_prod)
Decompose the input matrix by two given bases in two subsystems.
- Parameters:
mat (ndarray | Tensor) – the matrix
to be decomposedfirst_basis (List[ndarray] | List[Tensor]) – a basis
from the first spacesecond_basis (List[ndarray] | List[Tensor]) – a basis
from the second spaceinner_prod (Callable[[ndarray, ndarray], ndarray] | Callable[[Tensor, Tensor], Tensor]) – the inner product of these subspaces
- Returns:
a coefficient matrix
such that .- Return type:
ndarray | Tensor