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

CI checks that can be automatically repaired #119

Merged
merged 12 commits into from
Jul 26, 2024
Merged
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
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ jobs:
- run: env | sort
- run: make dev
- env:
# Two environment variables here can cause sphinx to fail to build in ci.
# CHAT_MAX_TOKENS: ${{ secrets.CHAT_MAX_TOKENS }}
# CHAT_TEMPERATURE: ${{ secrets.CHAT_TEMPERATURE }}
CHAT_AZURE_API_BASE: ${{ secrets.CHAT_AZURE_API_BASE }}
CHAT_AZURE_API_VERSION: ${{ secrets.CHAT_AZURE_API_VERSION }}
CHAT_MAX_TOKENS: ${{ secrets.CHAT_MAX_TOKENS }}
CHAT_MODEL: ${{ secrets.CHAT_MODEL }}
CHAT_TEMPERATURE: ${{ secrets.CHAT_TEMPERATURE }}
EMBEDDING_AZURE_API_BASE: ${{ secrets.CHAT_AZURE_API_BASE }}
EMBEDDING_AZURE_API_VERSION: ${{ secrets.CHAT_AZURE_API_VERSION }}
EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }}
name: lint test docs and build
run: make lint # test docs build sphinx
run: make lint docs-gen # test docs build
strategy:
matrix:
python-version:
Expand Down
29 changes: 23 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ constraints: deepclean

# Check lint with black.
black:
$(PIPRUN) python -m black --check . --extend-exclude test/scripts --extend-exclude git_ignore_folder -l 120

sphinx:
$(PIPRUN) sphinx-build -W --keep-going -b html ./docs _build
$(PIPRUN) python -m black --check --diff . --extend-exclude test/scripts --extend-exclude git_ignore_folder -l 120

# Check lint with isort.
isort:
Expand All @@ -107,13 +104,33 @@ toml-sort:
$(PIPRUN) toml-sort --check pyproject.toml

# Check lint with all linters.
# lint: black isort mypy ruff toml-sort
lint: mypy ruff
# Prioritize fixing isort, then black, otherwise you'll get weird and unfixable black errors.
# lint: mypy ruff
lint: mypy ruff isort black toml-sort

# Run pre-commit with autofix against all files.
pre-commit:
pre-commit run --all-files

########################################################################################
# Auto Lint
########################################################################################

# Auto lint with black.
auto-black:
$(PIPRUN) python -m black . --extend-exclude test/scripts --extend-exclude git_ignore_folder -l 120

# Auto lint with isort.
auto-isort:
$(PIPRUN) python -m isort . -s git_ignore_folder -s test/scripts

# Auto lint with toml-sort.
auto-toml-sort:
$(PIPRUN) toml-sort pyproject.toml

# Auto lint with all linters.
auto-lint: auto-isort auto-black auto-toml-sort

########################################################################################
# Test
########################################################################################
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
"sphinx.ext.autodoc",
]

autodoc_member_order = "bysource"
Expand Down
8 changes: 7 additions & 1 deletion docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ For Development
make dev
```

- Run linting and formatting.
- Run linting and checking.

```bash
make lint
```

- Some linting issues can be fixed automatically. We have added a command in the Makefile for easy use.

```bash
make auto-lint
```


Code Structure
=========================
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Welcome to RDAgent's documentation!
development
api_reference
policy
test_dropdown/test1

.. test_dropdown/test1

Expand Down
15 changes: 9 additions & 6 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ USE_AZURE_TOKEN_PROVIDER

### ☁️ Azure Configuration
- Install Azure CLI:
```sh
curl -L https://aka.ms/InstallAzureCli | bash
```

```sh
curl -L https://aka.ms/InstallAzureCli | bash
```

- Log in to Azure:
```sh
az login --use-device-code
```

```sh
az login --use-device-code
```

- `exit` and re-login to your environment (this step may not be necessary).

4 changes: 2 additions & 2 deletions docs/scenarios_and_quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Scenario lists
-

Scnarios' demo & quick start
=========================
============================

Scen1
-----
Expand Down Expand Up @@ -69,7 +69,7 @@ TODO: Show some examples:


Scen2:
-----
------
📄 Research Report-Based Factor Extraction

Scen2 Intro
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = [
"setuptools",
"setuptools-scm",
]
root= "rdagent"
root = "rdagent"

[project]
authors = [
Expand All @@ -27,14 +27,13 @@ dynamic = [
]
keywords = [
"Autonomous Agents",
"Research and Development",
"Large Language Models",
"Research and Development",
]
name = "rdagent"
readme = "README.md"
requires-python = ">=3.8"


[project.urls]
homepage = "https://github.com/microsoft/RD-Agent/"
issue = "https://github.com/microsoft/RD-Agent/issues"
Expand All @@ -52,13 +51,13 @@ color_output = true
profile = "black"

[tool.mypy]
explicit_package_bases = true
check_untyped_defs = true
disallow_any_unimported = true
disallow_untyped_defs = true
enable_error_code = [
"ignore-without-code",
]
explicit_package_bases = true
warn_return_any = true
warn_unused_ignores = true

Expand Down
7 changes: 3 additions & 4 deletions rdagent/app/data_mining/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from pathlib import Path


from rdagent.components.workflow.conf import BasePropSetting


Expand All @@ -19,11 +18,11 @@ class Config:

evolving_n: int = 10

# 2) Extra config for the scenario
# 2) Extra config for the scenario
# physionet account
# NOTE: You should apply the account in https://physionet.org/
username: str = ''
password: str = ''
username: str = ""
password: str = ""


PROP_SETTING = PropSetting()
2 changes: 2 additions & 0 deletions rdagent/app/data_mining/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fire

from rdagent.app.data_mining.conf import PROP_SETTING
from rdagent.components.workflow.rd_loop import RDLoop
from rdagent.core.exception import ModelEmptyError


class ModelRDLoop(RDLoop):
skip_loop_error = (ModelEmptyError,)

Expand Down
30 changes: 19 additions & 11 deletions rdagent/app/qlib_rd_loop/RDAgent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pickle

from rdagent.app.qlib_rd_loop.conf import PROP_SETTING
from rdagent.core.developer import Developer
from rdagent.core.exception import ModelEmptyError
Expand All @@ -12,6 +13,7 @@
from rdagent.core.utils import import_class
from rdagent.log import rdagent_logger as logger


# TODO: we can design a workflow that can automatically save session and traceback in the future
class Model_RD_Agent:
def __init__(self):
Expand All @@ -20,50 +22,55 @@ def __init__(self):
self.hypothesis2experiment: Hypothesis2Experiment = import_class(PROP_SETTING.model_hypothesis2experiment)()
self.qlib_model_coder: Developer = import_class(PROP_SETTING.model_coder)(self.scen)
self.qlib_model_runner: Developer = import_class(PROP_SETTING.model_runner)(self.scen)
self.qlib_model_summarizer: HypothesisExperiment2Feedback = import_class(PROP_SETTING.model_summarizer)(self.scen)
self.qlib_model_summarizer: HypothesisExperiment2Feedback = import_class(PROP_SETTING.model_summarizer)(
self.scen
)
self.trace = Trace(scen=self.scen)

def generate_hypothesis(self):
hypothesis = self.hypothesis_gen.gen(self.trace)
self.dump_objects(hypothesis=hypothesis, trace=self.trace, filename='step_hypothesis.pkl')
self.dump_objects(hypothesis=hypothesis, trace=self.trace, filename="step_hypothesis.pkl")
return hypothesis

def convert_hypothesis(self, hypothesis):
exp = self.hypothesis2experiment.convert(hypothesis, self.trace)
self.dump_objects(exp=exp, hypothesis=hypothesis, trace=self.trace, filename='step_experiment.pkl')
self.dump_objects(exp=exp, hypothesis=hypothesis, trace=self.trace, filename="step_experiment.pkl")
return exp

def generate_code(self, exp):
exp = self.qlib_model_coder.develop(exp)
self.dump_objects(exp=exp, trace=self.trace, filename='step_code.pkl')
self.dump_objects(exp=exp, trace=self.trace, filename="step_code.pkl")
return exp

def run_experiment(self, exp):
exp = self.qlib_model_runner.develop(exp)
self.dump_objects(exp=exp, trace=self.trace, filename='step_run.pkl')
self.dump_objects(exp=exp, trace=self.trace, filename="step_run.pkl")
return exp

def generate_feedback(self, exp, hypothesis):
feedback = self.qlib_model_summarizer.generate_feedback(exp, hypothesis, self.trace)
self.dump_objects(exp=exp, hypothesis=hypothesis, feedback=feedback, trace=self.trace, filename='step_feedback.pkl')
self.dump_objects(
exp=exp, hypothesis=hypothesis, feedback=feedback, trace=self.trace, filename="step_feedback.pkl"
)
return feedback

def append_to_trace(self, hypothesis, exp, feedback):
self.trace.hist.append((hypothesis, exp, feedback))
self.dump_objects(trace=self.trace, filename='step_trace.pkl')
self.dump_objects(trace=self.trace, filename="step_trace.pkl")

def dump_objects(self, exp=None, hypothesis=None, feedback=None, trace=None, filename='dumped_objects.pkl'):
with open(filename, 'wb') as f:
def dump_objects(self, exp=None, hypothesis=None, feedback=None, trace=None, filename="dumped_objects.pkl"):
with open(filename, "wb") as f:
pickle.dump((exp, hypothesis, feedback, trace or self.trace), f)

def load_objects(self, filename):
with open(filename, 'rb') as f:
with open(filename, "rb") as f:
return pickle.load(f)


def process_steps(agent):
# Load trace if available
try:
_, _, _, trace = agent.load_objects('step_trace.pkl')
_, _, _, trace = agent.load_objects("step_trace.pkl")
agent.trace = trace
print(trace.get_sota_hypothesis_and_experiment())
except FileNotFoundError:
Expand Down Expand Up @@ -99,6 +106,7 @@ def process_steps(agent):
# # Step 6: Append to trace
# agent.append_to_trace(hypothesis, exp, feedback)


if __name__ == "__main__":
agent = Model_RD_Agent()
process_steps(agent)
Loading