Skip to content

Commit

Permalink
Merge branch 'pytorch_backend' of https://github.com/qiboteam/qibo in…
Browse files Browse the repository at this point in the history
…to pytorch_backend
  • Loading branch information
renatomello committed Mar 9, 2024
2 parents ab535bc + 2cea316 commit 1e83f33
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 22 deletions.
8 changes: 2 additions & 6 deletions src/qibo/hamiltonians/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@ def nqubits(self):
@nqubits.setter
def nqubits(self, n):
if not isinstance(n, int):
raise_error(
RuntimeError, f"nqubits must be an integer but is {type(n)}."
)
raise_error(RuntimeError, f"nqubits must be an integer but is {type(n)}.")
if n < 1:
raise_error(
ValueError, f"nqubits must be a positive integer but is {n}"
)
raise_error(ValueError, f"nqubits must be a positive integer but is {n}")
self._nqubits = n

@abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/hamiltonians/adiabatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __new__(cls, h0, h1):
else:
raise_error(
TypeError,
f"h0 should be a hamiltonians.Hamiltonian object but is {type(h0)}."
f"h0 should be a hamiltonians.Hamiltonian object but is {type(h0)}.",
)

def __init__(self, h0, h1): # pragma: no cover
Expand Down
4 changes: 1 addition & 3 deletions src/qibo/hamiltonians/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def __init__(self, matrix, *q):
f"Invalid qubit id {qi} < 0 was given in Hamiltonian term.",
)
if not isinstance(matrix, np.ndarray):
raise_error(
TypeError, f"Invalid type {type(matrix)} of symbol matrix."
)
raise_error(TypeError, f"Invalid type {type(matrix)} of symbol matrix.")
dim = int(matrix.shape[0])
if 2 ** len(q) != dim:
raise_error(
Expand Down
4 changes: 1 addition & 3 deletions src/qibo/models/evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def __init__(self, hamiltonian, dt, solver="exp", callbacks=[], accelerators=Non
else:
ham = hamiltonian(0)
if not isinstance(ham, AbstractHamiltonian):
raise TypeError(
f"Hamiltonian type {type(ham)} not understood."
)
raise TypeError(f"Hamiltonian type {type(ham)} not understood.")
self.nqubits = ham.nqubits
self.backend = ham.backend
if dt <= 0:
Expand Down
8 changes: 2 additions & 6 deletions src/qibo/models/variational.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ def schedule(self, t):

s = self._schedule(t / self._t_max)
if (abs(s) - 1) > self.ATOL: # pragma: no cover
raise_error(
ValueError, f"s cannot be greater than 1 but it is {s}."
)
raise_error(ValueError, f"s cannot be greater than 1 but it is {s}.")
return s

def hamiltonian(self, t):
Expand Down Expand Up @@ -359,9 +357,7 @@ def __init__(
self.params = None
# problem hamiltonian
if not isinstance(hamiltonian, AbstractHamiltonian):
raise_error(
TypeError, f"Invalid Hamiltonian type {type(hamiltonian)}."
)
raise_error(TypeError, f"Invalid Hamiltonian type {type(hamiltonian)}.")
self.hamiltonian = hamiltonian
self.nqubits = hamiltonian.nqubits
# mixer hamiltonian (default = -sum(sigma_x))
Expand Down
4 changes: 1 addition & 3 deletions src/qibo/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def __init__(self, q, matrix=None, name="Symbol", commutative=False):
),
)
):
raise_error(
TypeError, f"Invalid type {type(matrix)} of symbol matrix."
)
raise_error(TypeError, f"Invalid type {type(matrix)} of symbol matrix.")
self.matrix = matrix

def __getstate__(self):
Expand Down

0 comments on commit 1e83f33

Please sign in to comment.