Fix Task.query_tasks() specifying pagesize or page number

This commit is contained in:
allegroai 2022-04-27 17:31:40 +03:00
parent 8f5c050fe0
commit 938b5f0e63
2 changed files with 19 additions and 10 deletions

View File

@ -1272,7 +1272,7 @@ class HyperParameterOptimizer(object):
# type: (Optional[Callable[[str, float, int, dict, str], None]]) -> bool # type: (Optional[Callable[[str, float, int, dict, str], None]]) -> bool
""" """
Start the HyperParameterOptimizer controller completely locally. Both the optimizer task Start the HyperParameterOptimizer controller completely locally. Both the optimizer task
and all spawned substasks are ran on the local machine using the current environment. and all spawned substasks are run on the local machine using the current environment.
If the calling process is stopped, then the controller stops as well. If the calling process is stopped, then the controller stops as well.
:param Callable job_complete_callback: Callback function, called when a job is completed. :param Callable job_complete_callback: Callback function, called when a job is completed.

View File

@ -877,6 +877,8 @@ class Task(_Task):
:param str task_name: The full name or partial name of the Tasks to match within the specified :param str task_name: The full name or partial name of the Tasks to match within the specified
``project_name`` (or all projects if ``project_name`` is ``None``). ``project_name`` (or all projects if ``project_name`` is ``None``).
This method supports regular expressions for name matching. (Optional) This method supports regular expressions for name matching. (Optional)
To match an exact task name (i.e. not partial matching),
add ^/$ at the beginning/end of the string, for example: "^exact_task_name_here$"
:param list(str) task_ids: list of unique task id string (if exists other parameters are ignored) :param list(str) task_ids: list of unique task id string (if exists other parameters are ignored)
:param str project_name: project name (str) the task belongs to (use None for all projects) :param str project_name: project name (str) the task belongs to (use None for all projects)
:param str task_name: task name (str) in within the selected project :param str task_name: task name (str) in within the selected project
@ -3736,22 +3738,29 @@ class Task(_Task):
if kwargs and kwargs.get('only_fields'): if kwargs and kwargs.get('only_fields'):
only_fields = list(set(kwargs.pop('only_fields')) | set(only_fields)) only_fields = list(set(kwargs.pop('only_fields')) | set(only_fields))
# if we have specific page to look for, we should only get the requested one
if not fetch_only_first_page and 'page' in kwargs:
fetch_only_first_page = True
ret_tasks = [] ret_tasks = []
page = -1 page = -1
page_size = 500 page_size = 500
while page == -1 or (len(res.response.tasks) == page_size and not fetch_only_first_page): while page == -1 or (len(res.response.tasks) == page_size and not fetch_only_first_page):
page += 1 page += 1
# work on a copy and make sure we override all fields with ours
request_kwargs = dict(
id=task_ids,
project=project_ids if project_ids else kwargs.pop("project", None),
name=task_name if task_name else kwargs.pop("name", None),
only_fields=only_fields,
page=page,
page_size=page_size,
)
# make sure we always override with the kwargs (specifically page selection / page_size)
request_kwargs.update(kwargs or {})
res = cls._send( res = cls._send(
session, session,
tasks.GetAllRequest( tasks.GetAllRequest(**request_kwargs),
id=task_ids,
project=project_ids if project_ids else kwargs.pop("project", None),
name=task_name if task_name else kwargs.pop("name", None),
only_fields=only_fields,
page=page,
page_size=page_size,
**kwargs
),
) )
ret_tasks.extend(res.response.tasks) ret_tasks.extend(res.response.tasks)
return ret_tasks return ret_tasks