-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
Codecov ReportAttention:
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. |
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)
There was a problem hiding this 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.
alchemiscale/interface/client.py
Outdated
return list(chain.from_iterable(priorities)) | ||
|
||
try: | ||
return asyncio.run(async_request(self)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 Task
s are practically identical, this may also be an opportunity to create generalized methods that both the status
and priority
getters and setters can use.
Waiting for #212 to be merged. There will be some conflicts that should auto-resolve with a |
There was a problem hiding this 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
Outdated
"""Set the priority of multiple Tasks. | ||
|
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
alchemiscale/storage/statestore.py
Outdated
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] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
. 😁
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]]: |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glorious!
alchemiscale/interface/client.py
Outdated
"""Set the priority of multiple Tasks. | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Fixes #200
This PR implements the
set_tasks_priority
andget_tasks_priority
methods of theAlchemiscaleClient
.