Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: New documentation #264

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 13 additions & 60 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
# Contributing to dynabench

We want to make contributing to this project as easy and transparent as
possible.

## Pull Requests

We actively welcome your pull requests.

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
4. Make sure your code lints.
5. If you haven't already, complete the Contributor License Agreement ("CLA").

## Coding Style

* In your editor, install the [editorconfig](https://editorconfig.org/) extension which should ensure that you are following the same standards as us.
* Dynabench uses pre-commit hooks to ensure style consistency and prevent common mistakes. Enable it by:
- In your editor, install the [editorconfig](https://editorconfig.org/) extension which should ensure that you are following the same standards as us.
- Dynabench uses pre-commit hooks to ensure style consistency and prevent common mistakes. Enable it by:

```sh
pip install pre-commit && pre-commit install
```

After this pre-commit hooks will be run before every commit.

* Read the [editorconfig](https://github.com/mlcommons/dynabench/blob/main/.editorconfig) file to understand the exact coding style preferences.
- Read the [editorconfig](https://github.com/mlcommons/dynabench/blob/main/.editorconfig) file to understand the exact coding style preferences.

* Ideally, black and isort should be run via pre-commit hooks.
But if for some reason you want to run black and isort separately follow this:
- Ideally, black and isort should be run via pre-commit hooks.
But if for some reason you want to run black and isort separately follow this:

``` bash
```bash

pip install black==22.3.0 isort==4.3.21
black ./(mmf|tests|tools)/**/*.py
Expand All @@ -38,62 +39,14 @@ isort -rc (mmf|tests|tools)

Before commit your changes to your branch run the pre-commit hooks and make sure your code pass all the tests. If your code fail a test, fix it and then commit.

__Note:__ If any linter doesn't pass, your pull request is not going to be accepted.

## Migrations

We are using [yoyo-migrations](https://ollycope.com/software/yoyo/latest/) tool to do our schema migrations in a systematic manner.
By default, yoyo should run any pending migrations automatically to your database.

To add or update the database schema, you will have to create a new migration following these steps:

* `cd api`
* Call `yoyo new ./migrations -m "Message describing your schema change"`
* This will open up an editor with all of the previous dependency migrations already added.
In the `step` call inside the template, you will add two queries, first argument is the query
you actually want to perform and second is the query to rollback your change.
* Add your migration queries, save the file and exit the editor.
* yoyo should create a new migration script for your queries.
* Commit these, create a PR and next time anybody launches there server after the pull, migrations
should get applied automatically.

An example of adding `api_token` field to table `users` looks like following:

```py
"""
Add api_token to users
"""

from yoyo import step

__depends__ = {}

steps = [
step(
"ALTER TABLE users ADD COLUMN api_token VARCHAR(255)",
"ALTER TABLE users DROP COLUMN api_token",
)
]
```

You can read more on yoyo in its [documentation](https://ollycope.com/software/yoyo/latest/).

> NOTE: Don't do manual CUD queries to database anymore, this can leave yoyo in a weird state

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>
**Note:** If any linter doesn't pass, your pull request is not going to be accepted.

## Issues

We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## License

By contributing to dynabench, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
Dynabench is a research platform for dynamic data collection and benchmarking.

Documentation:

1. [Platform overview](https://github.com/mlcommons/dynabench/blob/main/docs/overview.md)
2. [Developer guide](https://github.com/mlcommons/dynabench/blob/main/docs/start.md)
3. [Contributing guidelines](https://github.com/mlcommons/dynabench/blob/main/CONTRIBUTING.md)
4. [Task owners manual](https://github.com/mlcommons/dynabench/blob/main/docs/owners.md)
5. [Evaluation Server Developer Guide](https://github.com/mlcommons/dynabench/blob/main/docs/evaluation.md) [Possibly Outdated]
6. [Frontend Developer Guide](https://github.com/mlcommons/dynabench/blob/main/docs/frontend.md) [Possibly Outdated]

## License

Expand Down
104 changes: 36 additions & 68 deletions docs/start.md
Original file line number Diff line number Diff line change
@@ -1,96 +1,64 @@
# Development
## Dynabench Components Overview

Please read our [contributing guidelines](https://github.com/mlcommons/dynabench/blob/main/CONTRIBUTING.md) to understand how to setup your development environment including `pre-commit` hooks.
Dynabench currently consists of three main components:

## Clone the repository
### Old Backend

After forking [facebookresearch/dynabench](https://github.com/mlcommons/dynabench) to your own GitHub account, clone the forked repo using:
This backend is located in the `API` folder. Currently, the main functionality is the login system. To run this backend, follow these steps:

```
git clone [email protected]:{your_github_username}/dynabench.git
cd dynabench
```
1. Create a virtual environment (conda or venv can be used) (`python3 -m venv env`).
2. Activate the environment (`source env/bin/activate`).
3. Install the libraries from the `requirements` folder (`python3 -m pip install -r requirements.txt`).
4. Run the command: `python3 server.py dev`.

## Backend
**Note:** Remember to set the environment variables to run the backend, there is a an example of this file is called .env.example inside the `API` folder.

The backend is written in Python and requires a locally installed MySQL database.
### New Backend

### Prerequisites
The new backend is located in the `backend` folder. This is the core of the application, following a hexagonal architecture. It is composed of three main folders inside the `app`:

We recommend using Conda to create an environment for the backend and easily managing the dependencies. The following will install all of the dependencies required by the backend server:
- **API:** Endpoints reside in this folder. No business logic should be implemented in these endpoints.
- **Domain:** This folder contains all the logic of the functions, both programming and business.
- **Infrastructure:** Here, calls to the database are made using SQLAlchemy.

```
conda create -n dev python=3.7
conda activate dev
pip install -r requirements.txt
```
To install the new backend, follow the same steps as for the API, with the last command being:

Next, follow these [instructions to install MySQL](database.md).
`python3 -m uvicorn app.main:app --reload`

### Configuration
**Note:** Remember to set the environment variables to run the backend, there is a an example of this file is called .env.example inside the `backend` folder.

Set up your SSL certificates, e.g.:
### Frontend

```
mkdir ~/.ssl
cd ~/.ssl
openssl req -newkey rsa:2048 -x509 -new -nodes -keyout local-cert.key -out local-cert.crt -subj /CN=test1 -sha256 -days 365 -addext "extendedKeyUsage = serverAuth"
cat local-cert.key local-cert.crt > local-cert.pem
chmod 600 *
ln -s local-cert.key dynabench.org-key.pem
ln -s local-cert.crt dynabench.org.crt
```
The main frontend is located in the `frontends/web` folder. Inside this folder, you will find a folder called `src/new_front`. About 99% of new changes should be made inside this folder.

### Setting up the API server
To install the frontend, follow these steps:

Run the installation script to create your configuration files and ensure all outstanding database migrations are marked as completed:
1. Ensure that Node.js and npm are installed.
2. Run `npm i` (you may need to run it with the `--legacy-peer-deps` flag).
3. Run `npm run start`.

```
cd api
python install.py
```
**Note:** Remember to configure the environment variables, there is a an example of this file is called .env.example inside the `frontends/web` folder.

The script will ask you a list of questions to fill in the config file (in `api/common/config.py`). The answers will look like as follows:
```
Please enter your db_name: dynabench
Please enter your db_user: dynabench
Please enter your db_password: {use the password you set in MySQL install instructions}
Please enter your ssl_cert_file_path: {home directory path}/.ssl/dynabench.org.crt
Please enter your ssl_org_pem_file_path: {home directory path}/.ssl/dynabench.org-key.pem
```
## DB

### Running the API server
To migrate the database you can use the following link that comes with some artifacts:

Run the server:
https://models-dynalab.s3.eu-west-3.amazonaws.com/sql/db.sql

```
cd api
python server.py dev
```
## Types of Challenges in Dynabench

Your API backend should now be running at https://localhost:8081. If you just generated a local and unverified certificate, you may need to tell your browser it's okay to proceed.
Dynabench currently features three different types of challenges:

## Frontend
### Creation of Examples

To install and run the frontend, we recommend using [nvm](https://github.com/creationix/nvm) (see [here](https://github.com/nvm-sh/nvm#installing-and-updating) for installation instructions) to manage and install node versions.
Challenges falling under this category include PRISM, Wonders, Help-me, and Nibbler. To host the various interface types from the frontend, we utilize the strategy design pattern. Modifying components not adjustable from the YAML file requires specific actions:

```
cd frontends/web/
nvm install node
nvm install-latest-npm
npm install
echo 'REACT_APP_API_HOST = "https://localhost:8081"' >> .env
npm start
```
1. **Identify the YAML File:** Begin by accessing the YAML of the respective task.

If you get a warning about SSL certificates, edit the corresponding paths in `package.json`. Your frontend should now be running at https://localhost:3000.
2. **Check Context Type:** Determine the type of context.

## Docker Compose
Alternatively, you can run the following two commands to setup both backend and frontend locally:
3. **Locate Equivalence in Interface Options:** Navigate to `frontends/web/src/new_front/utils/creation_interface_options.json` and find the equivalence of the component used.

```
docker-compose build --no-cache
docker-compose up
```
4. **Identify Component in Codebase:** Proceed to `frontends/web/src/new_front/components/CreateSamples/CreateSamples/AnnotationInterfaces/Contexts` and identify the component.

Backend will be running on localhost:8081 and Frontend will be running on localhost:3000.
This process ensures efficient modification of components within the Dynabench platform.
Loading