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 = a^\dag a\), where \(a\) and \(a^\dag\) are the mode annihilation and creation operators, respectively. If multiple dimensions are provided \(\mathtt{dims}=(n_1,\dots,n_M)\), it returns a tuple with len(dims) operators \((N_1,\dots,N_M)\), where \(N_k\) is the number operator acting on the \(k\)-th subsystem within the composite Hilbert space of dimension \(n=\prod n_k\): $$ 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
orNone
).
Returns
(qarray or tuple of qarrays, each of shape (n, n)) Number operator(s), with n = prod(dims).
Examples
Single-mode \(a^\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 \(a^\dag a \otimes I_3\) and \(I_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]]