-
Notifications
You must be signed in to change notification settings - Fork 746
Open
Labels
bug 🐛Something isn't workingSomething isn't working
Description
Expected behavior
Hi Pennylane Team!
When simplifying a FermiSentence using self.simplify(): expected output is a FermiSentence with FermiWords whose coefficients exceed a threshold value. I've included an example code snippet and the expected output below.
However, the actual output obtained is None. This behavior is reproducible when using PauliSentence.simplify() as well.
- CODE:
fw1 = qml.FermiWord({(0, 0): "+", (1, 1): "-"})
fw2 = qml.FermiWord({(0, 0): "+", (1, 0): "-"})
fs = qml.FermiSentence({fw1: 1.2, fw2: 3.1})
print("FermiSentence: ", fs)
print('\nAdjoint: ', fs.adjoint())
fs_new = fs - fs.adjoint()
print('\nAnti-hermitian sentence:', fs_new)
fs_abs = fs_new.simplify()
print('\nSimplified sentence:', fs_abs)
- EXPECTED OUTPUT:
FermiSentence: 1.2 * a⁺(0) a(1)
+ 3.1 * a⁺(0) a(0)
Adjoint: 1.2 * a⁺(1) a(0)
+ 3.1 * a⁺(0) a(0)
Anti-hermitian sentence: 1.2 * a⁺(0) a(1)
+ 0.0 * a⁺(0) a(0)
+ -1.2 * a⁺(1) a(0)
Simplified sentence: 1.2 * a⁺(0) a(1)
+ -1.2 * a⁺(1) a(0)
Actual behavior
- ACTUAL OUTPUT:
FermiSentence: 1.2 * a⁺(0) a(1)
+ 3.1 * a⁺(0) a(0)
Adjoint: 1.2 * a⁺(1) a(0)
+ 3.1 * a⁺(0) a(0)
Anti-hermitian sentence: 1.2 * a⁺(0) a(1)
+ 0.0 * a⁺(0) a(0)
+ -1.2 * a⁺(1) a(0)
Simplified sentence: None
Additional information
No response
Source code
# Source code from
# https://docs.pennylane.ai/en/stable/_modules/pennylane/fermi/fermionic.html#FermiSentence.
#
# self.items() are incorrectly type casted as a `list` instead of a tuple.
def simplify(self, tol=1e-8):
r"""Remove any FermiWords in the FermiSentence with coefficients less than the threshold
tolerance."""
items = list(self.items())
for fw, coeff in items:
if abs(coeff) <= tol:
del self[fw]Tracebacks
System information
Name: pennylane
Version: 0.44.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page:
Author:
License:
Location: /Users/pranavijain/Documents/xx/.env/lib/python3.13/site-packages
Platform info: macOS-26.3-arm64-arm-64bit-Mach-O
Python version: 3.13.11
Numpy version: 2.4.2
Scipy version: 1.17.0
JAX version: 0.6.2
Installed devices:
- qiskit.aer (PennyLane-qiskit-0.44.1)
- qiskit.basicaer (PennyLane-qiskit-0.44.1)
- qiskit.basicsim (PennyLane-qiskit-0.44.1)
- qiskit.remote (PennyLane-qiskit-0.44.1)
- lightning.qubit (pennylane_lightning-0.44.0)
- default.clifford (pennylane-0.44.0)
- default.gaussian (pennylane-0.44.0)
- default.mixed (pennylane-0.44.0)
- default.qubit (pennylane-0.44.0)
- default.qutrit (pennylane-0.44.0)
- default.qutrit.mixed (pennylane-0.44.0)
- default.tensor (pennylane-0.44.0)
- null.qubit (pennylane-0.44.0)
- reference.qubit (pennylane-0.44.0)Existing GitHub issues
- I have searched existing GitHub issues to make sure the issue does not already exist.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug 🐛Something isn't workingSomething isn't working