Skip to content

Commit

Permalink
fix backend bug
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Dec 7, 2024
1 parent 1840363 commit f484ed7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/qibo/hamiltonians/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from qibo.backends import matrices
from qibo.backends import matrices, _check_backend
from qibo.config import raise_error
from qibo.hamiltonians.hamiltonians import Hamiltonian, SymbolicHamiltonian
from qibo.hamiltonians.terms import HamiltonianTerm
Expand Down Expand Up @@ -182,6 +182,8 @@ def Heisenberg(
elif isinstance(coupling_constants, (float, int)):
coupling_constants = [coupling_constants] * 3

backend = _check_backend(backend)

if dense:
condition = lambda i, j: i in {j % nqubits, (j + 1) % nqubits}
hx = _build_spin_model(nqubits, matrices.X, condition)
Expand All @@ -192,9 +194,10 @@ def Heisenberg(
- coupling_constants[1] * hy
- coupling_constants[2] * hz
)
matrix = backend.cast(matrix, dtype=matrix.dtype)

for pauli in [matrices.X, matrices.Y, matrices.Z]:
matrix += (
matrix = matrix + (
external_field_strength
* _OneBodyPauli(nqubits, pauli, dense, backend).matrix
)
Expand Down

0 comments on commit f484ed7

Please sign in to comment.