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
adjoint
()Return the adjoint of FermiWord.
items
()Returns the dictionary items in sorted order.
shift_operator
(initial_position, final_position)Shifts an operator in the FermiWord from
initial_position
tofinal_position
by applying the fermionic anti-commutation relations.to_mat
([n_orbitals, format, buffer_size])Return the matrix representation.
Return a compact string representation of a FermiWord.
update
(item)Restrict updating FermiWord after instantiation.
- shift_operator(initial_position, final_position)[source]¶
Shifts an operator in the FermiWord from
initial_position
tofinal_position
by applying the fermionic anti-commutation relations.There are three anti-commutator relations:
\[\left\{ a_i, a_j \right\} = 0, \quad \left\{ a^{\dagger}_i, a^{\dagger}_j \right\} = 0, \quad \left\{ a_i, a^{\dagger}_j \right\} = \delta_{ij},\]where
\[\left\{a_i, a_j \right\} = a_i a_j + a_j a_i,\]and
\[\begin{split}\delta_{ij} = \begin{cases} 1 & i = j \\ 0 & i \neq j \end{cases}.\end{split}\]- Parameters
initial_position (int) – The position of the operator to be shifted.
final_position (int) – The desired position of the operator.
- Returns
The
FermiSentence
obtained after applying the anti-commutator relations.- Return type
- Raises
TypeError – if
initial_position
orfinal_position
is not an integerValueError – if
initial_position
orfinal_position
are outside the range[0, len(fermiword) - 1]
wherelen(fermiword)
is the number of operators in the FermiWord.
Example
>>> w = qml.fermi.FermiWord({(0, 0): '+', (1, 1): '-'}) >>> w.shift_operator(0, 1) -1 * a(1) a⁺(0)
- to_mat(n_orbitals=None, format='dense', buffer_size=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.
format (str) – The format of the matrix. It is “dense” by default. Use “csr” for sparse.
buffer_size (int or None) – The maximum allowed memory in bytes to store intermediate results in the calculation of sparse matrices. It defaults to
2 ** 30
bytes that make 1GB of memory. In general, larger buffers allow faster computations.
- 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)