-
Notifications
You must be signed in to change notification settings - Fork 22
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
Blue/executor split #365
Merged
Merged
Blue/executor split #365
Changes from 31 commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
fe7cb1b
+ comment to "decrease-scores" strategy
shadeofblue 6da6bff
splitting executor...
shadeofblue 46479f3
Merge branch 'master' into blue/executor-split
shadeofblue cea1705
s/Engine/Golem/
shadeofblue dc8a2ac
Merge branch 'master' into blue/executor-split
shadeofblue 0857796
Merge remote-tracking branch 'origin/master' into blue/executor-split
azawlocki a617f40
Add method Golem.create_demand_builder()
azawlocki 91ad481
Make Job a toplevel class
azawlocki d240e14
Add Golem.create_activity(), add Activity._stream_events field
azawlocki 9337107
move `agreements_pool` to Job
shadeofblue 38a0148
Working blender example (without payments-related features)
azawlocki 3315794
Merge branch 'blue/executor-split' of github.com:golemfactory/yapapi …
azawlocki feb956d
move payment methods to `Golem`
shadeofblue 2dbf655
Merge branch 'blue/executor-split' of github.com:golemfactory/yapapi …
shadeofblue 9c3e6af
move debit note and invoice processing to `Golem`
shadeofblue 0794947
use `payload` instead of `package` when instantiating the Executor
shadeofblue 79d4e89
Move `process_batches()` from `Executor` to `Golem`
azawlocki 5eafa01
Make Executor backward compatible, so that original blender.py works
azawlocki d4ed1ef
Merge branch 'master' into blue/executor-split
shadeofblue 907b97a
Merge branch 'blue/executor-split' of github.com:golemfactory/yapapi …
shadeofblue e131548
move `storage_manager` to Golem
shadeofblue de300fc
bug
shadeofblue 2199cd4
Merge branch 'master' into blue/executor-split
shadeofblue e51ef68
rename the "old" `blender.py` to `blener-deprecated.py`
shadeofblue 7429ed9
Golem.execute_task() -> Golem.execute_tasks() & other minor changes
azawlocki 71181ce
Merge branch 'blue/executor-split' of github.com:golemfactory/yapapi …
azawlocki 142d3a3
black
shadeofblue c53903c
Merge branch 'master' into blue/executor-split
shadeofblue 9d8a9a3
move `execute_tasks` to the end of `Golem`
shadeofblue 8c13ca0
Fixes in executor/__init__.py to pass unit tests
azawlocki 5dac94b
Merge branch 'blue/executor-split' of github.com:golemfactory/yapapi …
azawlocki b0df49c
Changes in events/SummaryLogger to run yacat withour errors
azawlocki b1627de
Update yapapi/executor/__init__.py
shadeofblue 99de163
fix tests
shadeofblue 61a2896
fix script vs task events confusion
shadeofblue 68da31a
fix test, black
shadeofblue be30dbf
Add `message` field to `CommandExecuted` event
azawlocki 37e4c01
Adjust integration tests to changed summary logger messages
azawlocki 1973569
Make `AsyncWrapper` an async context manager
azawlocki a2e5c2d
Address CR suggestions
azawlocki 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
#!/usr/bin/env python3 | ||
import asyncio | ||
from datetime import datetime, timedelta | ||
import pathlib | ||
import sys | ||
|
||
from yapapi import ( | ||
Executor, | ||
NoPaymentAccountError, | ||
Task, | ||
__version__ as yapapi_version, | ||
WorkContext, | ||
windows_event_loop_fix, | ||
) | ||
from yapapi.log import enable_default_logger, log_summary, log_event_repr # noqa | ||
from yapapi.payload import vm | ||
from yapapi.rest.activity import BatchTimeoutError | ||
|
||
examples_dir = pathlib.Path(__file__).resolve().parent.parent | ||
sys.path.append(str(examples_dir)) | ||
|
||
from utils import ( | ||
build_parser, | ||
TEXT_COLOR_CYAN, | ||
TEXT_COLOR_DEFAULT, | ||
TEXT_COLOR_RED, | ||
TEXT_COLOR_YELLOW, | ||
) | ||
|
||
|
||
async def main(subnet_tag, driver=None, network=None): | ||
package = await vm.repo( | ||
image_hash="9a3b5d67b0b27746283cb5f287c13eab1beaa12d92a9f536b747c7ae", | ||
min_mem_gib=0.5, | ||
min_storage_gib=2.0, | ||
) | ||
|
||
async def worker(ctx: WorkContext, tasks): | ||
script_dir = pathlib.Path(__file__).resolve().parent | ||
scene_path = str(script_dir / "cubes.blend") | ||
ctx.send_file(scene_path, "/golem/resource/scene.blend") | ||
async for task in tasks: | ||
frame = task.data | ||
crops = [{"outfilebasename": "out", "borders_x": [0.0, 1.0], "borders_y": [0.0, 1.0]}] | ||
ctx.send_json( | ||
"/golem/work/params.json", | ||
{ | ||
"scene_file": "/golem/resource/scene.blend", | ||
"resolution": (400, 300), | ||
"use_compositing": False, | ||
"crops": crops, | ||
"samples": 100, | ||
"frames": [frame], | ||
"output_format": "PNG", | ||
"RESOURCES_DIR": "/golem/resources", | ||
"WORK_DIR": "/golem/work", | ||
"OUTPUT_DIR": "/golem/output", | ||
}, | ||
) | ||
ctx.run("/golem/entrypoints/run-blender.sh") | ||
output_file = f"output_{frame}.png" | ||
ctx.download_file(f"/golem/output/out{frame:04d}.png", output_file) | ||
try: | ||
# Set timeout for executing the script on the provider. Usually, 30 seconds | ||
# should be more than enough for computing a single frame, however a provider | ||
# may require more time for the first task if it needs to download a VM image | ||
# first. Once downloaded, the VM image will be cached and other tasks that use | ||
# that image will be computed faster. | ||
yield ctx.commit(timeout=timedelta(minutes=10)) | ||
# TODO: Check if job results are valid | ||
# and reject by: task.reject_task(reason = 'invalid file') | ||
task.accept_result(result=output_file) | ||
except BatchTimeoutError: | ||
print( | ||
f"{TEXT_COLOR_RED}" | ||
f"Task {task} timed out on {ctx.provider_name}, time: {task.running_time}" | ||
f"{TEXT_COLOR_DEFAULT}" | ||
) | ||
raise | ||
|
||
# Iterator over the frame indices that we want to render | ||
frames: range = range(0, 60, 10) | ||
# Worst-case overhead, in minutes, for initialization (negotiation, file transfer etc.) | ||
# TODO: make this dynamic, e.g. depending on the size of files to transfer | ||
init_overhead = 3 | ||
# Providers will not accept work if the timeout is outside of the [5 min, 30min] range. | ||
# We increase the lower bound to 6 min to account for the time needed for our demand to | ||
# reach the providers. | ||
min_timeout, max_timeout = 6, 30 | ||
|
||
timeout = timedelta(minutes=max(min(init_overhead + len(frames) * 2, max_timeout), min_timeout)) | ||
|
||
# By passing `event_consumer=log_summary()` we enable summary logging. | ||
# See the documentation of the `yapapi.log` module on how to set | ||
# the level of detail and format of the logged information. | ||
async with Executor( | ||
payload=package, | ||
max_workers=3, | ||
budget=10.0, | ||
timeout=timeout, | ||
subnet_tag=subnet_tag, | ||
driver=driver, | ||
network=network, | ||
event_consumer=log_summary(log_event_repr), | ||
) as executor: | ||
|
||
print( | ||
f"yapapi version: {TEXT_COLOR_YELLOW}{yapapi_version}{TEXT_COLOR_DEFAULT}\n" | ||
f"Using subnet: {TEXT_COLOR_YELLOW}{subnet_tag}{TEXT_COLOR_DEFAULT}, " | ||
f"payment driver: {TEXT_COLOR_YELLOW}{executor.driver}{TEXT_COLOR_DEFAULT}, " | ||
f"and network: {TEXT_COLOR_YELLOW}{executor.network}{TEXT_COLOR_DEFAULT}\n" | ||
) | ||
|
||
num_tasks = 0 | ||
start_time = datetime.now() | ||
|
||
async for task in executor.submit(worker, [Task(data=frame) for frame in frames]): | ||
num_tasks += 1 | ||
print( | ||
f"{TEXT_COLOR_CYAN}" | ||
f"Task computed: {task}, result: {task.result}, time: {task.running_time}" | ||
f"{TEXT_COLOR_DEFAULT}" | ||
) | ||
|
||
print( | ||
f"{TEXT_COLOR_CYAN}" | ||
f"{num_tasks} tasks computed, total time: {datetime.now() - start_time}" | ||
f"{TEXT_COLOR_DEFAULT}" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = build_parser("Render a Blender scene") | ||
now = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") | ||
parser.set_defaults(log_file=f"blender-yapapi-{now}.log") | ||
args = parser.parse_args() | ||
|
||
# This is only required when running on Windows with Python prior to 3.8: | ||
windows_event_loop_fix() | ||
|
||
enable_default_logger( | ||
log_file=args.log_file, | ||
debug_activity_api=True, | ||
debug_market_api=True, | ||
debug_payment_api=True, | ||
) | ||
|
||
loop = asyncio.get_event_loop() | ||
task = loop.create_task( | ||
main(subnet_tag=args.subnet_tag, driver=args.driver, network=args.network) | ||
) | ||
|
||
try: | ||
loop.run_until_complete(task) | ||
except NoPaymentAccountError as e: | ||
handbook_url = ( | ||
"https://handbook.golem.network/requestor-tutorials/" | ||
"flash-tutorial-of-requestor-development" | ||
) | ||
print( | ||
f"{TEXT_COLOR_RED}" | ||
f"No payment account initialized for driver `{e.required_driver}` " | ||
f"and network `{e.required_network}`.\n\n" | ||
f"See {handbook_url} on how to initialize payment accounts for a requestor node." | ||
f"{TEXT_COLOR_DEFAULT}" | ||
) | ||
except KeyboardInterrupt: | ||
print( | ||
f"{TEXT_COLOR_YELLOW}" | ||
"Shutting down gracefully, please wait a short while " | ||
"or press Ctrl+C to exit immediately..." | ||
f"{TEXT_COLOR_DEFAULT}" | ||
) | ||
task.cancel() | ||
try: | ||
loop.run_until_complete(task) | ||
print( | ||
f"{TEXT_COLOR_YELLOW}Shutdown completed, thank you for waiting!{TEXT_COLOR_DEFAULT}" | ||
) | ||
except (asyncio.CancelledError, KeyboardInterrupt): | ||
pass |
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
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
Oops, something went wrong.
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.
That's most likely not the scope of this PR but it would be best to make this
from yapapi import Golem
, either by actually moving the code or just importing it in the base package.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 would say this should be in the scope of the changes to be frozen - but I'll let @azawlocki decide if he'd like to proceed with reshuffling of code between the files within the scope of this pull request...