# qml.math¶

This package contains unified functions for framework-agnostic tensor and array manipulation. Given the input tensor-like object, the call is dispatched to the corresponding array manipulation framework, allowing for end-to-end differentiation to be preserved.

Warning

These functions are experimental, and only a subset of common functionality is supported. Furthermore, the names and behaviour of these functions may differ from similar functions in common frameworks; please refer to the function docstrings for more details.

The following frameworks are currently supported:

• NumPy

 _multi_dispatch(values) Determines the correct framework to dispatch to given a sequence of tensor-like objects. multi_dispatch([argnum, tensor_list]) Decorater to dispatch arguments handled by the interface. allclose(a, b[, rtol, atol]) Returns True if two arrays are element-wise equal within a tolerance. allequal(tensor1, tensor2, **kwargs) Returns True if two tensors are element-wise equal along a given axis. block_diag(values[, like]) Combine a sequence of 2D tensors to form a block diagonal tensor. cast(tensor, dtype) Casts the given tensor to a new type. cast_like(tensor1, tensor2) Casts a tensor to the same dtype as another. concatenate(values[, axis, like]) Concatenate a sequence of tensors along the specified axis. convert_like(tensor1, tensor2) Convert a tensor to the same type as another. cov_matrix(prob, obs[, wires, diag_approx]) Calculate the covariance matrix of a list of commuting observables, given the joint probability distribution of the system in the shared eigenbasis. diag(values[, k, like]) Construct a diagonal tensor from a list of scalars. dot(tensor1, tensor2[, like]) Returns the matrix or dot product of two tensors. einsum(indices, *operands[, like]) Evaluates the Einstein summation convention on the operands. fidelity(state0, state1[, check_state, c_dtype]) Compute the fidelity for two states (a state can be a state vector or a density matrix) acting on quantum systems with the same size. frobenius_inner_product(A, B[, normalize, like]) Frobenius inner product between two matrices. get_interface(tensor) Returns the name of the package that any array/tensor manipulations will dispatch to. get_trainable_indices(values[, like]) Returns a set containing the trainable indices of a sequence of values. is_abstract(tensor[, like]) Returns True if the tensor is considered abstract. is_independent(func, interface, args[, …]) Test whether a function is independent of its input arguments, both numerically and analytically. marginal_prob(prob, axis) Compute the marginal probability given a joint probability distribution expressed as a tensor. mutual_info(state, indices0, indices1[, …]) Compute the mutual information between two subsystems given a state: ones_like(tensor[, dtype]) Returns a tensor of all ones with the same shape and dtype as the input tensor. reduced_dm(state, indices[, check_state, …]) Compute the reduced density matrix from a state vector or a density matrix. requires_grad(tensor[, interface]) Returns True if the tensor is considered trainable. sqrt_matrix(density_matrix) Compute the square root matrix of a density matrix where $$\rho = \sqrt{\rho} \times \sqrt{\rho}$$ :param density_matrix: 2D density matrix of the quantum system. scatter_element_add(tensor, index, value[, like]) In-place addition of a multidimensional value over various indices of a tensor. stack(values[, axis, like]) Stack a sequence of tensors along the specified axis. tensordot(tensor1, tensor2[, axes, like]) Returns the tensor product of two tensors. unwrap(values[, max_depth]) Unwrap a sequence of objects to NumPy arrays. vn_entropy(state, indices[, base, …]) Compute the Von Neumann entropy from a state vector or density matrix on a given subsystem. where(condition[, x, y]) Returns elements chosen from x or y depending on a boolean tensor condition, or the indices of entries satisfying the condition.