quairkit.qinfo.linalg¶
-
quairkit.qinfo.linalg.block_enc_herm(mat, num_block_qubits=
1
)¶ generate a (qubitized) block encoding of hermitian
mat
-
quairkit.qinfo.linalg.create_matrix(linear_map, input_dim, input_dtype=
None
)¶ Create a matrix representation of a linear map without needing to specify the output dimension.
This function constructs a matrix representation for a given linear map and input dimension.
- quairkit.qinfo.linalg.gradient(loss_function, var, n)¶
Computes the gradient of a given loss function with respect to its input variable.
- quairkit.qinfo.linalg.hessian(loss_function, var)¶
Computes the Hessian matrix of a given loss function with respect to its input variables.
-
quairkit.qinfo.linalg.herm_transform(fcn, mat, ignore_zero=
False
)¶ function transformation for Hermitian matrix
- Parameters:¶
- Returns
\(f(H)\)
- quairkit.qinfo.linalg.NKron(matrix_A, matrix_B, *args)¶
calculate Kronecker product of at least two density matrices
from quairkit.state import density_op_random from quairkit.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
-
quairkit.qinfo.linalg.partial_trace(state, trace_idx, system_dim=
2
)¶ Calculate the partial trace of the quantum state
-
quairkit.qinfo.linalg.partial_trace_discontiguous(state, preserve_qubits=
None
)¶ Calculate the partial trace of the quantum state with arbitrarily selected subsystem
- Parameters:¶
- Returns:¶
Partial trace of the quantum state with arbitrarily selected subsystem.
- Return type:¶
ndarray | Tensor | State
Note
suitable only when the systems are qubits.
-
quairkit.qinfo.linalg.partial_transpose(state, transpose_idx, system_dim=
2
)¶ Calculate the partial transpose \(\rho^{T_A}\) of the input quantum state.
-
quairkit.qinfo.linalg.permute_systems(state, perm_list, system_dim=
2
)¶ Permute quantum system based on a permute list
-
quairkit.qinfo.linalg.prob_sample(distribution, shots=
1024
, binary=True
, proportional=False
)¶ Sample from a probability distribution.
-
quairkit.qinfo.linalg.schmidt_decompose(psi, sys_A=
None
)¶ Calculate the Schmidt decomposition of a quantum state \(\lvert\psi\rangle=\sum_ic_i\lvert i_A\rangle\otimes\lvert i_B \rangle\).
- Parameters:¶
- Returns:¶
contains elements
A one dimensional array composed of Schmidt coefficients, with shape
(k)
A high dimensional array composed of bases for subsystem A \(\lvert i_A\rangle\), with shape
(k, 2**m, 1)
A high dimensional array composed of bases for subsystem B \(\lvert i_B\rangle\) , with shape
(k, 2**m, 1)
- Return type:¶
Tuple[Tensor, Tensor, Tensor] | Tuple[ndarray, ndarray, ndarray]
-
quairkit.qinfo.linalg.trace(mat, axis1=
-2
, axis2=-1
)¶ Return the sum along diagonals of the tensor.
If \(mat\) is 2-D tensor, the sum along its diagonal is returned.
If \(mat\) has more than two dimensions, then the axes specified by
axis1
andaxis2
are used to determine the 2-D sub-tensors whose traces are returned. The shape of the resulting tensor is the same as the shape of \(mat\) withaxis1
andaxis2
removed.- Parameters:¶
- mat : ndarray | Tensor | State¶
Input tensor, from which the diagonals are taken.
- axis1 : int | None¶
The first axis of the 2-D sub-tensors along which the diagonals should be taken. Defaults to -2.
- axis2 : int | None¶
The second axis of the 2-D sub-tensors along which the diagonals should be taken. Defaults to -1.
- Returns:¶
The sum along the diagonals. If \(mat\) is 2-D tensor, the sum along its diagonal is returned. If \(mat\) has larger dimensions, then a tensor of sums along diagonals is returned.
- Raises:¶
ValueError – The 2-D tensor from which the diagonals should be taken is not square.
- Return type:¶
ndarray | Tensor
Note
The 2-D tensor/array from which the diagonals is taken should be square.