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

SymbolicHamiltonian.terms setter invalidates the object #1494

Open
BrunoLiegiBastonLiegi opened this issue Oct 16, 2024 · 0 comments
Open

SymbolicHamiltonian.terms setter invalidates the object #1494

BrunoLiegiBastonLiegi opened this issue Oct 16, 2024 · 0 comments

Comments

@BrunoLiegiBastonLiegi
Copy link
Contributor

BrunoLiegiBastonLiegi commented Oct 16, 2024

SymbolicHamiltonian provides a setter for terms that do not take care of updating the form.
This means that by doing the following for instance:

from qibo.symbols import Z, X
from qibo.hamiltonians import SymbolicHamiltonian

h0 = SymbolicHamiltonian(Z(0)*Z(1) + Z(2)*Z(1), nqubits = 3)
h1 = SymbolicHamiltonian(X(0)*X(1) + X(2)*X(1), nqubits = 3)
print(h0.form)
h0.terms = h1.terms
print(h0.form)

you make its form and terms inconsistent.
I would say, in general, that terms should not have a setter since it is computed starting from the form and I would rather make it a @cached_property probably. At the moment the main reason why it is there, I believe, is beacuse it makes it easier to compose hamiltonians through the __add__ operator for instance, without the need to recompute the terms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant