From 34c545b0128e9f0eacee9aa4bb03a991a0f4bf88 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 12:36:58 -0400 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=93=9D=20Added=20info=20about=20link?= =?UTF-8?q?=5Ftask=5Fsource=20to=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/docs/guides/tutorials/custom_react.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/web/docs/guides/tutorials/custom_react.md b/docs/web/docs/guides/tutorials/custom_react.md index cb6051f9d..07b8fc38d 100644 --- a/docs/web/docs/guides/tutorials/custom_react.md +++ b/docs/web/docs/guides/tutorials/custom_react.md @@ -36,15 +36,30 @@ mephisto: task_tags: "test,simple,button" ``` -The only change we'll make is to the `task_name` (as you should on any new tasks!), but we will update the other fields as we go. It's important to note the `task_source` and `extra_source_dir` arguments though, as this is where the `StaticReactBlueprint` class will be looking for the compiled React app's Javascript bundle as well as a folder for extra static resources for the page, respectively. +It is important to give a new `task_name` as we are creating a custom task. For local development **only** it also makes sense to set `link_task_source` to true. This allows changes to propagate to your localhost server when you reload the page (otherwise you would have to shutdown and restart the server to see changes). + +The `task_source` and `extra_source_dir` arguments are also of importance, as this is where the `StaticReactBlueprint` class will be looking for the compiled React app's Javascript bundle as well as a folder for extra static resources for the page, respectively. ### 1.2 Launching the task From the current directory, you should be able to execute the run script and get a job working. We're using a different `task_name` to prevent polluting our later task with data that won't share the same format. It is a good practice to do this with initial iterations, and to change the `task_name` any time you change input or output arguments. + +You can update the `task_name` and `link_task_source` values in your config and run the task like below ```bash -python run_task.py mephisto.task.task_name=custom-react-tutorial-iterating +python run_task.py +``` + +or you can set them when you run the task: + +```bash +python run_task.py mephisto.task.task_name=custom-react-tutorial-iterating mephisto.blueprint.link_task_source=true ``` This will launch a simple task where an annotator is supposed to note a sentence as being good or bad. Clicking a button auto-submits the task. In the next sections we'll add other content. +To establish a link where your changes will be propagated to the localhost server(when you reload) create a separate terminal window and run +```bash +cd webapp && npm run dev +``` + Moving forward, we'll update this task so that workers are able to edit the text as well as rate the original sentence. ## 2. Providing new data to the task From daecc99da4e9c03730542cd97c98bdf2e077c244 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 13:13:42 -0400 Subject: [PATCH 2/6] =?UTF-8?q?=E2=9C=A8=20Added=20logging=20message=20whe?= =?UTF-8?q?n=20link=5Ftaskk=5Fsource:=20false?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/web/docs/guides/tutorials/custom_react.md | 2 +- mephisto/operations/operator.py | 2 +- mephisto/operations/task_launcher.py | 17 +++++++++++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/web/docs/guides/tutorials/custom_react.md b/docs/web/docs/guides/tutorials/custom_react.md index 07b8fc38d..d8d65359d 100644 --- a/docs/web/docs/guides/tutorials/custom_react.md +++ b/docs/web/docs/guides/tutorials/custom_react.md @@ -57,7 +57,7 @@ This will launch a simple task where an annotator is supposed to note a sentence To establish a link where your changes will be propagated to the localhost server(when you reload) create a separate terminal window and run ```bash -cd webapp && npm run dev +cd webapp && npm run dev:watch ``` Moving forward, we'll update this task so that workers are able to edit the text as well as rate the original sentence. diff --git a/mephisto/operations/operator.py b/mephisto/operations/operator.py index 5da26be3d..6798368f2 100644 --- a/mephisto/operations/operator.py +++ b/mephisto/operations/operator.py @@ -313,7 +313,7 @@ def launch_task_run_or_die( raise e live_run.task_launcher.create_assignments() - live_run.task_launcher.launch_units(task_url) + live_run.task_launcher.launch_units(url=task_url, run_config=run_config) self._task_runs_tracked[task_run.db_id] = live_run task_run.update_completion_progress(status=False) diff --git a/mephisto/operations/task_launcher.py b/mephisto/operations/task_launcher.py index b5483ba2e..f97918c4f 100644 --- a/mephisto/operations/task_launcher.py +++ b/mephisto/operations/task_launcher.py @@ -26,7 +26,7 @@ if TYPE_CHECKING: from mephisto.data_model.task_run import TaskRun from mephisto.abstractions.database import MephistoDB - +from omegaconf import DictConfig, OmegaConf import threading from mephisto.utils.logger_core import get_logger import types @@ -180,7 +180,7 @@ def generate_units(self): if not self.unlaunched_units: break - def _launch_limited_units(self, url: str) -> None: + def _launch_limited_units(self, url: str, run_config: Optional[DictConfig]) -> None: """use units' generator to launch limited number of units according to (max_num_concurrent_units)""" # Continue launching if we haven't pulled the plug, so long as there are currently # units to launch, or more may come in the future. @@ -191,15 +191,24 @@ def _launch_limited_units(self, url: str) -> None: if unit is None: break unit.launch(url) + if ( + run_config is not None + and run_config.blueprint.link_task_source == False + ): + logger.info( + "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: true\n\nin your task's hydra configuration.\n\nFor more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task" + ) if self.generator_type == GeneratorType.NONE: break self.finished_generators = True - def launch_units(self, url: str) -> None: + def launch_units(self, url: str, run_config: Optional[DictConfig]) -> None: """launch any units registered by this TaskLauncher""" self.launch_url = url self.units_thread = threading.Thread( - target=self._launch_limited_units, args=(url,), name="unit-generator" + target=self._launch_limited_units, + args=(url, run_config), + name="unit-generator", ) self.units_thread.start() From 36eb84c568ec366e33e21c01b73f1b021be2341d Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 13:18:19 -0400 Subject: [PATCH 3/6] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Added=20more=20info=20?= =?UTF-8?q?to=20link=5Ftask=5Fsource=20log=20message?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mephisto/operations/task_launcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mephisto/operations/task_launcher.py b/mephisto/operations/task_launcher.py index f97918c4f..1db2dc15b 100644 --- a/mephisto/operations/task_launcher.py +++ b/mephisto/operations/task_launcher.py @@ -196,7 +196,7 @@ def _launch_limited_units(self, url: str, run_config: Optional[DictConfig]) -> N and run_config.blueprint.link_task_source == False ): logger.info( - "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: true\n\nin your task's hydra configuration.\n\nFor more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task" + "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: true\n\nin your task's hydra configuration and run \n\ncd webapp && npm run dev:watch\n\nin a separate terminal window. For more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task" ) if self.generator_type == GeneratorType.NONE: break From a4fd65a3856baddc6c0bf8d4591c1d0cf2ff7517 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Mon, 8 Aug 2022 14:01:42 -0400 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=93=9D=20Added=20a=20comma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/web/docs/guides/tutorials/custom_react.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/web/docs/guides/tutorials/custom_react.md b/docs/web/docs/guides/tutorials/custom_react.md index d8d65359d..9423eb7dd 100644 --- a/docs/web/docs/guides/tutorials/custom_react.md +++ b/docs/web/docs/guides/tutorials/custom_react.md @@ -55,7 +55,7 @@ python run_task.py mephisto.task.task_name=custom-react-tutorial-iterating mephi ``` This will launch a simple task where an annotator is supposed to note a sentence as being good or bad. Clicking a button auto-submits the task. In the next sections we'll add other content. -To establish a link where your changes will be propagated to the localhost server(when you reload) create a separate terminal window and run +To establish a link where your changes will be propagated to the localhost server(when you reload), create a separate terminal window and run ```bash cd webapp && npm run dev:watch ``` From e10c39862a7dc869e84e3e545e1b667735a31eb0 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Wed, 10 Aug 2022 11:12:27 -0400 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=9A=9A=20Moved=20link=5Ftask=5Fsource?= =?UTF-8?q?=20log=20message=20to=20operator.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎨 Added a little bit of color to the logging message --- mephisto/operations/operator.py | 8 +++++++- mephisto/operations/task_launcher.py | 14 +++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/mephisto/operations/operator.py b/mephisto/operations/operator.py index 6798368f2..3c7d86ffd 100644 --- a/mephisto/operations/operator.py +++ b/mephisto/operations/operator.py @@ -251,6 +251,12 @@ def launch_task_run_or_die( f"Task is using the default blueprint name {task_name} as a name, " "as no task_name is provided" ) + link_task_source = run_config.blueprint.get("link_task_source") + if link_task_source == False: + logger.info( + "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: [blue]true[/blue]\n\nin your task's hydra configuration and run \n\n[purple]cd[/purple] webapp && [green]npm[/green] run dev:watch\n\nin a separate terminal window. For more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task", + extra={"markup": True}, + ) tasks = self.db.find_tasks(task_name=task_name) @@ -313,7 +319,7 @@ def launch_task_run_or_die( raise e live_run.task_launcher.create_assignments() - live_run.task_launcher.launch_units(url=task_url, run_config=run_config) + live_run.task_launcher.launch_units(url=task_url) self._task_runs_tracked[task_run.db_id] = live_run task_run.update_completion_progress(status=False) diff --git a/mephisto/operations/task_launcher.py b/mephisto/operations/task_launcher.py index 1db2dc15b..178ca39ff 100644 --- a/mephisto/operations/task_launcher.py +++ b/mephisto/operations/task_launcher.py @@ -26,7 +26,6 @@ if TYPE_CHECKING: from mephisto.data_model.task_run import TaskRun from mephisto.abstractions.database import MephistoDB -from omegaconf import DictConfig, OmegaConf import threading from mephisto.utils.logger_core import get_logger import types @@ -180,7 +179,7 @@ def generate_units(self): if not self.unlaunched_units: break - def _launch_limited_units(self, url: str, run_config: Optional[DictConfig]) -> None: + def _launch_limited_units(self, url: str) -> None: """use units' generator to launch limited number of units according to (max_num_concurrent_units)""" # Continue launching if we haven't pulled the plug, so long as there are currently # units to launch, or more may come in the future. @@ -191,23 +190,16 @@ def _launch_limited_units(self, url: str, run_config: Optional[DictConfig]) -> N if unit is None: break unit.launch(url) - if ( - run_config is not None - and run_config.blueprint.link_task_source == False - ): - logger.info( - "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: true\n\nin your task's hydra configuration and run \n\ncd webapp && npm run dev:watch\n\nin a separate terminal window. For more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task" - ) if self.generator_type == GeneratorType.NONE: break self.finished_generators = True - def launch_units(self, url: str, run_config: Optional[DictConfig]) -> None: + def launch_units(self, url: str) -> None: """launch any units registered by this TaskLauncher""" self.launch_url = url self.units_thread = threading.Thread( target=self._launch_limited_units, - args=(url, run_config), + args=(url,), name="unit-generator", ) self.units_thread.start() From 52781d4045c0cbe6804b85ad325edbc42463ad04 Mon Sep 17 00:00:00 2001 From: Etesam Ansari Date: Wed, 10 Aug 2022 12:01:47 -0400 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=9A=9A=20Moved=20link=5Ftask=5Fsource?= =?UTF-8?q?=20log=20to=20assert=5Ftask=5Fargs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../static_react_task/static_react_blueprint.py | 10 ++++++++++ mephisto/operations/operator.py | 9 +-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py b/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py index 0f250e5d7..4f3373c02 100644 --- a/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py +++ b/mephisto/abstractions/blueprints/static_react_task/static_react_blueprint.py @@ -22,6 +22,9 @@ from mephisto.abstractions.blueprint import ( SharedTaskState, ) +from mephisto.utils.logger_core import ( + get_logger, +) if TYPE_CHECKING: from mephisto.data_model.task_run import TaskRun @@ -31,6 +34,7 @@ from omegaconf import DictConfig BLUEPRINT_TYPE_STATIC_REACT = "static_react_task" +logger = get_logger(name=__name__) @dataclass @@ -120,3 +124,9 @@ def assert_task_args( assert link_task_source == False or ( link_task_source == True and current_architect in allowed_architects ), f"`link_task_source={link_task_source}` is not compatible with architect type: {args.architect._architect_type}. Please check your task configuration." + + if link_task_source == False and current_architect in allowed_architects: + logger.info( + "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: [blue]true[/blue]\n\nin your task's hydra configuration and run \n\n[purple]cd[/purple] webapp [red]&&[/red] [green]npm[/green] run dev:watch\n\nin a separate terminal window. For more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task\n", + extra={"markup": True}, + ) diff --git a/mephisto/operations/operator.py b/mephisto/operations/operator.py index 3c7d86ffd..e6fb60cb2 100644 --- a/mephisto/operations/operator.py +++ b/mephisto/operations/operator.py @@ -29,7 +29,6 @@ ) from mephisto.abstractions.database import MephistoDB, EntryDoesNotExistException from mephisto.data_model.qualification import QUAL_NOT_EXIST -from mephisto.tools.data_browser import DataBrowser as MephistoDataBrowser from mephisto.utils.qualifications import make_qualification_dict from mephisto.operations.task_launcher import TaskLauncher from mephisto.operations.client_io_handler import ClientIOHandler @@ -56,7 +55,7 @@ logger = get_logger(name=__name__) if TYPE_CHECKING: - from mephisto.abstractions.blueprint import Blueprint, TaskRunner + from mephisto.abstractions.blueprint import Blueprint from mephisto.abstractions.crowd_provider import CrowdProvider from mephisto.abstractions.architect import Architect @@ -251,12 +250,6 @@ def launch_task_run_or_die( f"Task is using the default blueprint name {task_name} as a name, " "as no task_name is provided" ) - link_task_source = run_config.blueprint.get("link_task_source") - if link_task_source == False: - logger.info( - "If you want your server to update on reload whenever you make changes to your webapp, then make sure to set \n\nlink_task_source: [blue]true[/blue]\n\nin your task's hydra configuration and run \n\n[purple]cd[/purple] webapp && [green]npm[/green] run dev:watch\n\nin a separate terminal window. For more information check out:\nhttps://mephisto.ai/docs/guides/tutorials/custom_react/#12-launching-the-task", - extra={"markup": True}, - ) tasks = self.db.find_tasks(task_name=task_name)