Skip to content

Move Task queuing to Taskhubs - #80

Merged
dotsdl merged 28 commits into
OpenFreeEnergy:mainfrom
hmacdope:taskhub
Feb 14, 2023
Merged

Move Task queuing to Taskhubs#80
dotsdl merged 28 commits into
OpenFreeEnergy:mainfrom
hmacdope:taskhub

Conversation

@hmacdope

@hmacdope hmacdope commented Feb 3, 2023

Copy link
Copy Markdown
Collaborator

Fixes #78

Moves task queuing from a linked list with deterministic ordering to a hub-spoke model with stochastic pickup of tasks based on weights.

@dotsdl one key question is that currently the [:ACTIONS] relationships are built only when the tasks are queued (makes sense), meaning weights cannot be set or interrogated before then. This is not explicitly checked for at this stage but are we happy with this limitation?

@hmacdope hmacdope added this to the Release 0.2.0 milestone Feb 3, 2023
@hmacdope
hmacdope requested a review from dotsdl February 3, 2023 04:36
@hmacdope hmacdope changed the title Move Task queing to Taskhubs Move Task queuing to Taskhubs Feb 3, 2023
@codecov-commenter

codecov-commenter commented Feb 3, 2023

Copy link
Copy Markdown

Codecov Report

Base: 90.87% // Head: 91.10% // Increases project coverage by +0.22% 🎉

Coverage data is based on head (1abee2a) compared to base (a76613e).
Patch coverage: 95.34% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #80      +/-   ##
==========================================
+ Coverage   90.87%   91.10%   +0.22%     
==========================================
  Files          42       42              
  Lines        3300     3416     +116     
==========================================
+ Hits         2999     3112     +113     
- Misses        301      304       +3     
Impacted Files Coverage Δ
alchemiscale/interface/client.py 93.63% <ø> (ø)
alchemiscale/interface/api.py 50.32% <20.00%> (ø)
alchemiscale/compute/api.py 74.24% <77.77%> (ø)
alchemiscale/storage/statestore.py 91.90% <92.85%> (+0.44%) ⬆️
alchemiscale/base/client.py 97.36% <100.00%> (ø)
alchemiscale/compute/client.py 100.00% <100.00%> (ø)
alchemiscale/compute/service.py 63.36% <100.00%> (ø)
alchemiscale/storage/models.py 90.29% <100.00%> (ø)
.../integration/compute/client/test_compute_client.py 100.00% <100.00%> (ø)
...integration/compute/client/test_compute_service.py 100.00% <100.00%> (ø)
... and 5 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@hmacdope

hmacdope commented Feb 7, 2023

Copy link
Copy Markdown
Collaborator Author

@dotsdl did you push the changes from our pair session ?

@dotsdl

dotsdl commented Feb 7, 2023

Copy link
Copy Markdown
Member

Apologies, I didn't. Just pushed now.

@dotsdl

dotsdl commented Feb 7, 2023

Copy link
Copy Markdown
Member

I don't know why I don't see the commits here. ⁉️

@dotsdl

dotsdl commented Feb 7, 2023

Copy link
Copy Markdown
Member

I see them on the branch: https://github.com/hmacdope/alchemiscale/tree/taskhub

@dotsdl

dotsdl commented Feb 7, 2023

Copy link
Copy Markdown
Member

Oh nevermind, it's further up because the commits were 18 hours ago. 🤦

Comment thread alchemiscale/storage/statestore.py Outdated
@dotsdl

dotsdl commented Feb 8, 2023

Copy link
Copy Markdown
Member

I can go ahead and fix the merge conflicts here, unless you'd prefer to?

@hmacdope

hmacdope commented Feb 8, 2023

Copy link
Copy Markdown
Collaborator Author

Yep please go ahead. let me know if anything is unclear as we did a bit of renaming.
After merge conflicts resolved I will go through and fix up the test suite and implement the changes we discussed.

  • Add error for querying the weights when they are null or unable to be set because the :ACTIONS relationship is not created.
  • Add a weights interface to action_taskhub_tasks.

Comment thread alchemiscale/storage/statestore.py Outdated
@dotsdl

dotsdl commented Feb 8, 2023

Copy link
Copy Markdown
Member

Okay, think I've got the merge conflicts sorted. Seeing test failures in the claiming method in statestore. Can you address?

@hmacdope

hmacdope commented Feb 8, 2023

Copy link
Copy Markdown
Collaborator Author

Yep for sure.

@hmacdope

hmacdope commented Feb 8, 2023

Copy link
Copy Markdown
Collaborator Author

@dotsdl My tests are hanging locally, I'll investigate

assert task_sks2 == all_task_sks[1:]
assert task_sks[0] in all_task_sks

# TODO: Currently we only allow tasks to be added to a taskhub with an EXTENDS

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This had to be modified due to #84 blocking adding of :EXTENDS tasks using action_tasks. Will be fixed in a separate PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I added the first task in the chain for each of the three transformations in the n4js_preloaded fixture, so now we have multiple tasks to work with for this test.

@hmacdope

Copy link
Copy Markdown
Collaborator Author

@dotsdl I think this is probably ready for another review 😃

Simplified where possible, adjustments to docs, grouping queries under
transactions, etc.

@dotsdl dotsdl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great work @hmacdope! Some comments, but none blocking. Pushing my changes noted then proceeding to merge.

Comment thread alchemiscale/storage/statestore.py Outdated
Comment on lines +864 to +868
depth = lambda L: isinstance(L, list) and max(map(depth, L)) + 1
if depth(tasks) > 1:
raise ValueError(
"tasks must be a flat list of ScopedKeys, list with depth > 1 not allowed"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure this is strictly necessary, since we say we need a List[ScopedKey] for tasks in the signature; I think this is fast though so should be okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also this is deep in the storage layer, so by this point we shouldn't have to make too many sanity checks here; just adds expense.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I agree, too internal to need this kind of sanity checking.

Comment thread alchemiscale/storage/statestore.py Outdated
SET ar.weight = {w}
RETURN ar
"""
with self.transaction() as tx:

@dotsdl dotsdl Feb 14, 2023

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Moved transaction outside of loop to use a single transaction for all operations.

Comment thread alchemiscale/storage/statestore.py Outdated
with self.transaction() as tx:
tx.run(q)

# TODO: add exception for nothing returned for matches, or some Tasks missing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added return of Tasks we set weights for; None for those we did not.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

👍

Comment thread alchemiscale/storage/statestore.py Outdated

def get_task_weights(
self, tasks: List[ScopedKey], taskhub: ScopedKey
) -> Dict[ScopedKey, float]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Switched this over to return List[Union[float, None]] to allow for case where a Task ScopedKey is given but doesn't resolve to an actual Task.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

👍


def claim_taskqueue_tasks(
self, taskqueue: ScopedKey, claimant: str, count: int = 1
def get_taskhub_unclaimed_tasks(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have a use case for this method in mind? I'm fine with leaving it in, but not sure we use it anywhere yet?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, we do use it in tests; this is fine.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I was anticipating it might be useful for tests as you saw, but also possibly if one wanted to query what tasks are still waiting on the TaskHub eg for checks on the total volume of work etc. Can always YAGNI it away if not needed.

assert task_sks2 == all_task_sks[1:]
assert task_sks[0] in all_task_sks

# TODO: Currently we only allow tasks to be added to a taskhub with an EXTENDS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I added the first task in the chain for each of the three transformations in the n4js_preloaded fixture, so now we have multiple tasks to work with for this test.

assert all([i is None for i in task_sks_fail])

def test_cancel_task(self, n4js, network_tyk2, scope_test):
def test_action_task_nested_fails(self, n4js: Neo4jStore, network_tyk2, scope_test):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure we really need this test; see comments on action_tasks check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yep makes sense

@dotsdl
dotsdl merged commit 3378128 into OpenFreeEnergy:main Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restructure TaskQueue system to use TaskHubs

3 participants