mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-06 19:47:44 +00:00
chore: fix PR template (#487)
* fix PR template * subfolders of the log displayed on the web page * fix code error * add health check * reformat with isort * reformat with black * update README * fix bug && experience confusing * reformat with black & update health check code * reformat with isort * reformat with black * update README.md * Removed duplicates in documentation and health_check && Upgraded code for filtering folders * update docs * reformat with black
This commit is contained in:
+3
-1
@@ -25,10 +25,11 @@ from rdagent.app.kaggle.loop import main as kaggle_main
|
||||
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.
|
||||
"""
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -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__":
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import socket
|
||||
|
||||
import docker
|
||||
|
||||
from rdagent.log import rdagent_logger as logger
|
||||
|
||||
|
||||
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")
|
||||
print(logs)
|
||||
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():
|
||||
"""
|
||||
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()
|
||||
+21
-6
@@ -61,9 +61,25 @@ QLIB_SELECTED_METRICS = [
|
||||
|
||||
SIMILAR_SCENARIOS = (QlibModelScenario, DMModelScenario, QlibFactorScenario, QlibFactorFromReportScenario, KGScenario)
|
||||
|
||||
|
||||
def filter_log_folders(main_log_path):
|
||||
"""
|
||||
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)
|
||||
return folders
|
||||
|
||||
|
||||
if "log_path" not in state:
|
||||
if main_log_path:
|
||||
state.log_path = next(main_log_path.iterdir()).relative_to(main_log_path)
|
||||
state.log_path = filter_log_folders(main_log_path)[0]
|
||||
else:
|
||||
state.log_path = None
|
||||
st.toast(":red[**Please Set Log Path!**]", icon="⚠️")
|
||||
@@ -505,7 +521,7 @@ def research_window():
|
||||
# pdf image
|
||||
if pim := state.msgs[round]["r.extract_factors_and_implement.load_pdf_screenshot"]:
|
||||
for i in range(min(2, len(pim))):
|
||||
st.image(pim[i].content, use_column_width=True)
|
||||
st.image(pim[i].content, use_container_width=True)
|
||||
|
||||
# Hypothesis
|
||||
if hg := state.msgs[round]["r.hypothesis generation"]:
|
||||
@@ -526,7 +542,7 @@ def research_window():
|
||||
with c1:
|
||||
if pim := state.msgs[round]["r.pdf_image"]:
|
||||
for i in range(len(pim)):
|
||||
st.image(pim[i].content, use_column_width=True)
|
||||
st.image(pim[i].content, use_container_width=True)
|
||||
|
||||
# loaded model exp
|
||||
with c2:
|
||||
@@ -679,8 +695,7 @@ with st.sidebar:
|
||||
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()]
|
||||
folders = sorted(folders, key=lambda x: x.name)
|
||||
folders = filter_log_folders(main_log_path)
|
||||
st.selectbox(f"**Select from `{main_log_path}`**", folders, key="log_path", on_change=refresh)
|
||||
else:
|
||||
st.text_input(":blue[**log path**]", key="log_path", on_change=refresh)
|
||||
@@ -763,7 +778,7 @@ with st.container():
|
||||
image_c, scen_c = st.columns([3, 3], vertical_alignment="center")
|
||||
with image_c:
|
||||
img_path = rfiles("rdagent.log.ui").joinpath("flow.png")
|
||||
st.image(str(img_path), use_column_width=True)
|
||||
st.image(str(img_path), use_container_width=True)
|
||||
with scen_c:
|
||||
st.header("Scenario Description📖", divider="violet", anchor="_scenario")
|
||||
if state.scenario is not None:
|
||||
|
||||
Reference in New Issue
Block a user