Skip to content
Draft
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
4 changes: 4 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Reference docs at https://docs.codecov.com/docs/codecovyml-reference

codecov:
require_ci_to_pass: yes
25 changes: 5 additions & 20 deletions .github/workflows/rules.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
# A single CI script with github workflow
name: Tests

env:
CUDA_PATH:

name: Tests

on:
workflow_dispatch:
push:
pull_request:
types: [labeled]

jobs:
check:
# job to check cuda availability for local gpu host runners
runs-on: ubuntu-latest
steps:
- id: step1
run: echo "test=${{ env.CUDA_PATH != ''}}" >> "$GITHUB_OUTPUT"
- id: step2
run: echo "test=${{ contains(github.event.pull_request.labels.*.name, 'run-workflow') || github.event_name == 'push' }}" >> "$GITHUB_OUTPUT"
outputs:
cuda_avail: ${{ fromJSON(steps.step1.outputs.test) && fromJSON(steps.step2.outputs.test) }}

jobs:
build:
# job to build
needs: check
if: ${{fromJSON(needs.check.outputs.cuda_avail)}}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.9, "3.10", "3.11", "3.12"]
uses: qiboteam/workflows/.github/workflows/rules-poetry.yml@main
python-version: [ 3.9, "3.10", "3.11", "3.12"]
uses: qiboteam/workflows/.github/workflows/rules-poetry.yml@v1
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
Expand Down
24 changes: 18 additions & 6 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cupy-cuda11x = { version = "^11.6.0", optional = true }
cuquantum-python-cu11 = { version = "^23.3.0", optional = true }
mpi4py = { version = "^3.1.5", optional = true }


[tool.poetry.extras]
cuda = ["cupy-cuda11x", "cuquantum-python-cu11", "mpi4py"]

Expand Down
3 changes: 3 additions & 0 deletions src/qibotn/backends/cutensornet.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CuTensorNet(NumpyBackend): # pragma: no cover

def __init__(self, runcard):
super().__init__()
import cuquantum
from cuquantum import cutensornet as cutn # pylint: disable=import-error

if runcard is not None:
Expand All @@ -32,6 +33,7 @@ def __init__(self, runcard):
)
else:
raise TypeError("expectation_enabled has an unexpected type")
state = np.array(0)

mps_enabled_value = runcard.get("MPS_enabled")
if mps_enabled_value is True:
Expand Down Expand Up @@ -192,6 +194,7 @@ def execute_circuit(
state = np.array(0)
else:
raise_error(NotImplementedError, "Compute type not supported.")
state = np.array(0)

if return_array:
return state.flatten()
Expand Down
12 changes: 0 additions & 12 deletions tests/config.py

This file was deleted.

17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""To skip the pytests marked with gpu."""

import os

import pytest

tt = os.system("nvidia-smi")


def pytest_runtest_setup(item):
if tt != 0:
for marker in item.iter_markers(name="gpu"):
pytest.skip(f"test requires gpu")


"""Pytest fixtures.
"""
9 changes: 4 additions & 5 deletions tests/test_cuquantum_cutensor_backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from timeit import default_timer as timer

import config
import cupy as cp
import numpy as np
import pytest
import qibo
Expand Down Expand Up @@ -35,15 +33,14 @@ def test_eval(nqubits: int, dtype="complex128"):
import qibotn.eval

# Test qibo
qibo.set_backend(backend=config.qibo.backend, platform=config.qibo.platform)
qibo.set_backend("numpy")
qibo_time, (qibo_circ, result_sv) = time(lambda: qibo_qft(nqubits, swaps=True))

# Test Cuquantum
cutn_time, result_tn = time(
lambda: qibotn.eval.dense_vector_tn(qibo_circ, dtype).flatten()
)

assert 1e-2 * qibo_time < cutn_time < 1e2 * qibo_time
assert np.allclose(result_sv, result_tn), "Resulting dense vectors do not match"


Expand All @@ -57,10 +54,12 @@ def test_mps(nqubits: int, dtype="complex128"):
dtype (str): The data type for precision, 'complex64' for single,
'complex128' for double.
"""
import cupy as cp

import qibotn.eval

# Test qibo
qibo.set_backend(backend=config.qibo.backend, platform=config.qibo.platform)
qibo.set_backend("numpy")

qibo_time, (circ_qibo, result_sv) = time(lambda: qibo_qft(nqubits, swaps=True))

Expand Down
5 changes: 2 additions & 3 deletions tests/test_quimb_backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import os

import config
import numpy as np
import pytest
import qibo
Expand Down Expand Up @@ -42,7 +41,7 @@ def test_eval(nqubits: int, tolerance: float, is_mps: bool):
init_state_tn = copy.deepcopy(init_state)

# Test qibo
qibo.set_backend(backend=config.qibo.backend, platform=config.qibo.platform)
qibo.set_backend("numpy")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that's even fine by me, but maybe you wanted to change

qibo = Executor(backend="qibojit", platform="numpy")

Otherwise, you can decide to drop that file, and inline the values in the tests (that is a pretty good option).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can drop that file as it is doing nothing. Need to modify cuquantum side also.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I like the latter option because it explicitly avoids the dependency on qibojit.


qibo_circ, result_sv = qibo_qft(nqubits, init_state, swaps=True)

Expand All @@ -58,7 +57,7 @@ def test_eval(nqubits: int, tolerance: float, is_mps: bool):
else:
gate_opt = None
result_tn = qibotn.eval_qu.dense_vector_tn_qu(
qasm_circ, init_state_tn, gate_opt, backend=config.quimb.backend
qasm_circ, init_state_tn, gate_opt, backend="numpy"
).flatten()

assert np.allclose(
Expand Down