Skip to content

dq.number

number(*dims: int, layout: Layout | None = None) -> QArray | tuple[QArray, ...]

Returns the number operator of a bosonic mode, or a tuple of number operators for a multi-mode system.

For a single mode, it is defined by N=aaN = a^\dag a, where aa and aa^\dag are the mode annihilation and creation operators, respectively. If multiple dimensions are provided dims=(n1,,nM)\mathtt{dims}=(n_1,\dots,n_M), it returns a tuple with len(dims) operators (N1,,NM)(N_1,\dots,N_M), where NkN_k is the number operator acting on the kk-th subsystem within the composite Hilbert space of dimension n=nkn=\prod n_k: Nk=In1ankankInM. N_k = I_{n_1} \otimes\dots\otimes a_{n_k}^\dag a_{n_k} \otimes\dots\otimes I_{n_M}.

Parameters

  • *dims

    Hilbert space dimension of each mode.

  • layout

    Matrix layout (dq.dense, dq.dia or None).

Returns

(qarray or tuple of qarrays, each of shape (n, n)) Number operator(s), with n = prod(dims).

Examples

Single-mode aaa^\dag a:

>>> dq.number(4)
QArray: shape=(4, 4), dims=(4,), dtype=complex64, layout=dia, ndiags=1
[[  ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅    1.+0.j   ⋅      ⋅   ]
 [  ⋅      ⋅    2.+0.j   ⋅   ]
 [  ⋅      ⋅      ⋅    3.+0.j]]

Multi-mode aaI3a^\dag a \otimes I_3 and I2bbI_2\otimes b^\dag b:

>>> na, nb = dq.number(2, 3)
>>> na
QArray: shape=(6, 6), dims=(2, 3), dtype=complex64, layout=dia, ndiags=1
[[  ⋅      ⋅      ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅      ⋅      ⋅    1.+0.j   ⋅      ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅    1.+0.j   ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅      ⋅    1.+0.j]]
>>> nb
QArray: shape=(6, 6), dims=(2, 3), dtype=complex64, layout=dia, ndiags=1
[[  ⋅      ⋅      ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅    1.+0.j   ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅      ⋅    2.+0.j   ⋅      ⋅      ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅      ⋅      ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅    1.+0.j   ⋅   ]
 [  ⋅      ⋅      ⋅      ⋅      ⋅    2.+0.j]]