diff --git a/nbtools/core.py b/nbtools/core.py index 4ef62e3..4151861 100755 --- a/nbtools/core.py +++ b/nbtools/core.py @@ -139,7 +139,8 @@ def get_available_gpus(n=1, min_free_memory=0.9, max_processes=2, verbose=False, Returns ------- - List with indices of available GPUs + available_devices : list + Indices of available GPUs. """ try: import nvidia_smi @@ -215,6 +216,11 @@ def set_gpus(n=1, min_free_memory=0.9, max_processes=2, verbose=False, raise_err If 2, then display memory and process information for each device. raise_error : bool Whether to raise an exception if not enough devices are available. + + Returns + ------- + devices : list + Indices of selected and reserved GPUs. """ #pylint: disable=consider-iterating-dictionary if 'CUDA_VISIBLE_DEVICES' in os.environ.keys(): diff --git a/nbtools/nbstat/cli.py b/nbtools/nbstat/cli.py index a77465f..7c51b74 100755 --- a/nbtools/nbstat/cli.py +++ b/nbtools/nbstat/cli.py @@ -269,7 +269,7 @@ def devicewatch(): } def make_parameters(name): - """ Parse parameters from command line into dictionary. + """ Parse parameters from the command line into a dictionary. Use `store_const` instad of `store_true` to keep `None` values, if not passed explicitly """ # Set defaults diff --git a/nbtools/nbstat/resource_formatter.py b/nbtools/nbstat/resource_formatter.py index 198e8db..746c17b 100755 --- a/nbtools/nbstat/resource_formatter.py +++ b/nbtools/nbstat/resource_formatter.py @@ -8,7 +8,7 @@ class ResourceFormatter(list): """ An ordered sequence to define which resources to request from the system, as well as - how to structure them into formatted table. + how to structure them into a formatted table. Each element is a dictionary with mandatory `resource` and `include` keys, and defines whether this `resource` must be fetched/included in the table based on the value of `include` flag. @@ -86,7 +86,7 @@ def update(self, other=None, **kwargs): self.extend(other) def copy(self): - """ Deep copy of the formatter. Used to not mess up the original formatter. """ + """ Deep copy of the formatter. Used to avoid messing up the original formatter. """ return deepcopy(self) def include_all(self): @@ -96,7 +96,7 @@ def include_all(self): @property def included_only(self): - """ Return formatter with elements which `include` flag is set to True. + """ Return the formatter, including only the elements where the `include` flag is set to True. Also removes subsequent duplicates of table delimiters. """ formatter = [] diff --git a/nbtools/nbstat/resource_inspector.py b/nbtools/nbstat/resource_inspector.py index 9c71e01..baf0d59 100755 --- a/nbtools/nbstat/resource_inspector.py +++ b/nbtools/nbstat/resource_inspector.py @@ -1,4 +1,6 @@ -""" Controlling class for fetching tables with system information, merging them into view and displaying in stream. """ +""" Controlling class for fetching tables with system information, +merging them into a view and displaying in a stream. +""" import os import re import json @@ -212,7 +214,7 @@ def get_python_pids(self): def get_process_table(self, formatter=None): """ Collect information about all Python processes. - Information varies from properties of a process (its path, PID, NGID, status, etc) to system resource usage like + Information varies from process properties (its path, PID, NGID, status, etc) to system resource usage like CPU utilization or RSS. The table also includes some inferred columns like type and kernel_id. Some of the fields are intentionally left blank / with meaningless defaults: those are supposed to be filled by @@ -489,7 +491,7 @@ def nbstat_check_device_pids(self, device_pids, table, add_to_table=True): def devicestat_check_device_pids(self, table): """ Check if some of the `device pids` are not matched to any Python processes. - Add template names to them insted of empty ones. + Add template names to them instead of empty ones. """ self.warnings['missing_device_pids'] = set() for entry in table: diff --git a/nbtools/nbstat/resource_table.py b/nbtools/nbstat/resource_table.py index 09e0850..6a9cbd9 100755 --- a/nbtools/nbstat/resource_table.py +++ b/nbtools/nbstat/resource_table.py @@ -1,6 +1,6 @@ """ ResourceEntry -- a dict-like class to hold all properties (Resources) of an entry. ResourceTable -- sequence of multiple ResourceEntries with interface of merging, updating, sorting for multiple tables. -Can be formatted into beautiful colored string representation by using `format` method. +Can be formatted into a beautiful colored string representation by using `format` method. """ from .resource import Resource @@ -18,7 +18,7 @@ class ResourceTable: versions for working with tables with defined `index`. For the most part, this class acts as a lightweight version of a`Pandas.DataFrame`: it saves us a huge dependency - and also allows to tweak some of the metods to our needs. As our tables are tiny, efficiency is not a concern. + and also allows to tweak some of the methods to our needs. As our tables are tiny, efficiency is not a concern. If the `pandas` is already installed, `ResourceTable` can be converted to dataframe by using `to_pd` method. Also provides method `format` for table visualization as a beautiful colored string representation. @@ -313,7 +313,7 @@ def filter_by_index(self, condition, inplace=True): def filter_on_index(self, condition, inplace=True): """ Filter subtables and index values, based on `condition`, evaluated on them. - Keep only those which evaluate to True. + Keep only those that evaluate to True. """ self = self.maybe_copy(return_self=inplace) @@ -359,7 +359,7 @@ def __str__(self): return repr('\n'.join([str(entry) for entry in self.data])) def to_format_data(self, resource, terminal, **kwargs): - """ Create a string template and data for a given `resource` column from entire table. + """ Create a string template and data for a given `resource` column from the entire table. Works by aggregation information in the `resource` column and making string from it. For more information about formatting refer to `ResourceTable.format` method. @@ -394,8 +394,8 @@ def format(self, terminal, formatter, hide_similar=True, text formatting, and it is enough to format the string from entries. The header string is produced by (`style` + `name`). - - then we iterate over entries in the table. Each entry is requested to create a `style` and `string` for - current resource: that is done by the `ResourceEntry.to_format_data` method. + - then we iterate over the entries in the table. Each entry is requested to create a `style` and `string` + for the current resource: that is done by the `ResourceEntry.to_format_data` method. Note that we can't use just the resource and its value from the entry to create the `string`, as some of the columns require multiple items: for example, device memory requires current and total values. `style`, returned by the entry, can completely override the style from the Resource, but for the most cases,