Coverage for ibllib/misc/misc.py: 50%

22 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-08 17:16 +0100

1# library of small functions 

2import logging 

3import subprocess 

4 

5import numpy as np 

6 

7from ibllib.exceptions import NvidiaDriverNotReady 

8 

9_logger = logging.getLogger(__name__) 

10 

11 

12def _parametrized(dec): 

13 def layer(*args, **kwargs): 

14 def repl(f): 

15 return dec(f, *args, **kwargs) 

16 return repl 

17 return layer 

18 

19 

20def structarr(names, shape=None, formats=None): 

21 if not formats: 1abcdefghijklmnopqrstuvwx

22 formats = ['f8'] * len(names) 

23 dtyp = np.dtype({'names': names, 'formats': formats}) 1abcdefghijklmnopqrstuvwx

24 return np.zeros(shape, dtype=dtyp) 1abcdefghijklmnopqrstuvwx

25 

26 

27def check_nvidia_driver(): 

28 """ 

29 Checks if the GPU driver reacts and otherwise raises a custom error. 

30 Useful to check before long GPU-dependent processes. 

31 """ 

32 process = subprocess.Popen('nvidia-smi', shell=True, stdout=subprocess.PIPE, 

33 stderr=subprocess.PIPE, executable="/bin/bash") 

34 info, error = process.communicate() 

35 if process.returncode != 0: 

36 raise NvidiaDriverNotReady(f"{error.decode('utf-8')}") 

37 _logger.info("nvidia-smi command successful")