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

Fix set_device test for GPU #417

Merged
merged 6 commits into from
May 25, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -41,7 +41,7 @@ jobs:
run: |
pytest --cov=qibo --cov-report=xml --pyargs qibo
- name: Test examples
if: startsWith(matrix.os, 'ubuntu') && matrix.python-version == '3.8'
if: startsWith(matrix.os, 'ubuntu') && matrix.python-version == '3.9'
run: |
pytest examples/
- name: Upload coverage to Codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.6, 3.7, 3.8, 3.9]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
Expand Down
12 changes: 6 additions & 6 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Installing with pip

The installation using ``pip`` is the recommended approach to install
``qibotf``. We provide precompiled packages for linux x86/64 and macosx 10.15 or
greater for Python 3.6, 3.7 and 3.8.
greater for Python 3.6, 3.7, 3.8 and 3.9.

In order to install the package use the following command:

Expand Down Expand Up @@ -197,7 +197,7 @@ then proceed with the installation of requirements with:

pip install -r requirements.txt

Make sure your system has a GNU ``g++ >= 6`` compiler. If you are working on
Make sure your system has a GNU ``g++ >= 4`` compiler. If you are working on
macosx make sure the command ``c++`` is ``clang >= 11`` and install the libomp
library with ``brew install libomp`` command.

Expand All @@ -218,11 +218,11 @@ path.

3. make sure the NVCC compiler is available from ``CUDA_PATH/bin/nvcc``, otherwise the compilation may fail. You can locate it with ``whereis nvcc`` and eventually link/copy to your ``CUDA_PATH/bin`` folder.

For example, TensorFlow 2.4 supports CUDA 11. After installing
TensorFlow proceed with the NVCC 11 installation. On linux the
installation path usually is ``/usr/local/cuda-11/``.
For example, TensorFlow 2.5.0 supports CUDA 11.2. After installing
TensorFlow proceed with the NVCC 11.2 installation. On linux the
installation path usually is ``/usr/local/cuda-11.2/``.

Before installing Qibo do ``export CUDA_PATH=/usr/local/cuda-11``.
Before installing Qibo do ``export CUDA_PATH=/usr/local/cuda-11.2``.

Note that Qibo will not enable GPU support if points 1 and 2 are not
performed.
Expand Down
8 changes: 6 additions & 2 deletions src/qibo/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,14 @@ def operation(params, circuit, state): # pragma: no cover

def _check_parallel_configuration(processes):
"""Check if configuration is suitable for efficient parallel execution."""
import psutil
from qibo import get_device
import os, psutil
from qibo import get_device, get_backend
from qibo.config import raise_error, get_threads, log
device = get_device()
if os.name == "nt": # pragma: no cover
raise_error(RuntimeError, "Parallel evaluations not supported on Windows.")
if get_backend() == "tensorflow": # pragma: no cover
raise_error(RuntimeError, "tensorflow backend does not support parallel evaluations.")
if device is not None and "GPU" in device: # pragma: no cover
raise_error(RuntimeError, "Parallel evaluations cannot be used with GPU.")
if ((processes is not None and processes * get_threads() > psutil.cpu_count()) or
Expand Down
6 changes: 3 additions & 3 deletions src/qibo/tests/test_backends_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_set_precision_errors(backend):


def test_set_device(backend):
original_device = backends.get_device()
original_devices = {bk: bk.default_device for bk in K.constructed_backends.values()}
if backends.get_backend() == "numpy":
with pytest.warns(RuntimeWarning):
backends.set_device("/CPU:0")
Expand All @@ -99,8 +99,8 @@ def test_set_device(backend):
backends.set_device("/gpu:10")
with pytest.raises(ValueError):
backends.set_device("/GPU:10")
if original_device:
backends.set_device(original_device)
for bk, device in original_devices.items():
bk.set_device(device)


def test_set_shot_batch_size():
Expand Down
2 changes: 2 additions & 0 deletions src/qibo/tests/test_models_variational.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def test_vqe(backend, method, options, compile, filename):

if method == 'parallel_L-BFGS-B':
device = qibo.get_device()
if qibo.get_backend() == "tensorflow":
pytest.skip("unsupported backend")
if device is not None and "GPU" in device: # pragma: no cover
pytest.skip("unsupported configuration")
import os
Expand Down
4 changes: 2 additions & 2 deletions src/qibo/tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

def test_parallel_circuit_evaluation(backend):
"""Evaluate circuit for multiple input states."""
if 'GPU' in qibo.get_device() or os.name == 'nt': # pragma: no cover
if 'GPU' in qibo.get_device() or os.name == 'nt' or qibo.get_backend() == "tensorflow": # pragma: no cover
pytest.skip("unsupported configuration")
original_threads = qibo.get_threads()
qibo.set_threads(1)
Expand All @@ -34,7 +34,7 @@ def test_parallel_circuit_evaluation(backend):

def test_parallel_parametrized_circuit(backend):
"""Evaluate circuit for multiple parameters."""
if 'GPU' in qibo.get_device() or os.name == 'nt': # pragma: no cover
if 'GPU' in qibo.get_device() or os.name == 'nt' or qibo.get_backend() == "tensorflow": # pragma: no cover
pytest.skip("unsupported configuration")
original_threads = qibo.get_threads()
qibo.set_threads(1)
Expand Down