Skip to content

Commit

Permalink
Merge pull request #1262 from facebookresearch/port-examples-to-inhou…
Browse files Browse the repository at this point in the history
…se-provider

Port existing Task examples to use In-House provider
  • Loading branch information
meta-paul authored Nov 18, 2024
2 parents 22fef68 + 3147809 commit 598c8b3
Show file tree
Hide file tree
Showing 89 changed files with 390 additions and 462 deletions.
58 changes: 35 additions & 23 deletions .github/workflows/cypress-end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ jobs:
# browser: chrome
# project: ./examples/form_composer_demo/webapp
# config-file: ./cypress.config.js
# start: python examples/form_composer_demo/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh
# wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
# start: python examples/form_composer_demo/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
# wait-on: "http://localhost:3000/?worker_id=x&=1"
# headless: true
#
# video_annotator_demo:
Expand Down Expand Up @@ -177,8 +177,8 @@ jobs:
# browser: chrome
# project: ./examples/video_annotator_demo/webapp
# config-file: ./cypress.config.js
# start: python examples/video_annotator_demo/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh
# wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
# start: python examples/video_annotator_demo/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
# wait-on: "http://localhost:3000/?worker_id=x&id=1"
# headless: true

# Learn more about this test here: https://github.com/facebookresearch/Mephisto/pull/881
Expand Down Expand Up @@ -209,6 +209,9 @@ jobs:
- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 🚚 Create Inhouse provider
run: mephisto register inhouse

- name: 📦 Setting up mephisto-core package
run: |
cd packages/mephisto-core
Expand All @@ -224,12 +227,12 @@ jobs:
browser: chrome
project: ./mephisto/abstractions/blueprints/static_html_task/source
config-file: ./cypress.config.js
start: python ./examples/simple_static_task/run_task.py
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
start: python ./examples/simple_static_task/run_task__local__inhouse.py
wait-on: "http://localhost:3000/?worker_id=x&id=1"
headless: true

# Learn more about this test here: https://github.com/facebookresearch/Mephisto/pull/795
static-react-task:
static_react_task:
needs: changes
if: ${{ (needs.changes.outputs.static_react_task == 'true') || (needs.changes.outputs.mephisto-core == 'true') || (needs.changes.outputs.abstractions == 'true') || (needs.changes.outputs.data_model == 'true') || (needs.changes.outputs.operations == 'true') || (needs.changes.outputs.tools == 'true')}}
runs-on: ubuntu-latest
Expand All @@ -256,6 +259,9 @@ jobs:
- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 🚚 Create Inhouse provider
run: mephisto register inhouse

- name: 📦 Setting up mephisto-core package
run: |
cd packages/mephisto-core
Expand All @@ -271,8 +277,8 @@ jobs:
browser: chrome
project: ./examples/static_react_task/webapp
config-file: ./cypress.config.js
start: python examples/static_react_task/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
start: python examples/static_react_task/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&id=1"
headless: true

# Learn more about the remote_procedure_tests here: https://github.com/facebookresearch/Mephisto/pull/800
Expand Down Expand Up @@ -303,7 +309,7 @@ jobs:
- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 🖋 Create Inhouse provider
- name: 🚚 Create Inhouse provider
run: mephisto register inhouse

- name: 📦 Setting up mephisto-core package
Expand All @@ -322,7 +328,7 @@ jobs:
project: ./examples/remote_procedure/elementary_remote_procedure/webapp
config-file: ./cypress.config.js
start: python examples/remote_procedure/elementary_remote_procedure/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
wait-on: "http://localhost:3000/?worker_id=x&id=1"
headless: true

# TODO: Add tests and enable
Expand Down Expand Up @@ -375,13 +381,13 @@ jobs:
# browser: chrome
# project: ./examples/remote_procedure/interactive_image_generation/webapp
# config-file: ./cypress.config.js
# start: python examples/remote_procedure/interactive_image_generation/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh
# wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
# start: python examples/remote_procedure/interactive_image_generation/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
# wait-on: "http://localhost:3000/?worker_id=x&id=1"
# headless: true

remote_procedure_mnist:
needs: changes
if: ${{ (needs.changes.outputs.mnist == 'true') || (needs.changes.outputs.mephisto-core == 'true') }}
if: ${{ (needs.changes.outputs.mnist == 'true') || (needs.changes.outputs.mephisto-core == 'true') || (needs.changes.outputs.abstractions == 'true') || (needs.changes.outputs.data_model == 'true') || (needs.changes.outputs.operations == 'true') || (needs.changes.outputs.tools == 'true')}}
runs-on: ubuntu-latest
steps:
- name: 🔀 Checking out repo
Expand All @@ -408,6 +414,9 @@ jobs:
- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 🚚 Create Inhouse provider
run: mephisto register inhouse

- name: 📦 Setting up mephisto-core package
run: |
cd packages/mephisto-core
Expand All @@ -423,13 +432,13 @@ jobs:
browser: chrome
project: ./examples/remote_procedure/mnist/webapp
config-file: ./cypress.config.js
start: python examples/remote_procedure/mnist/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
start: python examples/remote_procedure/mnist/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&id=1"
headless: true

remote_procedure_toxicity_detection:
needs: changes
if: ${{ (needs.changes.outputs.toxicity_detection == 'true') || (needs.changes.outputs.mephisto-core == 'true') }}
if: ${{ (needs.changes.outputs.toxicity_detection == 'true') || (needs.changes.outputs.mephisto-core == 'true') || (needs.changes.outputs.abstractions == 'true') || (needs.changes.outputs.data_model == 'true') || (needs.changes.outputs.operations == 'true') || (needs.changes.outputs.tools == 'true')}}
runs-on: ubuntu-latest
steps:
- name: 🔀 Checking out repo
Expand All @@ -456,7 +465,7 @@ jobs:
- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 🖋 Create Inhouse provider
- name: 🚚 Create Inhouse provider
run: mephisto register inhouse

- name: 📦 Setting up mephisto-core package
Expand All @@ -475,7 +484,7 @@ jobs:
project: ./examples/remote_procedure/toxicity_detection/webapp
config-file: ./cypress.config.js
start: python examples/remote_procedure/toxicity_detection/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
wait-on: "http://localhost:3000/?worker_id=x&id=1"
headless: true

# Learn more about this test here: https://github.com/facebookresearch/Mephisto/pull/833
Expand Down Expand Up @@ -507,6 +516,9 @@ jobs:
- name: 📂 Set the data directory
run: mephisto config core.main_data_directory ~/mephisto/data

- name: 🚚 Create Inhouse provider
run: mephisto register inhouse

- name: 📦 Setting up mephisto-core package
run: |
cd packages/mephisto-core
Expand All @@ -530,8 +542,8 @@ jobs:
project: ./examples/static_react_task_with_worker_opinion/webapp
config-file: ./cypress.config.js
spec: ./examples/static_react_task_with_worker_opinion/webapp/cypress/e2e/pre_submission_tests/*
start: python examples/static_react_task_with_worker_opinion/run_task.py mephisto.task.force_rebuild=true mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
start: python examples/static_react_task_with_worker_opinion/run_task__local__inhouse.py mephisto.task.force_rebuild=true mephisto.task.post_install_script=link_mephisto_task.sh
wait-on: "http://localhost:3000/?worker_id=x&id=1"
headless: true

- name: 🔪 Killing the web server
Expand Down Expand Up @@ -604,7 +616,7 @@ jobs:
project: ./examples/static_react_task_with_worker_opinion/webapp
config-file: cypress.config.js
spec: ./examples/static_react_task_with_worker_opinion/webapp/cypress/e2e/post_submission_tests/*
start: python examples/static_react_task_with_worker_opinion/run_task.py mephisto.task.post_install_script=link_mephisto_task.sh mephisto.task.force_rebuild=true
wait-on: "http://localhost:3000/?worker_id=x&assignment_id=1"
start: python examples/static_react_task_with_worker_opinion/run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh mephisto.task.force_rebuild=true
wait-on: "http://localhost:3000/?worker_id=x&id=1"
browser: chrome
headless: true
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ mephisto/scripts/metrics/*
# Examples
examples/simple_static_task/hydra_configs/conf/*
!examples/simple_static_task/hydra_configs/conf/example*.yaml
!examples/simple_static_task/hydra_configs/conf/prolific_example.yaml
!examples/simple_static_task/hydra_configs/conf/onboarding_example*.yaml
examples/**/build/*
examples/form_composer_demo/preview/*_preview.html

Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ We actively welcome your pull requests.
6. If you haven't already, complete the Contributor License Agreement ("CLA").

## Cypress Testing
For cypress testing the base url is: http://localhost:3000/?worker_id=x&assignment_id=1
For cypress testing the base url is: http://localhost:3000/?worker_id=x&id=1

### Running end-to-end tests on a task:
1. Run the task by running python run_task.py in the appropriate task folder
1. Run the task by running python `run_task__local__inhouse.py` in the appropriate task folder
2. In a separate terminal window go into the webapp directory and run `npm run test`
3. This should open a cypress app
4. It is advised to test in Chrome(Chrome, Electron, and Firefox are all the options) as this browser works well with Cypress.
Expand All @@ -40,7 +40,7 @@ Suppose you ran the toxicity detection task and then closed it. This would use a

If you then ran the mnist task, for example, then assignmentId=3 and assignmentId=4 would be used. While this task is running you can choose to run cypress tests in a different terminal window by going into the webapp folder and running `npm run test`.

These tests will fail because the base url of http://localhost:3000/?worker_id=x&assignment_id=1 is not associated with the mnist task, it is associated with the toxicity detection task. The correct react-elements will not show up.
These tests will fail because the base url of http://localhost:3000/?worker_id=x&id=1 is not associated with the mnist task, it is associated with the toxicity detection task. The correct react-elements will not show up.

There is a way to fix this:
* You can change the base url(found in the cypress.config.js file in the webapp folder) to the current url that you are on.
Expand All @@ -51,7 +51,7 @@ If you are modifying either the `mephisto-core` or `mephisto-addons` packages yo

The easiest way to do this is to run a task by doing:
```bash
python run_task.py mephisto.task.post_install_script=link_mephisto_task.sh mephisto.task.force_rebuild=true
python run_task__local__inhouse.py mephisto.task.post_install_script=link_mephisto_task.sh mephisto.task.force_rebuild=true
```

Setting `mephisto.task.force_rebuild=true` runs `npm build` before running your task. By default the task is only rebuilt if a file is changed in the webapp, not if a linked package is changed.
Expand All @@ -60,7 +60,7 @@ Setting `mephisto.task.post_install_script=link_mephisto_task.sh` runs the `link

Alternatively, these values can be set in the task's hydra_configs/conf yaml file if you want to forgo typing the above and just type
```bash
python run_task.py
python run_task__local__inhouse.py
```
instead.

Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.dev.vscode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ services:
/tmp/debugpy
--wait-for-client
--listen 0.0.0.0:5678
/mephisto/examples/simple_static_task/run_task.py
/mephisto/examples/simple_static_task/run_task__local__inhouse.py
",
]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To setup your local codebase to auto-lint and avoid lint test failures for your
This repo uses cypress to conduct frontend end-to-end tests. Tasks in the examples folder have cypress tests.

To run the tests for a task:
* Launch the task using `python run_task.py`.
* Launch the task using `python run_task__local__inhouse.py`.
* Open cypress by running `npm run test` in the tasks' webapp folder.
* Choose the Chrome browser to run the tests (it is the most consistent).
* Click one of the specs to run its tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ docker-compose -f docker/docker-compose.dev.yml run \
--build \
--publish 3001:3000 \
--rm mephisto_dc \
python /mephisto/examples/form_composer_demo/run_task.py
python /mephisto/examples/form_composer_demo/run_task__local__inhouse.py
```

## Customizing Docker settings
Expand Down Expand Up @@ -50,5 +50,5 @@ docker-compose -f docker/docker-compose.local.yml run \
--build \
--publish 3001:3000 \
--rm mephisto_dc \
python /mephisto/examples/form_composer_demo/run_task.py
python /mephisto/examples/form_composer_demo/run_task__local__inhouse.py
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ As you begin launching many Mephisto tasks, you may find that there are some spe

Setting up profiles is pretty easy, and makes it so that you don't have to be writing architect and crowdprovider args on every launch:
```
python run_task.py mephisto/architect=heroku mephisto/provider=mturk_sandbox mephisto.provider.requester_name=MY_REQUESTER
python run_task__local__inhouse.py mephisto/architect=heroku mephisto/provider=mturk_sandbox mephisto.provider.requester_name=MY_REQUESTER
```

Instead you can move these common configurations into a file in your `~/.mephisto/hydra_configs/profile` dir.
Expand Down Expand Up @@ -61,9 +61,9 @@ mephisto:
Then augmenting your launch configs is as easy as doing:
```
python run_task.py +profile=local_testing
python run_task__local__inhouse.py +profile=local_testing
...
python run_task.py +profile=live_launch
python run_task__local__inhouse.py +profile=live_launch
```

Using `profile` can be an effective way to simplify the configuration for your most common workflows.
2 changes: 1 addition & 1 deletion docs/web/docs/guides/how_to_use/form_composer/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sidebar_position: 4
A few tips if you wish to embed FormComposer in your custom application:

- To extrapolate form config (and generate the `task_data.json` file), call the extrapolator function `mephisto.generators.generators_utils.config_validation.task_data_config.create_extrapolated_config`
- For a live example, you can explore the source code of [run_task_dynamic.py](https://github.com/facebookresearch/Mephisto/blob/main/examples/form_composer_demo/run_task_dynamic.py) module
- For a live example, you can explore the source code of [run_task_dynamic.py](https://github.com/facebookresearch/Mephisto/blob/main/examples/form_composer_demo/run_task_dynamic__local__inhouse.py) module
- To use code insertions:
- for custom validators:
- Point `WEBAPP__GENERATOR__CUSTOM_VALIDATORS` backend env variable to the location of `custom_validators.js` module (before building all webapp applications)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You can specify Prolific qualifications via Task config file, or directly in Tas

### Usage in shared state

Shared state can handle Prolific-supported qualifications. Example in `run_task.py`:
Shared state can handle Prolific-supported qualifications. Example in `run_task__ec2__prolific.py`:

```python
shared_state.prolific_specific_qualifications = [
Expand Down
7 changes: 5 additions & 2 deletions docs/web/docs/guides/how_to_use/review_app/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ sidebar_position: 1

# Overview

Generally, to view/export the data, you could write a Python script using the Mephisto [`DataBrowser` class](https://github.com/facebookresearch/Mephisto/blob/main/mephisto/tools/data_browser.py) to access the submitted data.
Generally, to view/export the data, you could write a Python script using the Mephisto
[`DataBrowser` class](https://github.com/facebookresearch/Mephisto/blob/main/mephisto/tools/data_browser.py) to access the submitted data.

For example, for the `html-static-task-example` task such a script already exists in the task folder, called [`examine_results.py`](https://github.com/facebookresearch/Mephisto/blob/main/examples/simple_static_task/examine_results.py). (This file uses the Mephisto `DataBrowser` class through the helpers in `mephisto.tools.examine_utils`.)
For example, for the `html-static-task-example` task such a script already exists in the task folder,
called [`examine_results.py`](https://github.com/facebookresearch/Mephisto/blob/main/examples/simple_static_task/examine_results.py).
(This file uses the Mephisto `DataBrowser` class through the helpers in `mephisto.tools.examine_utils`.)

Another example is TaskReview app, an application with convenient rich UI.

Expand Down
Loading

0 comments on commit 598c8b3

Please sign in to comment.