Skip to content

Commit

Permalink
Merge branch 'master' into entangling_capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomello committed Jan 4, 2024
2 parents 4b15576 + 0eeb6ae commit 48bf93a
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .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: 23.12.0
rev: 23.12.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
Expand Down
4 changes: 1 addition & 3 deletions doc/source/code-examples/advancedexamples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,11 @@ Using density matrices
Qibo circuits can evolve density matrices if they are initialized using the
``density_matrix=True`` flag, for example:

.. testsetup::
.. testcode::

import qibo
qibo.set_backend("qibojit")

.. testcode::

from qibo import models, gates

# Define circuit
Expand Down
132 changes: 82 additions & 50 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pytest-cov = "^4.0.0"
pylint = "^3.0.3"
matplotlib = "^3.7.0"
qibojit = { git = "https://github.com/qiboteam/qibojit.git" }
tensorflow = { version = "^2.15.0", markers = "sys_platform == 'linux'" }
tensorflow = { version = "^2.14.1", markers = "sys_platform == 'linux'" }

[tool.poe.tasks]
test = "pytest"
Expand Down
2 changes: 1 addition & 1 deletion src/qibo/backends/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ def samples_to_binary(self, samples, nqubits):
def samples_to_decimal(self, samples, nqubits):
qrange = self.np.arange(nqubits - 1, -1, -1, dtype="int32")
qrange = (2**qrange)[:, self.np.newaxis]
return self.np.matmul(samples, qrange)[:, 0]
return self.np.matmul(self.to_numpy(samples), qrange)[:, 0]

def calculate_frequencies(self, samples):
res, counts = self.np.unique(samples, return_counts=True)
Expand Down
5 changes: 3 additions & 2 deletions src/qibo/quantum_info/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ def gate_error(channel, target=None, check_unitary: bool = False, backend=None):
return error


def diamond_norm(channel, target=None, **kwargs):
def diamond_norm(channel, target=None, backend=None, **kwargs):
"""Calculates the diamond norm :math:`\\|\\mathcal{E}\\|_{\\diamond}` of
``channel`` :math:`\\mathcal{E}`, which is given by
Expand Down Expand Up @@ -938,7 +938,8 @@ def diamond_norm(channel, target=None, **kwargs):

# `CVXPY` only works with `numpy`, so this function has to
# convert any channel to the `numpy` backend by default
backend = GlobalBackend()
if backend is None: # pragma: no cover
backend = GlobalBackend()
channel = backend.to_numpy(channel)

channel = np.transpose(channel)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_hamiltonians.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_hamiltonian_matmul_states(backend, sparse_type):
else:
if backend.name == "tensorflow":
pytest.skip("Tensorflow does not support operations with sparse matrices.")
nqubits = 5
nqubits = 3
nstates = 2**nqubits
matrix = random_sparse_matrix(backend, nstates, sparse_type)
H = hamiltonians.Hamiltonian(nqubits, matrix, backend=backend)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_quantum_info_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ def test_diamond_norm(backend, nqubits):
unitary = backend.identity_density_matrix(nqubits, normalize=False)
unitary = to_choi(unitary, order="row", backend=backend)

dnorm = diamond_norm(unitary)
dnorm = diamond_norm(unitary, backend=backend)
backend.assert_allclose(dnorm, 1.0, atol=PRECISION_TOL)

dnorm = diamond_norm(unitary, unitary)
dnorm = diamond_norm(unitary, unitary, backend=backend)
backend.assert_allclose(dnorm, 0.0, atol=PRECISION_TOL)


Expand Down

0 comments on commit 48bf93a

Please sign in to comment.