PennyLaneAI / pennylane

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.
https://pennylane.ai
Apache License 2.0
2.17k stars 568 forks source link

Add matrix support for fermionic objects #5895

Open soranjh opened 1 week ago

soranjh commented 1 week ago

Feature details

⚠️ This issue is part of an internal assignment and not meant for external contributors.

The fermi module has several functions and classes for creating and manipulating fermionic operators. It will be useful to have tools for obtaining the matrix representation of these operators. The FermiWord and FermiSentence objects can be upgraded to have a to_mat() method that allows computing their matrix representation, similar to the PauliWord and PauliSentence classes. The users can then compute the matrix as

>>> import pennylane as qml
>>> op = qml.fermi.FermiWord({(0, 0): '+', (1, 1): '-'})
>>> op.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]])

Implementation

The to_mat() method should be added as an instance method to FermiWord and FermiSentence. The method should have an optional keyword argument, n, for specifying the total number of orbitals which determines the matrix size.

Requirements

  1. The computed matrix should properly describe the behaviour of fermionic operators.
  2. The computed matrix should satisfy the commutation relationship between fermionic operators.