particle_number(orbitals, mapping='jordan_wigner', wires=None)[source]

Computes the particle number operator \(\hat{N}=\sum_\alpha \hat{n}_\alpha\) in the Pauli basis.

The particle number operator is given by

\[\hat{N} = \sum_\alpha \hat{c}_\alpha^\dagger \hat{c}_\alpha,\]

where the index \(\alpha\) runs over the basis of single-particle states \(\vert \alpha \rangle\), and the operators \(\hat{c}^\dagger\) and \(\hat{c}\) are the particle creation and annihilation operators, respectively.

  • orbitals (int) – Number of spin orbitals. If an active space is defined, this is the number of active spin-orbitals.

  • mapping (str) – Specifies the transformation to map the fermionic operator to the Pauli basis. Input values can be 'jordan_wigner' or 'bravyi_kitaev'.

  • wires (Wires, list, tuple, dict) – Custom wire mapping used to convert the qubit operator to an observable measurable in a PennyLane ansatz. For types Wires/list/tuple, each item in the iterable represents a wire label corresponding to the qubit number equal to its index. For type dict, only int-keyed dict (for qubit-to-wire conversion) is accepted. If None, will use identity map (e.g. 0->0, 1->1, …).


the fermionic-to-qubit transformed observable

Return type



>>> orbitals = 4
>>> N = particle_number(orbitals, mapping="jordan_wigner")
>>> print(N)
(2.0) [I0]
+ (-0.5) [Z0]
+ (-0.5) [Z1]
+ (-0.5) [Z2]
+ (-0.5) [Z3]
>>> N = particle_number(orbitals, mapping="jordan_wigner", wires=['w0','w1','w2','w3'])
>>> print(N)
(2.0) [Iw0]
+ (-0.5) [Zw0]
+ (-0.5) [Zw1]
+ (-0.5) [Zw2]
+ (-0.5) [Zw3]