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

Add possibility to multiply SymbolicHamiltonian by scalar or add possibility to __add__ together with scalar rescaling #1516

Closed
marekgluza opened this issue Nov 7, 2024 · 1 comment · Fixed by #1517
Assignees
Labels
bug Something isn't working
Milestone

Comments

@marekgluza
Copy link
Contributor

I noticed that there is a nice feature of adding symbolic Hamiltonians but for many applications adding after rescaling by scalars is also useful.

Example

import qibo
from qibo.symbols import *
from qibo.hamiltonians import SymbolicHamiltonian

# works
h1 = SymbolicHamiltonian( Z(0), nqubits = 2)
h2 = SymbolicHamiltonian( Z(1), nqubits = 2)

h12 = h1 + h2
print(h12.form)

# works

h12 = SymbolicHamiltonian( 0.1 * Z(0) + 0.2 * Z(1), nqubits = 2)
print(h12.form)

# fails

h12 = 0.1 * h1 + 0.2 * h2

The error message is inaccurate because both Hamiltonians had the same nqubits

[Qibo 0.2.12|ERROR|2024-11-07 10:40:47]: Only hamiltonians with the same number of qubits can be added.
@marekgluza marekgluza added the enhancement New feature or request label Nov 7, 2024
@renatomello renatomello added bug Something isn't working enhancement New feature or request and removed enhancement New feature or request labels Nov 7, 2024
@renatomello renatomello linked a pull request Nov 7, 2024 that will close this issue
4 tasks
@renatomello renatomello removed the enhancement New feature or request label Nov 7, 2024
@renatomello
Copy link
Contributor

@marekgluza the fix is in #1517

@renatomello renatomello self-assigned this Nov 7, 2024
@renatomello renatomello added this to the Qibo 0.2.14 milestone Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants