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

Remove matmuleinsum backend #404

Merged
merged 21 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/qibo/models/variational.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from qibo import get_backend
from qibo.config import raise_error
from qibo.core.circuit import Circuit
from qibo.models.evolution import StateEvolution
Expand Down Expand Up @@ -76,20 +75,15 @@ def _loss(params, circuit, hamiltonian):
if K.op is not None:
raise_error(RuntimeError, "Cannot compile VQE that uses custom operators. "
"Set the compile flag to False.")
from qibo import K
for gate in self.circuit.queue:
_ = gate.cache
loss = K.compile(_loss)

if method == 'sgd':
# check if gates are using the MatmulEinsum backend
if K.op is not None:
raise_error(RuntimeError, 'SGD VQE requires native Tensorflow '
'gates because gradients are not '
'supported in the custom kernels.')
loss = _loss
else:
loss = _loss

if method != "sgd":
loss = lambda p, c, h: K.qnp.dtypes("DTYPE")(_loss(p, c, h))
scarrazza marked this conversation as resolved.
Show resolved Hide resolved

result, parameters, extra = self.optimizers.optimize(loss, initial_state,
args=(self.circuit, self.hamiltonian),
method=method, jac=jac, hess=hess, hessp=hessp,
Expand Down
10 changes: 3 additions & 7 deletions src/qibo/optimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,11 @@ def sgd(loss, initial_parameters, args=(), options=None, compile=False):
- ``'nmessage'`` (int, default: ``1e3``): Every how many epochs to print
a message of the loss function.
"""
# check if gates are using the MatmulEinsum backend
compatible_backends = {
"tensorflow_defaulteinsum", "tensorflow_matmuleinsum"}
from qibo import K
if K.name not in compatible_backends: # pragma: no cover
from qibo.config import raise_error
raise_error(RuntimeError, "SGD requires native Tensorflow backend.")
from qibo.config import log, raise_error
if K.name != "tensorflow":
raise_error(RuntimeError, "SGD optimizer requires Tensorflow backend.")

from qibo.config import log
sgd_options = {"nepochs": 1000000,
"nmessage": 1000,
"optimizer": "Adagrad",
Expand Down