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

fixing CI #420

Merged
merged 2 commits into from
May 24, 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
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
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
Copy link
Member

Choose a reason for hiding this comment

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

Optionally we could also cover the error cases here using:

with pytest.raises(RuntimeError):
    ...

instead of pytest.skip. This way we could remove # pragma: no cover from the errors above and include them in the coverage check.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about it, however then we need to wrap the parallel function call in a if/else condition, right? (and duplicate the test basically)

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I am not sure if it is the best way but this is what I do in a few other tests where I check for similar errors. For these tests I think it is sufficient to do something like:

if 'GPU' in qibo.get_device() or os.name == 'nt' or qibo.get_backend() == "tensorflow":
    with pytest.raises(RuntimeError):
        r2 = parallel_execution(c, states=states, processes=2)
else:
    r2 = parallel_execution(c, states=states, processes=2)
    np.testing.assert_allclose(r1, r2)

so the code duplication is not that large. Not very necessary to do this though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, let's keep as it is, thanks.

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