utils
numqi.utils.hf_num_state_to_num_qubit(num_state, kind='exact')
convert the number of states to the number of qubits
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_state
|
int
|
number of states |
required |
kind
|
str
|
'exact', 'ceil', 'floor' |
'exact'
|
Returns:
Name | Type | Description |
---|---|---|
ret |
int
|
number of qubits |
numqi.utils.hf_complex_to_real(x)
convert a complex matrix to a real matrix
complex -> [[real,-imag], [imag,real]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
(ndarray, Tensor)
|
a complex matrix, shape=(...,m,n), support batch |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
(ndarray, Tensor)
|
a real matrix, shape=(...,2m,2n) |
numqi.utils.hf_real_to_complex(x)
convert a real matrix to a complex matrix
[[real,-imag], [imag,real]] -> complex
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
(ndarray, Tensor)
|
a real matrix, shape=(...,2dim0,2dim1), support batch |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
(ndarray, Tensor)
|
a complex matrix, shape=(...,dim0,dim1) |
numqi.utils.partial_trace(rho, dim, keep_index)
partial trace of a density matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
ndarray
|
a density matrix, shape=(dim,dim) |
required |
dim
|
tuple[int]
|
shape of the density matrix |
required |
keep_index
|
set[int]
|
the indices to keep |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
the partial trace of the density matrix, shape=(dim[keep_index], dim[keep_index]) |
numqi.utils.get_fidelity(rho0, rho1)
get the fidelity of two density matrices or pure states
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho0
|
(ndarray, Tensor)
|
pure state (ndim=1) or density matrix (ndim=2) |
required |
rho1
|
(ndarray, Tensor)
|
pure state or density matrix |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
(float, Tensor)
|
the fidelity of the two states |
numqi.utils.get_von_neumann_entropy(rho, _torch_logm='eigen')
get the von Neumann entropy of a density matrix wiki-link
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
(ndarray, Tensor)
|
a density matrix, shape=(dim,dim) |
required |
_torch_logm
|
(str, tuple)
|
'eigen' or ('pade',num_sqrtm,pade_order), 'pade' is used only when requires_grad |
'eigen'
|
Returns:
Name | Type | Description |
---|---|---|
ret |
float
|
the von Neumann entropy of the density matrix |
numqi.utils.get_Renyi_entropy(rho, alpha)
get the Renyi entropy of a density matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
(ndarray, Tensor)
|
a density matrix, shape=(dim,dim) |
required |
alpha
|
float
|
the order of the Renyi entropy |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
float
|
the Renyi entropy of the density matrix |
numqi.utils.get_purification(rho, dimR=None, seed=None)
get the purification of a density matrix. all purification are connected by Stiefel manifold
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
ndarray
|
a density matrix, shape=(dim,dim) |
required |
dimR
|
(int, None)
|
the dimension of the purification, dimR>=dim, if None, dimR=dim |
None
|
seed
|
(int, None)
|
random seed |
None
|
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
a purification of the density matrix, shape=(dim,dimR) |
numqi.utils.get_trace_distance(rho, sigma)
get the trace distance of two density matrices. abs is not a good choice for loss function, so no torch-version
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
ndarray
|
a density matrix, shape=(dim,dim) |
required |
sigma
|
ndarray
|
a density matrix, shape=(dim,dim) |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
float
|
the trace distance of the density matrices |
numqi.utils.get_purity(rho)
get the purity of a density matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
(ndarray, Tensor)
|
a density matrix, shape=(dim,dim) |
required |
Returns:
Name | Type | Description |
---|---|---|
ret |
float
|
the purity of the density matrix |
numqi.utils.get_relative_entropy(rho, sigma, tr_rho_log_rho=None, _torch_logm=('pade', 6, 8))
get the relative entropy of two density matrices wiki-link
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
(ndarray, Tensor)
|
a density matrix, shape=(dim,dim) |
required |
sigma
|
(ndarray, Tensor)
|
a density matrix, shape=(dim,dim) |
required |
tr_rho_log_rho
|
(float, None)
|
tr(rho log(rho)), if None, calculate it |
None
|
_torch_logm
|
(str, tuple)
|
'eigen' or ('pade',num_sqrtm,pade_order), 'pade' is used only when requires_grad |
('pade', 6, 8)
|
Returns:
Name | Type | Description |
---|---|---|
ret |
(float, Tensor)
|
the relative entropy of the density matrices |
numqi.utils.get_tetrahedron_POVM(num_qubit=1)
Tetrahedron POVM
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_qubit
|
int
|
number of qubits |
1
|
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
shape=(N, m, m) where |
numqi.utils.is_positive_semi_definite(np0, shift=0.0, hermitian_eps=None)
check whether a matrix is positive semi-definite. Cholesky decomposition is used to check the positive semi-definite property.
Determining whether a symmetric matrix is positive-definite stackexchange-link
A practical way to check if a matrix is positive-definite stackexchange-link
Parameters:
Name | Type | Description | Default |
---|---|---|---|
np0
|
ndarray
|
matrix, must be Hermitian |
required |
shift
|
float
|
shift the matrix by a scalar, e.g. |
0.0
|
hermitian_eps
|
float | None
|
threshold for the Hermitian property, raise AssertionError if fail. if |
None
|
Returns:
Name | Type | Description |
---|---|---|
tag |
bool
|
whether the matrix is positive semi-definite |
numqi.utils.hf_interpolate_dm(rho, alpha=None, beta=None, dm_norm=None)
interpolate the density matrix between rho
and the maximally mixed state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rho
|
ndarray
|
density matrix, |
required |
alpha
|
(float, None)
|
|
None
|
beta
|
(float, None)
|
|
None
|
dm_norm
|
(float, None)
|
norm of the density matrix. if None, then calculate it internally |
None
|
Returns:
Name | Type | Description |
---|---|---|
ret |
ndarray
|
interpolated density matrix, |