qml.fermi.FermiWord¶
-
class
FermiWord
(operator)[source]¶ Bases:
dict
Immutable dictionary used to represent a Fermi word, a product of fermionic creation and annihilation operators, that can be constructed from a standard dictionary.
The keys of the dictionary are tuples of two integers. The first integer represents the position of the creation/annihilation operator in the Fermi word and the second integer represents the orbital it acts on. The values of the dictionary are one of
'+'
or'-'
symbols that denote creation and annihilation operators, respectively. The operator \(a^{\dagger}_0 a_1\) can then be constructed as>>> w = FermiWord({(0, 0) : '+', (1, 1) : '-'}) >>> w a⁺(0) a(1)
Attributes
Methods
to_mat
([n_orbitals])Return the matrix representation.
Return a compact string representation of a FermiWord.
update
(item)Restrict updating FermiWord after instantiation.
-
to_mat
(n_orbitals=None)[source]¶ Return the matrix representation.
- Parameters
n_orbitals (int or None) – Number of orbitals. If not provided, it will be inferred from the largest orbital index in the Fermi operator.
- Returns
Matrix representation of the
FermiWord
.- Return type
NumpyArray
Example
>>> w = FermiWord({(0, 0): '+', (1, 1): '-'}) >>> w.to_mat() array([0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j])
-
to_string
()[source]¶ Return a compact string representation of a FermiWord. Each operator in the word is represented by the number of the wire it operates on, and a + or - to indicate either a creation or annihilation operator.
>>> w = FermiWord({(0, 0) : '+', (1, 1) : '-'}) >>> w.to_string() a⁺(0) a(1)
-