qml.qchem.qubit_observable¶
-
qubit_observable
(o_ferm, cutoff=1e-12)[source]¶ Convert a fermionic observable to a PennyLane qubit observable.
- Parameters
o_ferm (Union[FermiWord, FermiSentence]) – fermionic operator
cutoff (float) – cutoff value for discarding the negligible terms
- Returns
Simplified PennyLane Hamiltonian
- Return type
Example
>>> w1 = qml.fermi.FermiWord({(0, 0) : '+', (1, 1) : '-'}) >>> w2 = qml.fermi.FermiWord({(0, 1) : '+', (1, 2) : '-'}) >>> s = qml.fermi.FermiSentence({w1 : 1.2, w2: 3.1}) >>> print(qubit_observable(s)) (-0.3j) [Y0 X1] + (0.3j) [X0 Y1] + (-0.775j) [Y1 X2] + (0.775j) [X1 Y2] + ((0.3+0j)) [Y0 Y1] + ((0.3+0j)) [X0 X1] + ((0.775+0j)) [Y1 Y2] + ((0.775+0j)) [X1 X2]
If the new op-math is active, an arithmetic operator is returned.
>>> qml.operation.enable_new_opmath() >>> w1 = qml.fermi.FermiWord({(0, 0) : '+', (1, 1) : '-'}) >>> w2 = qml.fermi.FermiWord({(0, 0) : '+', (1, 1) : '-'}) >>> s = qml.fermi.FermiSentence({w1 : 1.2, w2: 3.1}) >>> print(qubit_observable(s)) (-0.775j*(PauliY(wires=[0]) @ PauliX(wires=[1]))) + ((0.775+0j)*(PauliY(wires=[0]) @ PauliY(wires=[1]))) + ((0.775+0j)*(PauliX(wires=[0]) @ PauliX(wires=[1]))) + (0.775j*(PauliX(wires=[0]) @ PauliY(wires=[1])))
code/api/pennylane.qchem.qubit_observable
Download Python script
Download Notebook
View on GitHub