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

Workflows #7

Merged
merged 19 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Tests

on:
workflow_dispatch:
push:
merge_group:

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, "3.10", "3.11"]
uses: qiboteam/workflows/.github/workflows/rules-poetry.yml@main
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
doctests: false
poetry-extras: --all-extras
secrets: inherit
29 changes: 29 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Reference docs at:
# https://docs.codecov.io/docs/codecovyml-reference

codecov:
require_ci_to_pass: yes
coverage:
precision: 2
round: down
range: "70...100"
status:
project:
default:
threshold: 1%

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: no

github_checks:
annotations: false
2,068 changes: 2,068 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@ readme = "README.md"
packages = [{ include = "qiboml", from = "src" }]

[tool.poetry.dependencies]
python = "^3.9"
python = ">=3.9,<3.12"
numpy = "^1.26.4"
numba = "^0.59.0"
tensorflow = { version = "^2.16.1", markers = "sys_platform == 'linux' or sys_platform == 'darwin'" }
# TODO: the marker is a temporary solution due to the lack of the tensorflow-io 0.32.0's wheels for Windows, this package is one of
# the tensorflow requirements
qibo = "^0.2.6"

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

[tool.poetry.group.dev.dependencies]
ipython = "^7.34"
pdbpp = "^0.10.3"

[tool.poetry.group.benchmark.dependencies]
pytest = "^8.0.0"
pytest = "^7.1.2"
pylint = "^2.17"
pytest-cov = "^3.0.0"
pytest-env = "^0.8.1"
pytest-benchmark = { version = "^4.0.0", extras = ["histogram"] }

[tool.poe.tasks]
bench = "pytest benchmarks/"
test = "pytest"
lint = "pylint src/**/*.py -E"
lint-warnings = "pylint src/**/*.py --exit-zero"

[tool.pytest.ini_options]
testpaths = ['tests/', 'benchmarks/']
Expand All @@ -36,4 +49,9 @@ addopts = [
"--benchmark-warmup-iterations=100000",
"--benchmark-disable-gc",
"--benchmark-histogram=bench-hists/bench",
]
'--cov=qiboml',
'--cov-append',
'--cov-report=xml',
'--cov-report=html',
'--durations=60',
]
3 changes: 3 additions & 0 deletions src/qiboml/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import importlib.metadata as im

__version__ = im.version(__package__)
21 changes: 7 additions & 14 deletions src/qiboml/backends/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import numpy as np

from qibo import __version__
from qibo.backends.npmatrices import NumpyMatrices
from qibo.backends.numpy import NumpyBackend
Expand All @@ -14,7 +13,6 @@ class TensorflowMatrices(NumpyMatrices):

def __init__(self, dtype):
super().__init__(dtype)

import tensorflow as tf # pylint: disable=import-error
import tensorflow.experimental.numpy as tnp # pylint: disable=import-error

Expand Down Expand Up @@ -95,9 +93,6 @@ def to_numpy(self, x):
def compile(self, func):
return self.tf.function(func)

def customize_gradient(self, func):
return self.tf.custom_gradient(func)

def zero_state(self, nqubits):
idx = self.tf.constant([[0]], dtype="int32")
state = self.tf.zeros((2**nqubits,), dtype=self.dtype)
Expand Down Expand Up @@ -203,18 +198,16 @@ def calculate_hamiltonian_state_product(self, matrix, state):
else:
raise_error(
ValueError,
"Cannot multiply Hamiltonian with " "rank-{} tensor.".format(rank),
f"Cannot multiply Hamiltonian with rank-{rank} tensor.",
)

return expectation_with_custom_gradient(params)

def test_regressions(self, name):
if name == "test_measurementresult_apply_bitflips":
return [
[4, 0, 0, 1, 0, 2, 2, 4, 4, 0],
[4, 0, 0, 1, 0, 2, 2, 4, 4, 0],
[4, 0, 0, 1, 0, 0, 0, 4, 4, 0],
[4, 0, 0, 0, 0, 0, 0, 4, 4, 0],
[4, 0, 0, 1, 0, 0, 1, 0, 0, 0],
[0, 1, 1, 2, 1, 1, 4, 0, 0, 4],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 4, 0, 0, 0, 4],
]
elif name == "test_probabilistic_measurement":
if "GPU" in self.device: # pragma: no cover
Expand All @@ -229,6 +222,6 @@ def test_regressions(self, name):
elif name == "test_post_measurement_bitflips_on_circuit":
return [
{5: 30},
{5: 16, 7: 10, 6: 2, 3: 1, 4: 1},
{3: 6, 5: 6, 7: 5, 2: 4, 4: 3, 0: 2, 1: 2, 6: 2},
{5: 12, 7: 6, 4: 6, 1: 5, 6: 1},
{3: 7, 6: 4, 2: 4, 7: 4, 0: 4, 5: 3, 4: 2, 1: 2},
]
2 changes: 1 addition & 1 deletion src/qiboml/differentiation/psr.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def expectation_on_backend(
exec_backend = construct_backend(backend)

if "tensorflow" in frontend.name:
import tensorflow as tf
import tensorflow as tf # pylint: disable=import-error

@tf.custom_gradient
def _expectation_with_tf(params):
Expand Down
91 changes: 0 additions & 91 deletions src/qiboml/test_reuploading.py

This file was deleted.

14 changes: 14 additions & 0 deletions tests/test_models_reuploading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from qiboml.models.reuploading.fourier import FourierReuploading
from qiboml.models.reuploading.u3 import ReuploadingU3

NQUBITS = 3
NLAYERS = 2
DATADIM = (3,)


def test_reuloading_u3():
model = ReuploadingU3(nqubits=NQUBITS, nlayers=NLAYERS, data_dimensionality=DATADIM)
init_angles = model.circuit.get_parameters()
model.inject_data((0.4, 0.5, 0.6))
new_angles = model.circuit.get_parameters()
assert init_angles != new_angles
Loading