Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FermionicOp.simplify does not document its cross-behavior with FermionicOp.index_order #1260

Closed
AlexandreFoley opened this issue Sep 25, 2023 · 3 comments · Fixed by #1261
Closed
Labels
type: documentation Issues related to documentation

Comments

@AlexandreFoley
Copy link

Environment

  • Qiskit Nature version: qiskit-nature==0.5.2
  • Python version: 3.10.10
  • Operating system: macos

What is happening?

Calling simplify on a FermionicOp doesn't yield a fully simplified representation of the operator.
Calling normal order first seems to be a work around for this issue, but it makes simplifying SparseLabelOp in a generic manner impossible.

Simplify for Fermionic op should likely make use of normal ordering to perform simplification. The current implementation doesn't work.
This is similar to issue #901, but it's not that simplify is not agressive enough, but that it fail entirely to simplify the fermionic operator.

How can we reproduce the issue?

from qiskit_nature.second_q.hamiltonians import FermiHubbardModel
from qiskit_nature.second_q.hamiltonians.lattices import LineLattice,BoundaryCondition
from qiskit_nature.second_q.operators import commutators
from qiskit_nature.second_q.operators import FermionicOp

#Create a hamiltonian, Hubbard model because that's what i have on hand.
U = 4
mu = 2
t=1
L=2
line_lattice = LineLattice(num_nodes=L, boundary_condition=BoundaryCondition.OPEN)
Hamiltonian = FermiHubbardModel(line_lattice.uniform_parameters(uniform_interaction=t,uniform_onsite_potential=-mu),onsite_interaction=U).second_q_op()

#secondary operator
C0 = FermionicOp({ "+_0": 1 },    num_spin_orbitals=4)

#create a more complicated fermionic operator
F = commutators.commutator(Hamiltonian,commutators.commutator(Hamiltonian,C0))
print(len(F)) #prints 106
print(len(F.simplify())) #prints 106
print(len(F.normal_order())) #prints 6

What should happen?

simplify should manage to reduce the number of label in F as much or more than normal_order

Any suggestions?

aplying normal ordering could be part of simplify's implementation.

@woodsp-ibm
Copy link
Member

Had you seen this https://qiskit.org/ecosystem/nature/stubs/qiskit_nature.second_q.operators.FermionicOp.index_order.html It was done as part of #902 which addressed the #901 issue you referred to above. #902 has some comment in there as regards the choice things that way.

@AlexandreFoley
Copy link
Author

It's of little help when working with generic SparseLabelOp. simplify is apart of the generic interface, but not normal_order, nor index_order.
At best, those are workaround for FermionicOp simplify failing to simplify the fermionic operator.

@mrossinek
Copy link
Member

With the current development version of Qiskit Nature F has only 6 terms from the beginning (and never 106).
Regardless of that, as Steve also pointed out earlier, this behavior is intentional as explained here:

.. note::
You can use this method to achieve the most aggressive simplification of an operator
without changing the operation order per index. :meth:`simplify` does *not* reorder the
terms and, thus, cannot deduce ``-_0 +_1`` and ``+_1 -_0 +_0 -_0`` to be
identical labels. Calling this method will reorder the latter label to
``-_0 +_0 -_0 +_1``, after which :meth:`simplify` will be able to correctly collapse
these two labels into one.

Arguably, we should add this note to the docstring of the FermionicOp.simplify method, too.

@mrossinek mrossinek added type: documentation Issues related to documentation and removed bug labels Sep 26, 2023
@mrossinek mrossinek changed the title FermionicOp simplify fails to do its task FermionicOp.simplify does not document its cross-behavior with FermionicOp.index_order Sep 26, 2023
mrossinek added a commit to mrossinek/qiskit-nature that referenced this issue Sep 27, 2023
ftroisi pushed a commit that referenced this issue Sep 28, 2023
* docs: improve the documentation of SparseLabelOp.simplify

Closes #1260

* docs: unify the `simplify` docstrings

* docs: be even more explicit about term equivalence
ialsina pushed a commit to ialsina/qiskit-nature that referenced this issue Nov 17, 2023
…munity#1261)

* docs: improve the documentation of SparseLabelOp.simplify

Closes qiskit-community#1260

* docs: unify the `simplify` docstrings

* docs: be even more explicit about term equivalence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation Issues related to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants