Skip to content

Commit

Permalink
Merge pull request #1043 from facebookresearch/style-fix
Browse files Browse the repository at this point in the history
running black across codebase
  • Loading branch information
JackUrb authored Aug 15, 2023
2 parents 3b49915 + a925e3f commit 110a3b3
Show file tree
Hide file tree
Showing 145 changed files with 1,604 additions and 2,459 deletions.
30 changes: 15 additions & 15 deletions docker/docker-compose.dev.vscode.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
fb_mephisto_vscode:
Expand All @@ -7,9 +7,9 @@ services:
context: ..
dockerfile: Dockerfile
ports:
- '8081:8000'
- '3001:3000'
- '5678:5678'
- "8081:8000"
- "3001:3000"
- "5678:5678"
volumes:
- ..:/mephisto
- ./entrypoints/server.sh:/entrypoint.sh
Expand All @@ -18,14 +18,14 @@ services:
entrypoint: /entrypoint.sh
env_file: envs/env.local
command: [
"sh",
"-c",
"pip install debugpy -t /tmp
&&
python
/tmp/debugpy
--wait-for-client
--listen 0.0.0.0:5678
/mephisto/examples/simple_static_task/static_test_script.py
"
]
"sh",
"-c",
"pip install debugpy -t /tmp
&&
python
/tmp/debugpy
--wait-for-client
--listen 0.0.0.0:5678
/mephisto/examples/simple_static_task/static_test_script.py
",
]
7 changes: 3 additions & 4 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3'
version: "3"

services:
fb_mephisto:
Expand All @@ -7,8 +7,8 @@ services:
context: ..
dockerfile: Dockerfile
ports:
- '8081:8000'
- '3001:3000'
- "8081:8000"
- "3001:3000"
volumes:
- ..:/mephisto
- ./entrypoints/server.prolific.sh:/entrypoint.sh
Expand All @@ -17,4 +17,3 @@ services:
entrypoint: /entrypoint.sh
env_file: envs/env.dev
command: tail -f /dev/null

7 changes: 2 additions & 5 deletions examples/parlai_chat_task_demo/parlai_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class ParlAITaskConfig(build_default_task_config("example")): # type: ignore
turn_timeout: int = field(
default=300,
metadata={
"help": "Maximum response time before kicking "
"a worker out, default 300 seconds"
"help": "Maximum response time before kicking " "a worker out, default 300 seconds"
},
)

Expand All @@ -46,9 +45,7 @@ def main(operator: "Operator", cfg: DictConfig) -> None:
)
world_opt["send_task_data"] = True

shared_state = SharedParlAITaskState(
world_opt=world_opt, onboarding_world_opt=world_opt
)
shared_state = SharedParlAITaskState(world_opt=world_opt, onboarding_world_opt=world_opt)

operator.launch_task_run(cfg.mephisto, shared_state)
operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)
Expand Down
4 changes: 1 addition & 3 deletions examples/remote_procedure/mnist/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
from collections import OrderedDict
import torch.utils.model_zoo as model_zoo

model_urls = {
"mnist": "http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/mnist-b07bb66b.pth"
}
model_urls = {"mnist": "http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/mnist-b07bb66b.pth"}


class MLP(nn.Module):
Expand Down
4 changes: 3 additions & 1 deletion examples/simple_static_task/examine_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def format_for_printing_data(data):
)

inputs = contents["inputs"]
inputs_string = f"Character: {inputs['character_name']}\nDescription: {inputs['character_description']}\n"
inputs_string = (
f"Character: {inputs['character_name']}\nDescription: {inputs['character_description']}\n"
)

outputs = contents["outputs"]
output_string = f" Rating: {outputs['rating']}\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@ mephisto:
architect:
_architect_type: ec2
profile_name: mephisto-router-iam
subdomain: '0802.1'
subdomain: "0802.1"
blueprint:
data_csv: ${task_dir}/data_prolific.csv
task_source: ${task_dir}/server_files/demo_task.html
preview_source: ${task_dir}/server_files/demo_preview.html
extra_source_dir: ${task_dir}/server_files/extra_refs
units_per_assignment: 2
log_level: 'debug'
log_level: "debug"
task:
task_name: '0802'
task_title: '0802 Task'
task_description: 'This is a simple test of static Prolific tasks.'
task_name: "0802"
task_title: "0802 Task"
task_description: "This is a simple test of static Prolific tasks."
task_reward: 70
task_tags: 'static,task,testing'
task_tags: "static,task,testing"
max_num_concurrent_units: 1
provider:
prolific_external_study_url: 'https://example.com?participant_id={{%PROLIFIC_PID%}}&study_id={{%STUDY_ID%}}&submission_id={{%SESSION_ID%}}'
prolific_id_option: 'url_parameters'
prolific_workspace_name: 'My Workspace'
prolific_project_name: 'Project'
prolific_allow_list_group_name: 'Allow list'
prolific_block_list_group_name: 'Block list'
prolific_external_study_url: "https://example.com?participant_id={{%PROLIFIC_PID%}}&study_id={{%STUDY_ID%}}&submission_id={{%SESSION_ID%}}"
prolific_id_option: "url_parameters"
prolific_workspace_name: "My Workspace"
prolific_project_name: "Project"
prolific_allow_list_group_name: "Allow list"
prolific_block_list_group_name: "Block list"
prolific_eligibility_requirements:
- name: 'CustomWhitelistEligibilityRequirement'
- name: "CustomWhitelistEligibilityRequirement"
white_list:
- 6463d32f50a18041930b71be
- 6463d3922d7d99360896228f
- 6463d40e8d5d2f0cce2b3b23
- 6463d44ed1b61a8fb4e0765a
- 6463d488c2f2821eaa2fa13f
- name: 'ApprovalRateEligibilityRequirement'
- name: "ApprovalRateEligibilityRequirement"
minimum_approval_rate: 0
maximum_approval_rate: 100
10 changes: 5 additions & 5 deletions examples/simple_static_task/static_test_prolific_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from mephisto.utils.qualifications import make_qualification_dict


@task_script(default_config_file='prolific_example')
@task_script(default_config_file="prolific_example")
def main(operator, cfg: DictConfig) -> None:
shared_state = SharedStaticTaskState()

Expand All @@ -27,15 +27,15 @@ def main(operator, cfg: DictConfig) -> None:
# Note that we'll prefix names with a customary `web.eligibility.models.` later in the code
shared_state.prolific_specific_qualifications = [
{
'name': 'AgeRangeEligibilityRequirement',
'min_age': 18,
'max_age': 100,
"name": "AgeRangeEligibilityRequirement",
"min_age": 18,
"max_age": 100,
},
]

operator.launch_task_run(cfg.mephisto, shared_state)
operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)


if __name__ == '__main__':
if __name__ == "__main__":
main()
4 changes: 1 addition & 3 deletions hydra_plugins/mephisto_path_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ def manipulate_search_path(self, search_path: ConfigSearchPath) -> None:
profile_path_user = os.path.join(DEFAULT_CONFIG_FOLDER, "hydra_configs")

search_path.append(provider="mephisto-profiles", path=f"file://{profile_path}")
search_path.append(
provider="mephisto-profiles-user", path=f"file://{profile_path_user}"
)
search_path.append(provider="mephisto-profiles-user", path=f"file://{profile_path_user}")
4 changes: 1 addition & 3 deletions mephisto/abstractions/_subcomponents/agent_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def __new__(cls, agent: Union["Agent", "OnboardingAgent"]) -> "AgentState":
if isinstance(agent, Agent):
correct_class = get_blueprint_from_type(agent.task_type).AgentStateClass
else:
correct_class = get_blueprint_from_type(
agent.task_type
).OnboardingAgentStateClass
correct_class = get_blueprint_from_type(agent.task_type).OnboardingAgentStateClass
return super().__new__(correct_class)
else:
# We are constructing another instance directly
Expand Down
20 changes: 5 additions & 15 deletions mephisto/abstractions/_subcomponents/task_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ class TaskRunner(ABC):
passing agents through a task.
"""

def __init__(
self, task_run: "TaskRun", args: "DictConfig", shared_state: "SharedTaskState"
):
def __init__(self, task_run: "TaskRun", args: "DictConfig", shared_state: "SharedTaskState"):
self.args = args
self.shared_state = shared_state
self.task_run = task_run
Expand Down Expand Up @@ -172,9 +170,7 @@ def _launch_and_run_onboarding(
"""Supervise the completion of an onboarding"""
with ONGOING_THREAD_COUNT.labels(
thread_type="onboarding"
).track_inprogress(), EXECUTION_DURATION_SECONDS.labels(
thread_type="onboarding"
).time():
).track_inprogress(), EXECUTION_DURATION_SECONDS.labels(thread_type="onboarding").time():
live_run = onboarding_agent.get_live_run()
onboarding_id = onboarding_agent.get_agent_id()
logger.debug(f"Launching onboarding for {onboarding_agent}")
Expand Down Expand Up @@ -202,9 +198,7 @@ def _launch_and_run_onboarding(
if onboarding_agent.get_status() == AgentState.STATUS_WAITING:
# The agent completed the onboarding task
async def register_then_cleanup():
await live_run.worker_pool.register_agent_from_onboarding(
onboarding_agent
)
await live_run.worker_pool.register_agent_from_onboarding(onboarding_agent)
await cleanup_after()

live_run.loop_wrap.execute_coro(register_then_cleanup())
Expand Down Expand Up @@ -267,9 +261,7 @@ def _launch_and_run_unit(
"""Supervise the completion of a unit thread"""
with ONGOING_THREAD_COUNT.labels(
thread_type="unit"
).track_inprogress(), EXECUTION_DURATION_SECONDS.labels(
thread_type="unit"
).time():
).track_inprogress(), EXECUTION_DURATION_SECONDS.labels(thread_type="unit").time():
try:
self.run_unit(unit, agent)
except (
Expand Down Expand Up @@ -348,9 +340,7 @@ def _launch_and_run_assignment(
"""Supervise the completion of an assignment thread"""
with ONGOING_THREAD_COUNT.labels(
thread_type="assignment"
).track_inprogress(), EXECUTION_DURATION_SECONDS.labels(
thread_type="assignment"
).time():
).track_inprogress(), EXECUTION_DURATION_SECONDS.labels(thread_type="assignment").time():
try:
self.run_assignment(assignment, agents)
except (
Expand Down
16 changes: 4 additions & 12 deletions mephisto/abstractions/architects/channels/websocket_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ async def on_error(error):
if hasattr(error, "errno"):
if error.errno == errno.ECONNREFUSED:
# TODO(CLEAN) replace with channel exception
raise Exception(
f"Socket {self.socket_url} refused connection, cancelling"
)
raise Exception(f"Socket {self.socket_url} refused connection, cancelling")
else:
logger.info(f"Socket logged error: {error}")

Expand Down Expand Up @@ -132,9 +130,7 @@ async def run_socket():
# Outer loop allows reconnects
while not self._is_closed:
try:
async with websockets.connect(
self.socket_url, open_timeout=30
) as websocket:
async with websockets.connect(self.socket_url, open_timeout=30) as websocket:
# Inner loop recieves messages until closed
self.socket = websocket
on_socket_open()
Expand All @@ -160,15 +156,11 @@ async def run_socket():
self.on_catastrophic_disconnect(self.channel_id)
return
except OSError as e:
logger.error(
f"Unhandled OSError exception in socket {e}, attempting restart"
)
logger.error(f"Unhandled OSError exception in socket {e}, attempting restart")
await asyncio.sleep(0.2)
except websockets.exceptions.InvalidStatusCode as e:
if self._retries == 0:
raise ConnectionRefusedError(
"Could not connect after retries"
) from e
raise ConnectionRefusedError("Could not connect after retries") from e
curr_retry = MAX_RETRIES - self._retries
logger.exception(
f"Status code error {repr(e)}, attempting retry {curr_retry}",
Expand Down
34 changes: 14 additions & 20 deletions mephisto/abstractions/architects/ec2/cleanup_ec2_server_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,56 +27,50 @@ def main():
all_server_names = [
os.path.splitext(s)[0]
for s in os.listdir(DEFAULT_SERVER_DETAIL_LOCATION)
if s.endswith('json') and s not in EXCLUDE_FILES_IN_SERVER_DIR
if s.endswith("json") and s not in EXCLUDE_FILES_IN_SERVER_DIR
]
n_names = len(all_server_names)

if not n_names:
logger.info('No servers found to clean up')
logger.info("No servers found to clean up")
return

logger.info(f'Found {n_names} server names: {", ".join(all_server_names)}')

confirm = input(
f'Are you sure you want to remove the {n_names} found servers? [y/N]\n'
f'>> '
)
if confirm != 'y':
confirm = input(f"Are you sure you want to remove the {n_names} found servers? [y/N]\n" f">> ")
if confirm != "y":
return

# Get EC2 user role
iam_role_name = input(
'Please enter local profile name for IAM role\n'
'>> '
)
logger.info(f'Removing {n_names} servers...')
iam_role_name = input("Please enter local profile name for IAM role\n" ">> ")
logger.info(f"Removing {n_names} servers...")

# Cleanup local server JSON files, and remove related EC2 infra
skipped_names = []
for i, server_name in enumerate(all_server_names):
_name = f'"{server_name}"'
logger.info(f'{i+1}/{n_names} Removing {_name}...')
logger.info(f"{i+1}/{n_names} Removing {_name}...")

session = boto3.Session(profile_name=iam_role_name, region_name='us-east-2')
session = boto3.Session(profile_name=iam_role_name, region_name="us-east-2")
try:
skipped_names.append(_name)
ec2_helpers.remove_instance_and_cleanup(session, server_name)
logger.debug(f'...{_name} - successfully removed')
logger.debug(f"...{_name} - successfully removed")
skipped_names.remove(_name)
except botocore.exceptions.ClientError as e:
logger.warning(f'...{_name} - could not be removed: {e}')
logger.warning(f"...{_name} - could not be removed: {e}")
except json.decoder.JSONDecodeError as e:
logger.warning(f'...{_name} - could not read JSON config: {e}')
logger.warning(f"...{_name} - could not read JSON config: {e}")
except Exception as e:
logger.warning(f'...{_name} - encountered error: {e}')
logger.warning(f"...{_name} - encountered error: {e}")

if skipped_names:
logger.info(
f'Could not remove {len(skipped_names)}/{n_names} servers: {", ".join(skipped_names)}'
)
else:
logger.info(f'Successfully removed {n_names} servers')
logger.info(f"Successfully removed {n_names} servers")


if __name__ == '__main__':
if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ def main():
f"Please enter server name you want to clean up (existing servers: {all_server_names})\n>> "
)
assert (
os.path.join(DEFAULT_SERVER_DETAIL_LOCATION, f"{server_name}.json")
!= DEFAULT_FALLBACK_FILE
os.path.join(DEFAULT_SERVER_DETAIL_LOCATION, f"{server_name}.json") != DEFAULT_FALLBACK_FILE
), "This is going to completely delete the fallback server for your EC2 architect."
assert server_name in all_server_names, f"{server_name} does not exist"

Expand Down
Loading

0 comments on commit 110a3b3

Please sign in to comment.