Skip to content

Commit

Permalink
Refactor a lot of paths to re-organize structure (#295)
Browse files Browse the repository at this point in the history
* moving around the stuff from data_model and webapp/client

* Migrating crowd providers

* Moving script utils

* Migrating architects

* Forgot to update channel callsites

* Moving blueprints

* Migrating core

* merging 298

* doc path refactor
  • Loading branch information
JackUrb authored Nov 4, 2020
1 parent b5c262f commit 5c9700f
Show file tree
Hide file tree
Showing 277 changed files with 33,504 additions and 11,689 deletions.
2 changes: 1 addition & 1 deletion docs/architecture_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ The classes are all expected to provide an `Args` class, which is a dataclass th
There's also the abstraction of the `MephistoDB`, which defines the data operations that Mephisto requires to operate properly. If a specific setup requires specialized data handling, any class implementing this interface could stand in for it.

## Blueprints
The [blueprints](https://github.com/facebookresearch/Mephisto/tree/master/mephisto/server/blueprints) contain all of the related code required to set up a task run. Blueprints may follow a hierarchical structure, in that general functionality can be written into abstract blueprints (which are powerful but perhaps hard to configure) and then downstream blueprints may have more configuration control but less breadth. Much of this can actually require significant overhead, so we've created additional abstract classes that a blueprint must link to an implementation for. These are listed below:
The [blueprints](https://github.com/facebookresearch/Mephisto/tree/master/mephisto/abstractions/blueprints) contain all of the related code required to set up a task run. Blueprints may follow a hierarchical structure, in that general functionality can be written into abstract blueprints (which are powerful but perhaps hard to configure) and then downstream blueprints may have more configuration control but less breadth. Much of this can actually require significant overhead, so we've created additional abstract classes that a blueprint must link to an implementation for. These are listed below:
### BlueprintArgs
These define the specific arguments for configuring a blueprint. Some base arguments relevant to all blueprints are provided already, and classes that override `BlueprintArgs` can add anything else they want.
### SharedTaskState
Expand Down
32 changes: 16 additions & 16 deletions docs/hydra_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ This document shows the transition steps from moving from the old format to the
import os
import time
import shlex
from mephisto.core.operator import Operator
from mephisto.core.utils import get_root_dir
from mephisto.server.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE
from mephisto.utils.scripts import MephistoRunScriptParser, str2bool
from mephisto.operations.operator import Operator
from mephisto.operations.utils import get_root_dir
from mephisto.abstractions.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE
from mephisto.tools.scripts import MephistoRunScriptParser, str2bool

parser = MephistoRunScriptParser()
parser.add_argument(
Expand Down Expand Up @@ -214,7 +214,7 @@ defaults = [
{"conf": "example"},
]
from mephisto.core.hydra_config import RunScriptConfig, register_script_config
from mephisto.operations.hydra_config import RunScriptConfig, register_script_config
@dataclass
class TestScriptConfig(RunScriptConfig):
Expand Down Expand Up @@ -321,10 +321,10 @@ operator.wait_for_runs_then_shutdown(skip_input=True, log_rate=30)
```python
import os
import shlex # shlex is no longer required, as we're not using arg strings
from mephisto.core.operator import Operator
from mephisto.core.utils import get_root_dir
from mephisto.server.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE
from mephisto.utils.scripts import MephistoRunScriptParser, str2bool # RunScriptParser has been deprecated.
from mephisto.operations.operator import Operator
from mephisto.operations.utils import get_root_dir
from mephisto.abstractions.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE
from mephisto.tools.scripts import MephistoRunScriptParser, str2bool # RunScriptParser has been deprecated.
```

We remove unnecessary or deprecated imports.
Expand All @@ -334,9 +334,9 @@ We'll need to add a few things. First, `load_db_and_process_config` covers the o
Mephisto now defines run scripts and configurations using Hydra and dataclasses, as such you'll need some imports from `dataclasses`, `hydra`, and `omegaconf` (which is the configuration library that powers hydra).
```python
import os
from mephisto.core.operator import Operator
from mephisto.utils.scripts import load_db_and_process_config
from mephisto.server.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE, SharedParlAITaskState
from mephisto.operations.operator import Operator
from mephisto.tools.scripts import load_db_and_process_config
from mephisto.abstractions.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE, SharedParlAITaskState

import hydra
from omegaconf import DictConfig
Expand All @@ -349,9 +349,9 @@ from typing import List, Any
```python
# parlai_test_script.py
import os
from mephisto.core.operator import Operator
from mephisto.utils.scripts import load_db_and_process_config
from mephisto.server.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE, SharedParlAITaskState
from mephisto.operations.operator import Operator
from mephisto.tools.scripts import load_db_and_process_config
from mephisto.abstractions.blueprints.parlai_chat.parlai_chat_blueprint import BLUEPRINT_TYPE, SharedParlAITaskState

import hydra
from omegaconf import DictConfig
Expand All @@ -368,7 +368,7 @@ defaults = [
{"conf": "example"},
]

from mephisto.core.hydra_config import RunScriptConfig, register_script_config
from mephisto.operations.hydra_config import RunScriptConfig, register_script_config

@dataclass
class TestScriptConfig(RunScriptConfig):
Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ $ cd examples/simple_static_task
$ python static_test_script.py mephisto/architect=heroku mephisto.provider.requester_name=my_mturk_user_sandbox
Locating heroku...
INFO - Creating a task run under task name: html-static-task-example
[mephisto.core.operator][INFO] - Creating a task run under task name: html-static-task-example
[mephisto.operations.operator][INFO] - Creating a task run under task name: html-static-task-example
Building server files...
...

Expand Down
8 changes: 4 additions & 4 deletions examples/parlai_chat_task_demo/parlai_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


import os
from mephisto.core.operator import Operator
from mephisto.utils.scripts import load_db_and_process_config
from mephisto.server.blueprints.parlai_chat.parlai_chat_blueprint import (
from mephisto.operations.operator import Operator
from mephisto.tools.scripts import load_db_and_process_config
from mephisto.abstractions.blueprints.parlai_chat.parlai_chat_blueprint import (
BLUEPRINT_TYPE,
SharedParlAITaskState,
)
Expand All @@ -28,7 +28,7 @@
{"conf": "example"},
]

from mephisto.core.hydra_config import RunScriptConfig, register_script_config
from mephisto.operations.hydra_config import RunScriptConfig, register_script_config


@dataclass
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_static_task/examine_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from mephisto.core.local_database import LocalMephistoDB
from mephisto.core.data_browser import DataBrowser as MephistoDataBrowser
from mephisto.abstractions.databases.local_database import LocalMephistoDB
from mephisto.tools.data_browser import DataBrowser as MephistoDataBrowser
from mephisto.data_model.worker import Worker
from mephisto.data_model.assignment import Unit

Expand Down
14 changes: 8 additions & 6 deletions examples/simple_static_task/static_run_with_onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
# LICENSE file in the root directory of this source tree.

import os
from mephisto.core.operator import Operator
from mephisto.core.utils import get_root_dir
from mephisto.utils.scripts import load_db_and_process_config
from mephisto.server.blueprints.static_task.static_html_blueprint import BLUEPRINT_TYPE
from mephisto.server.blueprints.abstract.static_task.static_blueprint import (
from mephisto.operations.operator import Operator
from mephisto.operations.utils import get_root_dir
from mephisto.tools.scripts import load_db_and_process_config
from mephisto.abstractions.blueprints.static_html_task.static_html_blueprint import (
BLUEPRINT_TYPE,
)
from mephisto.abstractions.blueprints.abstract.static_task.static_blueprint import (
SharedStaticTaskState,
)

Expand All @@ -28,7 +30,7 @@
{"conf": "onboarding_example"},
]

from mephisto.core.hydra_config import RunScriptConfig, register_script_config
from mephisto.operations.hydra_config import RunScriptConfig, register_script_config


@dataclass
Expand Down
12 changes: 7 additions & 5 deletions examples/simple_static_task/static_test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
# LICENSE file in the root directory of this source tree.

import os
from mephisto.core.operator import Operator
from mephisto.core.utils import get_root_dir
from mephisto.server.blueprints.static_task.static_html_blueprint import BLUEPRINT_TYPE
from mephisto.utils.scripts import load_db_and_process_config
from mephisto.operations.operator import Operator
from mephisto.operations.utils import get_root_dir
from mephisto.abstractions.blueprints.static_html_task.static_html_blueprint import (
BLUEPRINT_TYPE,
)
from mephisto.tools.scripts import load_db_and_process_config

import hydra
from omegaconf import DictConfig
Expand All @@ -25,7 +27,7 @@
{"conf": "example"},
]

from mephisto.core.hydra_config import RunScriptConfig, register_script_config
from mephisto.operations.hydra_config import RunScriptConfig, register_script_config


@dataclass
Expand Down
12 changes: 6 additions & 6 deletions examples/static_react_task/run_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import os
import shutil
import subprocess
from mephisto.core.operator import Operator
from mephisto.core.utils import get_root_dir
from mephisto.utils.scripts import load_db_and_process_config
from mephisto.server.blueprints.static_react_task.static_react_blueprint import (
from mephisto.operations.operator import Operator
from mephisto.operations.utils import get_root_dir
from mephisto.tools.scripts import load_db_and_process_config
from mephisto.abstractions.blueprints.static_react_task.static_react_blueprint import (
BLUEPRINT_TYPE,
)
from mephisto.server.blueprints.abstract.static_task.static_blueprint import (
from mephisto.abstractions.blueprints.abstract.static_task.static_blueprint import (
SharedStaticTaskState,
)

Expand All @@ -31,7 +31,7 @@
{"conf": "example"},
]

from mephisto.core.hydra_config import RunScriptConfig, register_script_config
from mephisto.operations.hydra_config import RunScriptConfig, register_script_config


@dataclass
Expand Down
6 changes: 3 additions & 3 deletions mephisto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from mephisto.core.registry import fill_registries
from mephisto.core.config_handler import init_config
from mephisto.core.hydra_config import initialize_named_configs
from mephisto.operations.registry import fill_registries
from mephisto.operations.config_handler import init_config
from mephisto.operations.hydra_config import initialize_named_configs

__version__ = "0.1.0"

Expand Down
File renamed without changes.
113 changes: 113 additions & 0 deletions mephisto/abstractions/architect.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from omegaconf import MISSING, DictConfig
from typing import Dict, List, Any, ClassVar, Type, TYPE_CHECKING, Callable

if TYPE_CHECKING:
from mephisto.abstractions.channel import Channel
from mephsito.data_model.packet import Packet
from mephisto.data_model.task_run import TaskRun
from mephisto.abstractions.database import MephistoDB
from mephisto.abstractions.blueprint import SharedTaskState
from argparse import _ArgumentGroup as ArgumentGroup


@dataclass
class ArchitectArgs:
"""Base class for arguments to configure architects"""

_architect_type: str = MISSING


class Architect(ABC):
"""
Provides methods for setting up a server somewhere and deploying tasks
onto that server.
"""

ArgsClass: ClassVar[Type[ArchitectArgs]] = ArchitectArgs
ARCHITECT_TYPE: str

def __init__(
self,
db: "MephistoDB",
args: DictConfig,
shared_state: "SharedTaskState",
task_run: "TaskRun",
build_dir_root: str,
):
"""
Initialize this architect with whatever options are provided given
ArgsClass. Parse whatever additional options may be required
for the specific task_run.
Also set up any required database/memory into the MephistoDB so that
this data can be stored long-term.
"""
raise NotImplementedError()

@classmethod
def assert_task_args(cls, args: DictConfig, shared_state: "SharedTaskState"):
"""
Assert that the provided arguments are valid. Should
fail if a task launched with these arguments would
not work.
This should include throwing an exception if the architect
needs login details or something similar given the
arguments passed in.
"""
return

def get_channels(
self,
on_channel_open: Callable[[str], None],
on_catastrophic_disconnect: Callable[[str], None],
on_message: Callable[[str, "Packet"], None],
) -> List["Channel"]:
"""
Return a list of all relevant channels that the Supervisor will
need to register to in order to function
"""
raise NotImplementedError()

def download_file(self, filename: str, save_dir: str) -> None:
"""
Save the file that is noted as stored on the server to
the desired save location.
"""
raise NotImplementedError()

def prepare(self) -> str:
"""
Produce the server files that will be deployed to the server
"""
raise NotImplementedError()

def deploy(self) -> str:
"""
Launch the server, and push the task files to the server. Return
the server URL
"""
raise NotImplementedError()

def cleanup(self) -> None:
"""
Remove any files that were used for the deployment process that
no longer need to be kept track of now that the task has
been launched.
"""
raise NotImplementedError()

def shutdown(self) -> None:
"""
Shut down the server launched by this Surveyor, as stored
in the db.
"""
raise NotImplementedError()
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 5c9700f

Please sign in to comment.