qml.fermi.from_string¶
- from_string(fermi_string)[source]¶
Return a fermionic operator object from its string representation.
The string representation is a compact format that uses the orbital index and
'+'
or'-'
symbols to indicate creation and annihilation operators, respectively. For instance, the string representation for the operator \(a^{\dagger}_0 a_1 a^{\dagger}_0 a_1\) is'0+ 1- 0+ 1-'
. The'-'
symbols can be optionally dropped such that'0+ 1 0+ 1'
represents the same operator. The format commonly used in OpenFermion to represent the same operator,'0^ 1 0^ 1'
, is also supported.- Parameters
fermi_string (str) – string representation of the fermionic object
- Returns
the fermionic operator object
- Return type
Example
>>> from_string('0+ 1- 0+ 1-') a⁺(0) a(1) a⁺(0) a(1)
>>> from_string('0+ 1 0+ 1') a⁺(0) a(1) a⁺(0) a(1)
>>> from_string('0^ 1 0^ 1') a⁺(0) a(1) a⁺(0) a(1)
>>> op1 = FermiC(0) * FermiA(1) * FermiC(2) * FermiA(3) >>> op2 = from_string('0+ 1- 2+ 3-') >>> op1 == op2 True
code/api/pennylane.fermi.from_string
Download Python script
Download Notebook
View on GitHub