qml.math¶
Overview¶
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
Autograd
TensorFlow
PyTorch
JAX
Functions¶
|
Add arguments element-wise. |
|
Returns True if two arrays are element-wise equal within a tolerance. |
|
Returns True if two tensors are element-wise equal along a given axis. |
|
Creates an array or tensor object of the target framework. |
|
Combine a sequence of 2D tensors to form a block diagonal tensor. |
|
Casts the given tensor to a new type. |
|
Casts a tensor to the same dtype as another. |
|
Concatenate a sequence of tensors along the specified axis. |
|
Convert a tensor to the same type as another. |
|
Convert a 2x2 unitary matrix to \(SU(2)\). |
|
Convert a 4x4 matrix to \(SU(4)\). |
|
Calculate the covariance matrix of a list of commuting observables, given the joint probability distribution of the system in the shared eigenbasis. |
|
Detach a tensor from its trace and return just its numerical values. |
|
Construct a diagonal tensor from a list of scalars. |
|
Convenience function to compute a (full) density matrix from a state vector. |
|
Returns the matrix or dot product of two tensors. |
|
Evaluates the Einstein summation convention on the operands. |
|
Re-express a matrix acting on a subspace defined by a set of wire labels according to a global wire order. |
|
Expand a vector to more wires. |
|
Compute the expectation value of an operator with respect to a pure state. |
|
Compute the matrix exponential of an array \(e^{X}\). |
|
Creates an identity array or tensor object of the target framework. |
|
Compute the fidelity for two states (given as density matrices) acting on quantum systems with the same size. |
|
Compute the fidelity for two states (given as state vectors) acting on quantum systems with the same size. |
|
Frobenius inner product between two matrices. |
|
Return the lower incomplete Gamma function. |
An interface independent way of getting the name of the datatype. |
|
|
Determines the correct framework to dispatch to given a tensor-like object or a sequence of tensor-like objects. |
|
Determine whether a tensor has an additional batch dimension for broadcasting, compared to an expected_shape. |
|
Helper function to get the canonical interface name. |
|
Given a deep data structure with interface-specific scalars at the bottom, return their interface name. |
|
Returns a set containing the trainable indices of a sequence of values. |
|
Compute the gradient in a jax-like manner for any interface. |
|
Returns True if the tensor is considered to be in a backpropagation environment, it works for Autograd, TensorFlow and Jax. |
|
Returns True if the tensor is considered abstract. |
|
Test whether a function is independent of its input arguments, both numerically and analytically. |
|
Return True if the tensor has a non-zero complex component. |
|
Compute the Jacobian in a jax-like manner for any interface. |
|
The kronecker/tensor product of args. |
|
Returns the matrix product of two tensors. |
|
Compute the marginal probability given a joint probability distribution expressed as a tensor. |
|
Compute the maximum entropy of a density matrix on a given subsystem. |
|
Compute the minimum entropy from a density matrix. |
|
Decorator to dispatch arguments handled by the interface. |
|
Compute the mutual information between two subsystems given a state: |
|
Compute the norm of a tensor in each interface. |
|
Returns a tensor of all ones with the same shape and dtype as the input tensor. |
|
Compute the reduced density matrix by tracing out the provided indices. |
|
Computes the purity of a density matrix. |
|
Compute the density matrix from a state represented with a density matrix. |
|
Apply the given |
|
Compute the density matrix from a state vector. |
|
Returns the reduced row echelon form (RREF) of a matrix in a binary finite field \(\mathbb{Z}_2\). |
|
Compute the quantum relative entropy of one state with respect to another. |
|
Returns True if the tensor is considered trainable. |
|
Scatters an array into a tensor of shape new_dims according to indices. |
|
In-place addition of a multidimensional value over various indices of a tensor. |
|
Set the value at a specified index in an array. |
|
Compute the square root matrix of a density matrix where \(\rho = \sqrt{\rho} \times \sqrt{\rho}\) |
|
Stack a sequence of tensors along the specified axis. |
|
Compute the singular value decomposition of a tensor in each interface. |
|
Returns the tensor product of two tensors. |
|
Compute the trace distance between two quantum states. |
|
Unwrap a sequence of objects to NumPy arrays. |
|
Compute the Von Neumann entropy from a density matrix on a given subsystem. |
|
Compute the Von Neumann entanglement entropy between two subsystems in a given state. |
|
Returns elements chosen from x or y depending on a boolean tensor condition, or the indices of entries satisfying the condition. |
Classes¶
|
Canonical set of interfaces supported. |
Utility functions for decompositions¶
Utility functions for decompositions are available from qml.math.decomposition
.
Functions¶
Decompose an integer \(k<=2^{n-1}\) into additions and subtractions of the smallest-possible number of powers of two. |
|
|
Decompose a unitary into a sequence of Givens rotation gates with phase shifts and a diagonal phase matrix. |
Given a matrix \(U = A \otimes B\) in SU(2) x SU(2), extract A and B |
|
|
Compute the rotation angles \(\lambda\), \(\theta\), and \(\phi\) and the phase \(\alpha\) of a 2x2 unitary matrix as a product of X and Y rotations in the form \(e^{i\alpha} RX(\phi) RY(\theta) RX(\lambda)\). |
|
Compute the rotation angles \(\lambda\), \(\theta\), and \(\phi\) and the phase \(\alpha\) of a 2x2 unitary matrix as a product of X and Z rotations in the form \(e^{i\alpha} RX(\phi) RZ(\theta) RX(\lambda)\). |
|
Compute the rotation angles \(\lambda\), \(\theta\), and \(\phi\) and the phase \(\alpha\) of a 2x2 unitary matrix as a product of Z and X rotations in the form \(e^{i\alpha} RZ(\phi) RX(\theta) RZ(\lambda)\). |
|
Compute the rotation angles \(\phi\), \(\theta\), and \(\omega\) and the phase \(\alpha\) of a 2x2 unitary matrix as a product of Z and Y rotations in the form \(e^{i\alpha} RZ(\omega) RY(\theta) RZ(\phi)\) |