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

Add getters and setters for Task priority in AlchemiscaleClient #213

Merged
merged 21 commits into from
Dec 21, 2023

Conversation

ianmkenney
Copy link
Collaborator

Fixes #200

This PR implements the set_tasks_priority and get_tasks_priority methods of the AlchemiscaleClient.

@codecov-commenter
Copy link

codecov-commenter commented Dec 5, 2023

Codecov Report

Attention: 28 lines in your changes are missing coverage. Please review.

Comparison is base (8e98af3) 81.76% compared to head (9e22c8c) 81.89%.

Files Patch % Lines
alchemiscale/interface/api.py 16.00% 21 Missing ⚠️
alchemiscale/interface/client.py 84.09% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #213      +/-   ##
==========================================
+ Coverage   81.76%   81.89%   +0.12%     
==========================================
  Files          22       22              
  Lines        2781     2834      +53     
==========================================
+ Hits         2274     2321      +47     
- Misses        507      513       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

The reversed naming was deliberate.

This reverts commit 6208602.
Implemented
* tasks_get_priority (api)
* _get_task_priority (client)
* get_tasks_priority (client)
* get_task_priority  (state store)
* test_get_tasks_priority (client integration)
Copy link
Member

@dotsdl dotsdl left a comment

Choose a reason for hiding this comment

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

Looking good so far @ianmkenney! Definitely on the right track.

return list(chain.from_iterable(priorities))

try:
return asyncio.run(async_request(self))
Copy link
Member

Choose a reason for hiding this comment

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

Generally better to create the async_request(self) coroutine outside of here, because if asyncio.run fails (such as in a Jupyter notebook), then the Python interpreter will complain about an unexecuted coroutine hanging around.

Copy link
Member

Choose a reason for hiding this comment

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

I see I didn't do that for get_tasks_status, but did for set_tasks_status. You're welcome to propagate that practice there too in this PR.

Since the code for the status and priority methods for Tasks are practically identical, this may also be an opportunity to create generalized methods that both the status and priority getters and setters can use.

@ianmkenney
Copy link
Collaborator Author

Waiting for #212 to be merged. There will be some conflicts that should auto-resolve with a main merge once that's done.

@ianmkenney ianmkenney changed the title [WIP] Add getters and setters for Task priority in AlchemiscaleClient Add getters and setters for Task priority in AlchemiscaleClient Dec 12, 2023
@ianmkenney ianmkenney marked this pull request as ready for review December 12, 2023 19:18
Copy link
Member

@dotsdl dotsdl left a comment

Choose a reason for hiding this comment

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

Looking great @ianmkenney! Thank you for the detailed work here!

There's a few changes I'd like you to pursue before we're good to merge. I think the lion's share of the work is already done, so these are mostly sculpting.

alchemiscale/interface/client.py Show resolved Hide resolved
Comment on lines 874 to 875
"""Set the priority of multiple Tasks.

Copy link
Member

Choose a reason for hiding this comment

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

Can you add a note here on what kind of integers are allowed for priority, and what these values mean? As-in, priority 1 is the highest priority, 2 the next highest, and so on, with the lowest priority allowed being 2**64 / 2 (max value of java long, since this gets stored in Neo4j).

Copy link
Member

@dotsdl dotsdl Dec 21, 2023

Choose a reason for hiding this comment

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

I was wrong about this; max value of a java long is 2**64/2 - 1, or 2**63 - 1. Fixing this myself now.

Copy link
Member

Choose a reason for hiding this comment

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

Also adding guardrail in Neo4jStore.

Comment on lines 1713 to 1718
def set_task_priority(self, task: Union[ScopedKey, List[ScopedKey]], priority: int):
if not priority >= 0:
raise ValueError("priority cannot be negative")

if isinstance(task, ScopedKey):
task = [task]
Copy link
Member

Choose a reason for hiding this comment

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

Just to simplify a bit and make it consistent with other methods, let's axe this method's ability to take a single task, since it avoids the asymmetry of input sometimes being a non-iterable but output always being an iterable.

We generally try to take this pattern at this lowest layer of the stack; it doesn't need to be user-friendly, but we aim for a fairly logical consistency where possible.

This will simplify the tests for these methods as well, reducing the input space.

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add -> List[Optional[ScopedKey]] as the output?

Copy link
Member

Choose a reason for hiding this comment

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

And rename task to tasks. 😁

Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a docstring?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to simplify a bit and make it consistent with other methods, let's axe this method's ability to take a single task, since it avoids the asymmetry of input sometimes being a non-iterable but output always being an iterable.

We generally try to take this pattern at this lowest layer of the stack; it doesn't need to be user-friendly, but we aim for a fairly logical consistency where possible.

This will simplify the tests for these methods as well, reducing the input space.

Agreed. This will require changing compute tests using the single task inputs. I was trying to preserve previous functionality. Might be worthwhile doing a general consistency sweep before the next release.

task_results.append(ScopedKey.from_str(scoped_key))
return task_results

def get_task_priority(self, tasks: List[ScopedKey]) -> List[Optional[int]]:
Copy link
Member

Choose a reason for hiding this comment

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

Please add a docstring here as well!

nest_asyncio.apply()
return asyncio.run(coro)

def _task_attribute_setter(
Copy link
Member

Choose a reason for hiding this comment

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

Glorious!

Comment on lines 874 to 875
"""Set the priority of multiple Tasks.

Copy link
Member

@dotsdl dotsdl Dec 21, 2023

Choose a reason for hiding this comment

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

I was wrong about this; max value of a java long is 2**64/2 - 1, or 2**63 - 1. Fixing this myself now.

Copy link
Member

@dotsdl dotsdl left a comment

Choose a reason for hiding this comment

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

Fantastic work @ianmkenney! I added guardrails and checks for upper bound of priority; will merge following tests passing.

@dotsdl dotsdl merged commit 81d977b into main Dec 21, 2023
4 checks passed
@dotsdl dotsdl deleted the 200-Task-priority-setter-getter branch December 21, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement methods to get and set Task priorities to AlchemiscaleClient
3 participants