Skip to content

Commit

Permalink
Disable device switch during new backend creation
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros11 committed Jul 9, 2021
1 parent 109e859 commit 9ad5edf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ def construct_backend(self, name):
new_backend = self.available_backends.get(name)()
if self.active_backend is not None:
new_backend.set_precision(self.active_backend.precision)
if self.active_backend.default_device:
new_backend.set_device(self.active_backend.default_device)
self.constructed_backends[name] = new_backend
return self.constructed_backends.get(name)

Expand Down Expand Up @@ -199,8 +197,9 @@ def set_device(name):
"""
if not config.ALLOW_SWITCHERS and name != K.default_device:
log.warning("Device should not be changed after allocating gates.")
K.set_device(name)
for bk in K.constructed_backends.values():
if bk.name != "numpy":
if bk.name != "numpy" and bk != K.active_backend:
bk.set_device(name)


Expand Down

0 comments on commit 9ad5edf

Please sign in to comment.