-
Notifications
You must be signed in to change notification settings - Fork 123
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
Implementation of taskvine allpairs/map/reduce #4011
Merged
btovar
merged 13 commits into
cooperative-computing-lab:master
from
RamenMode:futures_executor_feature
Jan 30, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
658c212
Implementation of taskvine allpairs/map/reduce
378aa52
lint
586d7f9
lint v2
5788321
cleanup code
btovar 3b9d8a4
cleanup reduce
btovar fe44574
add test
btovar fb342bd
remove debug print
btovar 7048609
cleanup map
btovar 81a13ec
format
btovar 06dd5f8
allpairs in terms of map
btovar ef3f742
format
btovar 190a6fa
do not create lib in map
btovar e5fe9f7
error on lib name
btovar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
. ../../dttools/test/test_runner_common.sh | ||
|
||
import_config_val CCTOOLS_PYTHON_TEST_EXEC | ||
import_config_val CCTOOLS_PYTHON_TEST_DIR | ||
|
||
export PYTHONPATH=$(pwd)/../../test_support/python_modules/${CCTOOLS_PYTHON_TEST_DIR}:$PYTHONPATH | ||
|
||
STATUS_FILE=vine.status | ||
PORT_FILE=vine.port | ||
|
||
check_needed() | ||
{ | ||
[ -n "${CCTOOLS_PYTHON_TEST_EXEC}" ] || return 1 | ||
|
||
# Poncho currently requires ast.unparse to serialize the function, | ||
# which only became available in Python 3.9. Some older platforms | ||
# (e.g. almalinux8) will not have this natively. | ||
"${CCTOOLS_PYTHON_TEST_EXEC}" -c "from ast import unparse" || return 1 | ||
|
||
# In some limited build circumstances (e.g. macos build on github), | ||
# poncho doesn't work due to lack of conda-pack or cloudpickle | ||
"${CCTOOLS_PYTHON_TEST_EXEC}" -c "import conda_pack" || return 1 | ||
"${CCTOOLS_PYTHON_TEST_EXEC}" -c "import cloudpickle" || return 1 | ||
|
||
return 0 | ||
} | ||
|
||
prepare() | ||
{ | ||
rm -f $STATUS_FILE | ||
rm -f $PORT_FILE | ||
return 0 | ||
} | ||
|
||
run() | ||
{ | ||
( ${CCTOOLS_PYTHON_TEST_EXEC} vine_python_future_hof.py $PORT_FILE; echo $? > $STATUS_FILE ) & | ||
|
||
# wait at most 15 seconds for vine to find a port. | ||
wait_for_file_creation $PORT_FILE 15 | ||
|
||
run_taskvine_worker $PORT_FILE worker.log --cores 2 --memory 2000 --disk 2000 | ||
|
||
# wait for vine to exit. | ||
wait_for_file_creation $STATUS_FILE 15 | ||
|
||
# retrieve exit status | ||
status=$(cat $STATUS_FILE) | ||
if [ $status -ne 0 ] | ||
then | ||
# display log files in case of failure. | ||
logfile=$(latest_vine_debug_log) | ||
if [ -f ${logfile} ] | ||
then | ||
echo "master log:" | ||
cat ${logfile} | ||
fi | ||
|
||
if [ -f worker.log ] | ||
then | ||
echo "worker log:" | ||
cat worker.log | ||
fi | ||
|
||
exit 1 | ||
fi | ||
|
||
exit 0 | ||
} | ||
|
||
clean() | ||
{ | ||
rm -f $STATUS_FILE | ||
rm -f $PORT_FILE | ||
rm -rf vine-run-info | ||
exit 0 | ||
} | ||
|
||
|
||
dispatch "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#! /usr/bin/env python | ||
|
||
import sys | ||
import ndcctools.taskvine as vine | ||
|
||
port_file = None | ||
try: | ||
port_file = sys.argv[1] | ||
except IndexError: | ||
sys.stderr.write("Usage: {} PORTFILE\n".format(sys.argv[0])) | ||
raise | ||
|
||
def main(): | ||
executor = vine.FuturesExecutor( | ||
port=[9123, 9129], manager_name="vine_hof_test", factory=False | ||
) | ||
|
||
print("listening on port {}".format(executor.manager.port)) | ||
with open(port_file, "w") as f: | ||
f.write(str(executor.manager.port)) | ||
|
||
nums = list(range(101)) | ||
|
||
rows = 3 | ||
mult_table = executor.allpairs(lambda x, y: x*y, range(rows), nums, chunk_size=11).result() | ||
assert sum(mult_table[1]) == sum(nums) | ||
assert sum(sum(r) for r in mult_table) == sum(sum(nums) * n for n in range(rows)) | ||
|
||
doubles = executor.map(lambda x: 2*x, nums, chunk_size=10).result() | ||
assert sum(doubles) == sum(nums)*2 | ||
|
||
doubles = executor.map(lambda x: 2*x, nums, chunk_size=13).result() | ||
assert sum(doubles) == sum(nums)*2 | ||
|
||
maximum = executor.reduce(max, nums, fn_arity=2).result() | ||
assert maximum == 100 | ||
|
||
maximum = executor.reduce(max, nums, fn_arity=25).result() | ||
assert maximum == 100 | ||
|
||
maximum = executor.reduce(max, nums, fn_arity=1000).result() | ||
assert maximum == 100 | ||
|
||
maximum = executor.reduce(max, nums, fn_arity=2, chunk_size=50).result() | ||
assert maximum == 100 | ||
|
||
minimum = executor.reduce(min, nums, fn_arity=2, chunk_size=50).result() | ||
assert minimum == 0 | ||
|
||
total = executor.reduce(sum, nums, fn_arity=11, chunk_size=13).result() | ||
assert total == sum(nums) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
|
||
# vim: set sts=4 sw=4 ts=4 expandtab ft=python: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we add tests for libraries/function calls here as well?
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.
It seems that library calls don't work with futures right 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.
Mmm, no, the test for funcall future calls works.
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.
Ok, the issue is that the auxiliary functions to run chunks will not be in the library constructed by the user. I guess we can always add them to all libraries that are created?
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.
@tphung3 libraries cannot be used right now. The issue is that we cannot compose functions in a library and these high order functions would need to construct the event structure to pass the correct arguments for remote execution.
We could make it work for this case, but I think we would be better if we come up with something more general.
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'm good with that as long as we have a safeguard of not using functions atm. I see that the code raises error if library is used so that should be safe enough for users.