Quantum state¶
import numpy as np
try:
import numqi
except ImportError:
%pip install numqi
import numqi
Pure state¶
Definition: a complex vector (array) with length 1, usually denoted using Dirac (bra-ket) notation wiki/bra-ket-notation $|\phi\rangle,|\psi\rangle$. If the vector has $d$ components, we call it qudit with $d$-dimension. Specially, when $d=2$, we call it qubit. let's see some examples.
Qubit: be care the state $|0\rangle,|1\rangle$ are used conventional in this field and they are also called basis (computational basis)
$$ |0\rangle=[1,0]$$
$$ |1\rangle=[0,1] $$
$$ |\psi\rangle=[0.6, 0.48+0.64j] $$
qutrit (qudit with $d=3$):
$$ |\psi\rangle = [0.6,0.48,0.64] $$
2 qubits (or qudit with $d=4$)
$$ |\psi\rangle = [0.36,0.48j,0.48,0.64] $$
more generally for any qudit of size $d$
$$ |\psi\rangle=\sum_{x=0}^{d-1}\psi_x|x\rangle $$
The length (norm) is measured in complex 2-norm and its norm should always be one (unit)
$$\lVert \psi \rVert_2=\sum_{x=0}^{d-1}\psi_x\psi_x^*=1$$
We can create pure states using numpy
or numqi
(they are simply numpy
array)
psi0 = np.array([1,0])
psi1 = np.array([0,1])
psi2 = np.array([0.6,0.8j])
print(f'{psi0=}')
print(f'{psi1=}')
print(f'{psi2=}')
psi0=array([1, 0]) psi1=array([0, 1]) psi2=array([0.6+0.j , 0. +0.8j])
# qudit (d=4)
psi0 = np.array([0.36, 0.48j, 0.48, 0.64])
psi1 = np.array([1,2,3,4])/np.sqrt(30)
psi2 = np.array([0,1,-1,0])/np.sqrt(2) #Bell state (pure state)
print(f'{psi0=}')
print(f'{psi1=}')
print(f'{psi2=}')
psi0=array([0.36+0.j , 0. +0.48j, 0.48+0.j , 0.64+0.j ]) psi1=array([0.18257419, 0.36514837, 0.54772256, 0.73029674]) psi2=array([ 0. , 0.70710678, -0.70710678, 0. ])
and we can also generate random pure state using numqi.random.rand_haar_state(d)
where d
is the dimension of the qudit.
# qudit (d=5): random qudit state
psi0 = numqi.random.rand_haar_state(5)
print(f'{psi0=}')
psi0=array([-0.52406293-0.02979227j, 0.49785481+0.00734536j, -0.41159196+0.30872204j, -0.01358215-0.42161046j, -0.17823339-0.04618287j])
To evaluate its norm, one should always get almost 1 up to machine precision
psi0 = numqi.random.rand_haar_state(233)
print(np.linalg.norm(psi0)) #1.0
0.9999999999999999
Inner product between two pure states can be done using np.vdot
. For example, the inner product between $|0\rangle$ and $|1\rangle$ is 0. Generally, the inner product between two pure states will be a complex number with absolute value less than 1.
psi0 = np.array([1,0])
psi1 = np.array([0,1])
print(np.vdot(psi0,psi1)) #0.0
psi0 = numqi.random.rand_haar_state(23)
psi1 = numqi.random.rand_haar_state(23)
print(np.vdot(psi0,psi1))
0 (-0.0020300229959286133+0.022207945210738576j)
Mixed state¶
Definition: a Hermitian, semi-definite matrix with trace 1, usually denoted with symbol $\rho$. If this matrix has $d$ column and $d$ row (columns must be equal to rows), we call it density matrix of qudit with $d$ dimension and write it as
$$\rho=\sum_{i,j=0}^{d-1} \rho_{ij}|i\rangle\langle j|$$
where $\rho_{ij}$ is the numerical value at i-th row j-th column, $|i\rangle$ is the i-th basis (ket, pure state with only $i$-th component 1), $\langle j|$ is the j-th basis (a row vector, complex transpose of the corresponding $|j\rangle$). Let's explain each word in the definition
- complex matrix: $\rho\in\mathbb{C}^{d\times d}$
- Hermitian: $\rho_{ij}=\rho_{ji}^*$
- semi-definite: for any nonzero complex vector $v$, $\sum_{ij}v^*_i\rho_{ij}v_j>0$
- equivalent: the minimum eigenvalues of $\rho$ is non-negative
- usually denoted as $\rho\succeq 0$, the symbol $0$ denotes zero matrix of size $d\times d$
- trace 1: $\sum_i\rho_{ii}=1$
- equivalent: summation of all eigenvalues gives one, $\sum_i \lambda_i(\rho)=1$
We can generate random density matrix in numqi
# d=4
rho = numqi.random.rand_density_matrix(4)
print(f'random density matrix:\n{rho}')
random density matrix: [[ 0.15403959+0.j -0.0592051 +0.12397048j 0.08765451+0.14432239j 0.08112008-0.00992777j] [-0.0592051 -0.12397048j 0.31825667+0.j 0.05018745-0.1704175j -0.03540679-0.01599733j] [ 0.08765451-0.14432239j 0.05018745+0.1704175j 0.25148447+0.j 0.0985614 -0.11537861j] [ 0.08112008+0.00992777j -0.03540679+0.01599733j 0.0985614 +0.11537861j 0.27621927+0.j ]]
and evaluate its trace which should almost 1, and its eigenvalue which should be all non-negative
print(np.round(rho,3))
print(f'{np.trace(rho)=}')
print(f'{np.linalg.eigvalsh(rho)=}')
print(f'{np.linalg.eigvalsh(rho).sum()=}')
[[ 0.154+0.j -0.059+0.124j 0.088+0.144j 0.081-0.01j ] [-0.059-0.124j 0.318+0.j 0.05 -0.17j -0.035-0.016j] [ 0.088-0.144j 0.05 +0.17j 0.251+0.j 0.099-0.115j] [ 0.081+0.01j -0.035+0.016j 0.099+0.115j 0.276+0.j ]] np.trace(rho)=np.complex128(1+0j) np.linalg.eigvalsh(rho)=array([0.01099727, 0.08655814, 0.26405238, 0.63839221]) np.linalg.eigvalsh(rho).sum()=np.float64(0.9999999999999994)
Connection between pure state and density matrix: when the density matrix $\rho$ has only one non-zero eigenvalue (must be 1), let's denote the associated eigenvector $|\psi\rangle$, then we say the density matrix $\rho$ and the pure state $|\psi\rangle$ are equivalent and have the following equation
$$\rho=|\psi\rangle\langle\psi|$$
The matrix with only one nonzero eigenvalue is said of rank one.
# generate a random pure state
psi = numqi.random.rand_haar_state(3)
rho = psi.reshape(-1,1) @ psi.reshape(1,-1).conj()
print(np.round(rho,3))
print(f'{np.trace(rho)=}')
print(f'{np.linalg.eigvalsh(rho)=}')
print(f'{np.linalg.eigvalsh(rho).sum()=}')
[[0.509+0.j 0.486-0.053j 0.078-0.071j] [0.486+0.053j 0.469+0.j 0.081-0.059j] [0.078+0.071j 0.081+0.059j 0.022+0.j ]] np.trace(rho)=np.complex128(0.9999999999999999+0j) np.linalg.eigvalsh(rho)=array([-6.40058791e-19, 9.08456795e-17, 1.00000000e+00]) np.linalg.eigvalsh(rho).sum()=np.float64(1.0)
Special states¶
numqi.state
implements those speical / interesting states in quantum information.
Maximally entangled state¶
$$ \frac{1}{\sqrt{d}} \sum_{i=1}^{d} |ii\rangle $$
numqi.state.maximally_entangled_state(3)
array([0.57735027, 0. , 0. , 0. , 0.57735027, 0. , 0. , 0. , 0.57735027])
Maximally mixed state¶
$$ \rho_0 = \sum_{i\in[d^2]} \frac{1}{d^2} | ii \rangle\langle ii |.$$
numqi.state.maximally_mixed_state(2)
array([[1., 0., 0., 0.], [0., 1., 0., 0.], [0., 0., 1., 0.], [0., 0., 0., 1.]])
Bell state¶
$$ |\Phi_0\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle) $$
$$ |\Phi_1\rangle = \frac{1}{\sqrt{2}}(|00\rangle - |11\rangle) $$
$$ |\Phi_2\rangle = \frac{1}{\sqrt{2}}(|01\rangle + |10\rangle) $$
$$ |\Phi_3\rangle = \frac{1}{\sqrt{2}}(|01\rangle - |10\rangle) $$
for i in range(4):
print(numqi.state.Bell(i))
[0.70710678 0. 0. 0.70710678] [ 0.70710678 0. 0. -0.70710678] [0. 0.70710678 0.70710678 0. ] [ 0. 0.70710678 -0.70710678 0. ]
W state¶
$$ |W\rangle=\frac{1}{\sqrt{3}}(|001\rangle + |010\rangle + |100\rangle) \in (\mathcal{H}_2)^{\otimes 3} $$
$$ |W_n\rangle=\frac{1}{\sqrt{n}}\sum_{\mathrm{wt}(x)=1} |x\rangle \in (\mathcal{H}_2)^{\otimes n} $$
numqi.state.W(3)
array([0. , 0.57735027, 0.57735027, 0. , 0.57735027, 0. , 0. , 0. ])
GHZ state¶
$$ |\mathrm{GHZ}\rangle = \frac{1}{\sqrt{2}}(|0\rangle^{\otimes n} + |1\rangle^{\otimes n}) $$
numqi.state.GHZ(3)
array([0.70710678, 0. , 0. , 0. , 0. , 0. , 0. , 0.70710678])
Werner state¶
doi-link Compatible quantum correlations: Extension problems for Werner and isotropic states
Definition chosen in numqi
:
$$ \rho_d(\alpha)=\frac{1}{d^2-d\alpha}I-\frac{\alpha}{d^2-d\alpha}\sum_{ij}\left|ij\right\rangle \left\langle ji\right|,\quad\alpha\in\left[-1,1\right] $$
Other definition of Werner state
$$ \rho_{d}\left(a\right)=\frac{d-a}{d\left(d^{2}-1\right)}I+\frac{ad-1}{d\left(d^{2}-1\right)}\sum_{ij}\left|ij\right\rangle \left\langle ji\right|,\quad a\in\left[-1,1\right] $$
Given a Werner state in variable $a$, we can find the corresponding Werner state in variable $\alpha$ by $\alpha=\frac{1-ad}{d-a}$.
d = 2
alpha = 0.5
numqi.state.Werner(d,alpha)
array([[ 0.16666667, 0. , 0. , 0. ], [ 0. , 0.33333333, -0.16666667, 0. ], [ 0. , -0.16666667, 0.33333333, 0. ], [ 0. , 0. , 0. , 0.16666667]])
Isotropic state¶
doi-link Compatible quantum correlations: Extension problems for Werner and isotropic states
Definition chosen in numqi
:
$$ \rho_d(\alpha)=\frac{1-\alpha}{d^2}I+\frac{\alpha}{d}\sum_{ij}\left|ii\right\rangle \left\langle jj\right|,\quad\alpha\in\left[-\frac{1}{d^{2}-1},1\right] $$
Other definition of Isotropic state
$$ \rho_d\left(a\right)=\frac{d-a}{d\left(d^{2}-1\right)}I+\frac{ad-1}{d\left(d^{2}-1\right)}\sum_{ij}\left|ii\right\rangle \left\langle jj\right|,\quad a\in\left[0,d\right] $$
Given a Isotropic state in variable $a$, we can find the corresponding Isotropic state in variable $\alpha$ by $\alpha=\frac{ad-1}{d^2-1}$.
d = 2
alpha = 0.5
numqi.state.Isotropic(d,alpha)
array([[0.375, 0. , 0. , 0.25 ], [0. , 0.125, 0. , 0. ], [0. , 0. , 0.125, 0. ], [0.25 , 0. , 0. , 0.375]])