-
Notifications
You must be signed in to change notification settings - Fork 62
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
Fix bug in SymbolicHamiltonian.__mul__
#1517
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1517 +/- ##
=======================================
Coverage 99.72% 99.72%
=======================================
Files 80 80
Lines 11781 11782 +1
=======================================
+ Hits 11749 11750 +1
Misses 32 32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Thanks @renatomello
qibo/tests/test_hamiltonians_symbolic.py Lines 162 to 202 in 05b57e9
by multiplying some fiducial numbers - see 1.5 and 0.6 in the next to last lines def test_symbolic_hamiltonian_operator_add_and_sub(
backend, nqubits, calcterms, calcdense
):
"""Test addition and subtraction between Trotter Hamiltonians."""
local_ham1 = hamiltonians.SymbolicHamiltonian(
symbolic_tfim(nqubits, h=1.0), backend=backend
)
local_ham2 = hamiltonians.SymbolicHamiltonian(
symbolic_tfim(nqubits, h=0.5), backend=backend
)
if calcterms:
_ = local_ham1.terms
_ = local_ham2.terms
if calcdense:
_ = local_ham1.dense
_ = local_ham2.dense
local_ham = local_ham1 + local_ham2
target_ham = hamiltonians.TFIM(nqubits, h=1.0, backend=backend) + hamiltonians.TFIM(
nqubits, h=0.5, backend=backend
)
dense = local_ham.dense
backend.assert_allclose(dense.matrix, target_ham.matrix)
local_ham1 = hamiltonians.SymbolicHamiltonian(
symbolic_tfim(nqubits, h=1.0), backend=backend
)
local_ham2 = hamiltonians.SymbolicHamiltonian(
symbolic_tfim(nqubits, h=0.5), backend=backend
)
if calcterms:
_ = local_ham1.terms
_ = local_ham2.terms
if calcdense:
_ = local_ham1.dense
_ = local_ham2.dense
local_ham =1.5 * local_ham1 - 0.6 * local_ham2
target_ham = 1.5 *hamiltonians.TFIM(nqubits, h=1.0, backend=backend) - 0.6 * hamiltonians.TFIM(
nqubits, h=0.5, backend=backend
)
dense = local_ham.dense
backend.assert_allclose(dense.matrix, target_ham.matrix) |
@marekgluza I introduced a small example that covers this situation. |
nqubits, h=0.5, backend=backend | ||
) | ||
dense = local_ham.dense | ||
backend.assert_allclose(dense.matrix, target_ham.matrix) | ||
|
||
# Test multiplication and sum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Worth also keeping in mind for tutorials even :)
Checklist: