Skip to content

Commit

Permalink
Merge pull request #745 from facebookresearch/abstract-static-assert
Browse files Browse the repository at this point in the history
Adding assert to static tasks for data type
  • Loading branch information
JackUrb committed Apr 7, 2022
2 parents f9dae60 + 1a549c8 commit 3151ac0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ def update_data(self, live_update: Dict[str, Any]) -> None:
def update_submit(self, submission_data: Dict[str, Any]) -> None:
"""Move the submitted output to the local dict"""
outputs: Dict[str, Any]
assert isinstance(submission_data, dict), (
"Static tasks must get dict results. Ensure you are passing an object to "
f"your frontend task's `handleSubmit` method. Got {submission_data}"
)
output_files = submission_data.get("files")
if output_files is not None:
submission_data["files"] = [f["filename"] for f in submission_data["files"]]
Expand Down
21 changes: 12 additions & 9 deletions mephisto/operations/client_io_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,18 @@ def _on_submit_unit(self, packet: Packet, _channel_id: str):
agent = live_run.worker_pool.get_agent_for_id(packet.subject_id)
assert agent is not None, "Could not find given agent!"

# If the packet is_submit, and has files, we need to
# process downloading those files first
data_files = packet.data.get("files")
if data_files is not None:
save_dir = agent.get_data_dir()
architect = live_run.architect
for f_obj in data_files:
# TODO(#649) this is incredibly blocking!
architect.download_file(f_obj["filename"], save_dir)
# Special handler for file downloads while we have architect access
# NOTE: this is a leaky abstraction at the moment - only architects
# know how to save files but "file saving" methods are defined by
# AgentStates, which don't have architect access.
if isinstance(packet.data, dict):
data_files = packet.data.get("files")
if data_files is not None:
save_dir = agent.get_data_dir()
architect = live_run.architect
for f_obj in data_files:
# TODO(#649) this is incredibly blocking!
architect.download_file(f_obj["filename"], save_dir)

agent.handle_submit(packet.data)

Expand Down

0 comments on commit 3151ac0

Please sign in to comment.