Skip to content

Commit

Permalink
Merge branch 'master' into ZNE_get_noisy_circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
mho291 committed Aug 15, 2024
2 parents a63cc4d + 37e1010 commit 4960305
Show file tree
Hide file tree
Showing 31 changed files with 1,236 additions and 680 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: check-yaml
- id: debug-statements
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
Expand All @@ -18,7 +18,7 @@ repos:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.17.0
hooks:
- id: pyupgrade
- repo: https://github.com/hadialqattan/pycln
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ To get in touch with the community and the developers, consider joining the Qibo

[![Matrix](https://img.shields.io/matrix/qibo%3Amatrix.org?logo=matrix)](https://matrix.to/#/#qibo:matrix.org)

If you have a question about the project, please contact us with [📫](mailto:[email protected]).

## Supporters and collaborators

- Quantum Research Center, Technology Innovation Institute (TII), United Arab Emirates
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

334 changes: 280 additions & 54 deletions examples/dbi/dbi_tutorial_basic_intro.ipynb

Large diffs are not rendered by default.

1,082 changes: 574 additions & 508 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "qibo"
version = "0.2.10"
version = "0.2.12"
description = "A framework for quantum computing with hardware acceleration."
authors = ["The Qibo team"]
license = "Apache License 2.0"
Expand Down Expand Up @@ -34,8 +34,8 @@ 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 }
qulacs = { version = "^0.6.4", optional = true, markers="(sys_platform == 'darwin' and python_version > '3.9') or sys_platform != 'darwin'"}
torch = { version = "^2.1.1,<2.4", optional = true }
qulacs = { version = "^0.6.4", optional = true, markers = "(sys_platform == 'darwin' and python_version > '3.9') or sys_platform != 'darwin'" }

[tool.poetry.group.dev]
optional = true
Expand All @@ -56,7 +56,7 @@ sphinx-markdown-tables = "^0.0.17"
sphinx-copybutton = "^0.5.2"
nbsphinx = "^0.8.12"
ipython = "^8.10.0"
qulacs = { version = "^0.6.4", markers="(sys_platform == 'darwin' and python_version > '3.9') or sys_platform != 'darwin'"}
qulacs = { version = "^0.6.4", markers = "(sys_platform == 'darwin' and python_version > '3.9') or sys_platform != 'darwin'" }
seaborn = "^0.13.2"
ipykernel = "^6.29.4"
qibojit = { git = "https://github.com/qiboteam/qibojit.git" }
Expand All @@ -73,11 +73,11 @@ 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"
torch = "^2.1.1,<2.4"
qibojit = { git = "https://github.com/qiboteam/qibojit.git" }
qibotn = { git = "https://github.com/qiboteam/qibotn.git" }
stim = "^1.12.0"
qulacs = { version = "^0.6.4", markers="(sys_platform == 'darwin' and python_version > '3.9') or sys_platform != 'darwin'" }
qulacs = { version = "^0.6.4", markers = "(sys_platform == 'darwin' and python_version > '3.9') or sys_platform != 'darwin'" }

[tool.poe.tasks]
test = "pytest"
Expand All @@ -88,7 +88,6 @@ docs-clean = "make -C doc clean"
test-docs = "make -C doc doctest"



[tool.poetry.group.cuda11]
optional = true

Expand All @@ -112,6 +111,7 @@ qibotn = { git = "https://github.com/qiboteam/qibotn.git" }
tensorflow = ["tensorflow"]
torch = ["torch"]
qinfo = ["stim"]
qulacs = ["qulacs"]

[tool.pylint.main]
ignored-modules = ["cvxpy"]
Expand Down
22 changes: 14 additions & 8 deletions src/qibo/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from qibo.config import log, raise_error

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


class MetaBackend:
Expand Down Expand Up @@ -195,10 +194,10 @@ def _check_backend(backend):
return backend


def list_available_backends() -> dict:
def list_available_backends(*providers: str) -> dict:
"""Lists all the backends that are available."""
available_backends = MetaBackend().list_available()
for backend in QIBO_NON_NATIVE_BACKENDS:
for backend in providers:
try:
module = import_module(backend.replace("-", "_"))
available = getattr(module, "MetaBackend")().list_available()
Expand All @@ -210,22 +209,29 @@ def list_available_backends() -> dict:

def construct_backend(backend, **kwargs) -> Backend:
"""Construct a generic native or non-native qibo backend.
Args:
backend (str): Name of the backend to load.
kwargs (dict): Additional arguments for constructing the backend.
Returns:
qibo.backends.abstract.Backend: The loaded backend.
"""
if backend in QIBO_NATIVE_BACKENDS + ("clifford",):
return MetaBackend.load(backend, **kwargs)
elif backend in QIBO_NON_NATIVE_BACKENDS:
module = import_module(backend.replace("-", "_"))

provider = backend.replace("-", "_")
try:
module = import_module(provider)
return getattr(module, "MetaBackend").load(**kwargs)
else:
except ImportError as e:
# pylint: disable=unsupported-membership-test
if provider not in e.msg:
raise e
raise_error(
ValueError,
f"Backend {backend} is not available. To check which backends are installed use `qibo.list_available_backends()`.",
f"The '{backend}' backends' provider is not available. Check that a Python "
f"package named '{provider}' is installed, and it is exposing valid Qibo "
"backends.",
)


Expand Down
1 change: 1 addition & 0 deletions src/qibo/backends/clifford.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def apply_channel(self, channel, state, nqubits):
index = self.np.random.choice(
range(len(probabilities)), size=1, p=probabilities
)[0]
index = int(index)
if index != len(channel.gates):
gate = channel.gates[index]
state = gate.apply_clifford(self, state, nqubits)
Expand Down
2 changes: 0 additions & 2 deletions src/qibo/backends/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,7 @@ def aggregate_shots(self, shots):
return self.cast(shots, dtype=shots[0].dtype)

def samples_to_binary(self, samples, nqubits):
### This is faster just staying @ NumPy.
qrange = np.arange(nqubits - 1, -1, -1, dtype=np.int32)
samples = self.to_numpy(samples)
return np.mod(np.right_shift(samples[:, None], qrange), 2)

def samples_to_decimal(self, samples, nqubits):
Expand Down
4 changes: 4 additions & 0 deletions src/qibo/gates/gates.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,10 @@ def __init__(self, q, phi, trainable=True):
def qasm_label(self):
return "gpi2"

@property
def clifford(self):
return _is_clifford_given_angle(self.parameters[0])

def _dagger(self) -> "Gate":
""""""
return self.__class__(self.target_qubits[0], self.parameters[0] + math.pi)
Expand Down
11 changes: 6 additions & 5 deletions src/qibo/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ def samples(self, binary=True, registers=False):
# calculate samples for the whole circuit so that
# individual register samples are registered here
self.circuit.final_state.samples()

if binary:
return self._samples
else:
qubits = self.measurement_gate.target_qubits
return self.backend.samples_to_decimal(self._samples, len(qubits))

qubits = self.measurement_gate.target_qubits
return self.backend.samples_to_decimal(self._samples, len(qubits))

def frequencies(self, binary=True, registers=False):
"""Returns the frequencies of measured samples.
Expand All @@ -198,8 +199,8 @@ def frequencies(self, binary=True, registers=False):
if binary:
qubits = self.measurement_gate.target_qubits
return frequencies_to_binary(self._frequencies, len(qubits))
else:
return self._frequencies

return self._frequencies

def apply_bitflips(self, p0, p1=None): # pragma: no cover
return apply_bitflips(self, p0, p1)
Loading

0 comments on commit 4960305

Please sign in to comment.