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

chore: fix PR template #487

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
4 changes: 1 addition & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@

## How Has This Been Tested?
<!--- Put an `x` in all the boxes that apply: --->
- [ ] Pass the test by running: `pytest qlib/tests/test_all_pipeline.py` under upper directory of `qlib`.
- [ ] If you are adding a new feature, test on your own test scripts.

<!--- **ATTENTION**: If you are adding a new feature, please make sure your codes are **correctly tested**. If our test scripts do not cover your cases, please provide your own test scripts under the `tests` folder and test them. More information about test scripts can be found [here](https://docs.python.org/3/library/unittest.html#basic-example), or you could refer to those we provide under the `tests` folder. -->

## Screenshots of Test Results (if appropriate):
1. Pipeline test:
2. Your own tests:
1. Your own tests:

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
Expand Down
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ You can try above demos by running the following command:
### 🐳 Docker installation.
Users must ensure Docker is installed before attempting most scenarios. Please refer to the [official 🐳Docker page](https://docs.docker.com/engine/install/) for installation instructions.

**Note:** rdagent provides a command to check if the docker installation was successful.
```sh
rdagent health_check
```

### 🐍 Create a Conda Environment
- Create a new conda environment with Python (3.10 and 3.11 are well-tested in our CI):
```sh
Expand All @@ -84,14 +89,30 @@ Users must ensure Docker is installed before attempting most scenarios. Please r
```

### ⚙️ Configuration
- You have to config your GPT model in the `.env`
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
- The demos requires following ability:
- ChatCompletion
- json_mode
- embedding query

- For example: If you are using the `OpenAI API`, you have to configure your GPT model in the `.env` file like this.
```bash
cat << EOF > .env
OPENAI_API_KEY=<your_api_key>
OPENAI_API_KEY=<replace_with_your_openai_api_key>
# EMBEDDING_MODEL=text-embedding-3-small
CHAT_MODEL=gpt-4-turbo
EOF
```
- However, not every API services support these features by devault. For example: `AZURE OpenAI`, you have to configure your GPT model in the `.env` file like this.
```bash
cat << EOF > .env
USE_AZURE=True
OPENAI_API_KEY=<replace_with_your_azure_openai_api_key>
# EMBEDDING_MODEL=text-embedding-3-small
CHAT_MODEL=<replace_it_with_the_name_of_your_chat_model.>
CHAT_AZURE_API_VERSION=<replace_with_the_version_of_your_Azure_OpenAI_API>
EOF
```
- For more configuration information, please refer to the [documentation](https://rdagent.readthedocs.io/en/latest/installation_and_configuration.html).

### 🚀 Run the Application

Expand Down Expand Up @@ -170,9 +191,18 @@ The **[🖥️ Live Demo](https://rdagent.azurewebsites.net/)** is implemented b
> - The **Competition List Available** can be found [here](https://rdagent.readthedocs.io/en/latest/scens/kaggle_agent.html#competition-list-available). <br />

### 🖥️ Monitor the Application Results
- You can serve our demo app to monitor the RD loop by running the following command:
- You can run the following command for our demo program to see the run logs.

```sh
rdagent ui --port 80 --log_dir <your log folder like "log/">
rdagent ui --port 19899 --log_dir <your log folder like "log/">
```

**Note:** Although port 19899 is not commonly used, but before you run this demo, you need to check if port 19899 is occupied. If it is, please change it to another port that is not occupied.

You can check if a port is occupied by running the following command.

```sh
rdagent health_check
```

# 🏭 Scenarios
Expand Down Expand Up @@ -211,7 +241,15 @@ Different scenarios vary in entrance and configuration. Please check the detaile
Here is a gallery of [successful explorations](https://github.com/SunsetWolf/rdagent_resource/releases/download/demo_traces/demo_traces.zip) (5 traces showed in **[🖥️ Live Demo](https://rdagent.azurewebsites.net/)**). You can download and view the execution trace using the command below:

```bash
rdagent ui --port 80 --log_dir ./demo_traces
rdagent ui --port 19899 --log_dir ./demo_traces
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
```

**Note:** Although port 19899 is not commonly used, but before you run this demo, you need to check if port 19899 is occupied. If it is, please change it to another port that is not occupied.

You can check if a port is occupied by running the following command.

```sh
rdagent health_check
```

Please refer to **[📖readthedocs_scen](https://rdagent.readthedocs.io/en/latest/scens/catalog.html)** for more details of the scenarios.
Expand Down
4 changes: 3 additions & 1 deletion rdagent/app/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
from rdagent.app.qlib_rd_loop.factor import main as fin_factor
from rdagent.app.qlib_rd_loop.factor_from_report import main as fin_factor_report
from rdagent.app.qlib_rd_loop.model import main as fin_model
from rdagent.app.utils.health_check import health_check
from rdagent.app.utils.info import collect_info


def ui(port=80, log_dir="", debug=False):
def ui(port=19899, log_dir="", debug=False):
"""
start web app to show the log traces.
"""
Expand All @@ -52,6 +53,7 @@ def app():
"med_model": med_model,
"general_model": general_model,
"ui": ui,
"health_check": health_check,
"collect_info": collect_info,
"kaggle": kaggle_main,
}
Expand Down
1 change: 0 additions & 1 deletion rdagent/app/general_model/general_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def extract_models_and_implement(report_file_path: str) -> None:
with logger.tag("d"):
exp = QlibModelCoSTEER(scenario).develop(exp)
logger.log_object(exp, tag="developed_experiment")
return exp


if __name__ == "__main__":
Expand Down
62 changes: 62 additions & 0 deletions rdagent/app/utils/health_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import socket

import docker

from rdagent.log import rdagent_logger as logger

SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved

def run_hello_world():
try:
client = docker.from_env()
client.images.pull("hello-world")
container = client.containers.run("hello-world", detach=True)
logs = container.logs().decode("utf-8")
print(logs)
container.remove()
print("Container removed successfully.")
except docker.errors.DockerException as e:
print(f"An error occurred: {e}")
return logs


def check_docker() -> None:
try:
client = docker.from_env()
client.images.pull("hello-world")
container = client.containers.run("hello-world", detach=True)
logs = container.logs().decode("utf-8")
container.remove()
logger.info(f"The docker status is normal")
except docker.errors.DockerException as e:
logger.error(f"An error occurred: {e}")
logger.warning(
f"Docker status is exception, please check the docker configuration or reinstall it. Refs: https://docs.docker.com/engine/install/ubuntu/."
)


def is_port_in_use(port):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
return s.connect_ex(("127.0.0.1", port)) == 0


def check_and_list_free_ports(start_port=19899, max_ports=10) -> None:
is_occupied = is_port_in_use(port=start_port)
if is_occupied:
free_ports = []
for port in range(start_port, start_port + max_ports):
if not is_port_in_use(port):
free_ports.append(port)
logger.warning(
f"Port 19899 is occupied, please replace it with an available port when running the `rdagent ui` command. Available ports: {free_ports}"
)
else:
logger.info(f"Port 19899 is not occupied, you can run the `rdagent ui` command")


def health_check():
SunsetWolf marked this conversation as resolved.
Show resolved Hide resolved
"""
Check that docker is installed correctly,
and that the ports used in the sample README are not occupied.
"""
check_docker()
check_and_list_free_ports()
17 changes: 11 additions & 6 deletions rdagent/log/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@
SIMILAR_SCENARIOS = (QlibModelScenario, DMModelScenario, QlibFactorScenario, QlibFactorFromReportScenario, KGScenario)

if "log_path" not in state:
if main_log_path:
state.log_path = next(main_log_path.iterdir()).relative_to(main_log_path)
else:
state.log_path = None
st.toast(":red[**Please Set Log Path!**]", icon="⚠️")
state.log_path = None

if "scenario" not in state:
state.scenario = None
Expand Down Expand Up @@ -681,7 +677,16 @@ def evolving_window():
if manually:
st.text_input("log path", key="log_path", on_change=refresh, label_visibility="collapsed")
else:
folders = [folder.relative_to(main_log_path) for folder in main_log_path.iterdir() if folder.is_dir()]
# The webpage only displays valid folders.
# If the __session__ folder exists in a subfolder of the log folder, it is considered a valid folder,
# otherwise it is considered an invalid folder.
folders = [
folder.relative_to(main_log_path)
for folder in main_log_path.iterdir()
if folder.is_dir()
and folder.joinpath("__session__").exists()
and folder.joinpath("__session__").is_dir()
]
folders = sorted(folders, key=lambda x: x.name)
st.selectbox(f"**Select from `{main_log_path}`**", folders, key="log_path", on_change=refresh)
else:
Expand Down