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

Migrate ML backends to Qiboml #1365

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7beb79f
refactor: build ml backends through qiboml
MatteoRobbiati Jun 18, 2024
93903ae
fix: fix pytorch check in hamiltonians
MatteoRobbiati Jun 18, 2024
c9ad013
refactor: rm tf and torch backends
MatteoRobbiati Jun 18, 2024
026472b
build: add qiboml
MatteoRobbiati Jun 19, 2024
ce48bdd
refactor: load ml backends from qiboml
MatteoRobbiati Jun 19, 2024
e3afebc
refactor: adapt derivative to qiboml backends loading
MatteoRobbiati Jun 19, 2024
8362f8c
refactor: adapt test to qiboml backends loading
MatteoRobbiati Jun 19, 2024
978d7a3
fix: getting qiboml backends in conftest
MatteoRobbiati Jun 19, 2024
bb26953
build: updating lock
MatteoRobbiati Jun 19, 2024
844ae5d
fix: test backend list
MatteoRobbiati Jun 19, 2024
f103e83
fix: test backend list
MatteoRobbiati Jun 19, 2024
750a510
fix: test backend list
MatteoRobbiati Jun 19, 2024
f116174
fix: Remove qiboml exception, leave tensorflow exception
alecandido Jun 20, 2024
dcf8d70
Update tests/conftest.py
MatteoRobbiati Jun 20, 2024
4e3742e
fix: construct backend in case of qiboml backends
MatteoRobbiati Jun 20, 2024
1a092e9
fix: get_backend in conftest
MatteoRobbiati Jun 20, 2024
da726da
fix: get_backend arguments in conftest
MatteoRobbiati Jun 20, 2024
dd37f1b
Merge branch 'master' into qiboml_backends
MatteoRobbiati Jun 25, 2024
72eea4b
fix: rm explicit arg in construct backend call
MatteoRobbiati Jun 25, 2024
794b396
fix: conflicts with master and rm explicit qiboml backends from backe…
MatteoRobbiati Sep 3, 2024
42d2ec5
fix: rm pytorch backend import
MatteoRobbiati Sep 4, 2024
47cd497
fix: import pytorch from qiboml
MatteoRobbiati Sep 4, 2024
72f04aa
build: updating lock
MatteoRobbiati Sep 4, 2024
7b5f0c3
Merge branch 'master' into qiboml_backends
MatteoRobbiati Sep 11, 2024
5f874c9
fix: lint and pytest errors due to mpldrawer
MatteoRobbiati Sep 11, 2024
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
305 changes: 197 additions & 108 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ tabulate = "^0.9.0"
openqasm3 = { version = ">=0.5.0", extras = ["parser"] }
numpy = "^1.26.4"
networkx = "^3.2.1"
tensorflow = { version = "^2.16.1", markers = "sys_platform == 'linux' or sys_platform == 'darwin'", optional = true }
torch = { version = "^2.1.1", optional = true }

[tool.poetry.group.dev]
optional = true
Expand Down Expand Up @@ -69,8 +67,7 @@ scikit-learn = "^1.2.1"
pytest-cov = "^4.0.0"
pylint = "3.1.0"
matplotlib = "^3.7.0"
tensorflow = { version = "^2.16.1", markers = "sys_platform == 'linux'" }
torch = "^2.1.1"
qiboml = { git = "https://github.com/qiboteam/qiboml.git" }
qibojit = { git = "https://github.com/qiboteam/qibojit.git" }
qibotn = { git = "https://github.com/qiboteam/qibotn.git" }
stim = "^1.12.0"
Expand Down Expand Up @@ -105,8 +102,6 @@ qibojit = { git = "https://github.com/qiboteam/qibojit.git" }
qibotn = { git = "https://github.com/qiboteam/qibotn.git" }

[tool.poetry.extras]
tensorflow = ["tensorflow"]
torch = ["torch"]
qinfo = ["stim"]

[tool.pylint.main]
Expand Down
25 changes: 16 additions & 9 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
from qibo.backends.clifford import CliffordBackend
from qibo.backends.npmatrices import NumpyMatrices
from qibo.backends.numpy import NumpyBackend
from qibo.backends.pytorch import PyTorchBackend
from qibo.backends.tensorflow import TensorflowBackend
from qibo.config import log, raise_error

QIBO_NATIVE_BACKENDS = ("numpy", "tensorflow", "pytorch")
QIBO_NON_NATIVE_BACKENDS = ("qibojit", "qibolab", "qibo-cloud-backends", "qibotn")
QIBO_NATIVE_BACKENDS = ("numpy",)
QIBO_NON_NATIVE_BACKENDS = (
"qibojit",
"qibolab",
"qibo-cloud-backends",
"qibotn",
)
QIBOML_BACKENDS = (
"tensorflow",
"pytorch",
)


class MetaBackend:
Expand All @@ -31,10 +38,6 @@ def load(backend: str, **kwargs) -> Backend:

if backend == "numpy":
return NumpyBackend()
elif backend == "tensorflow":
return TensorflowBackend()
elif backend == "pytorch":
return PyTorchBackend()
elif backend == "clifford":
engine = kwargs.pop("platform", None)
kwargs["engine"] = engine
Expand Down Expand Up @@ -194,7 +197,7 @@ def _check_backend(backend):
def list_available_backends() -> dict:
"""Lists all the backends that are available."""
available_backends = MetaBackend().list_available()
for backend in QIBO_NON_NATIVE_BACKENDS:
for backend in QIBO_NON_NATIVE_BACKENDS + ("qiboml",):
try:
module = import_module(backend.replace("-", "_"))
available = getattr(module, "MetaBackend")().list_available()
Expand All @@ -218,6 +221,10 @@ def construct_backend(backend, **kwargs) -> Backend:
elif backend in QIBO_NON_NATIVE_BACKENDS:
module = import_module(backend.replace("-", "_"))
return getattr(module, "MetaBackend").load(**kwargs)
elif backend in QIBOML_BACKENDS:
module = import_module("qiboml")
return getattr(module, "MetaBackend").load(backend, **kwargs)

else:
raise_error(
ValueError,
Expand Down
185 changes: 0 additions & 185 deletions src/qibo/backends/pytorch.py

This file was deleted.

Loading
Loading