diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..f30443ba --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: + - MIIC-finance diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..cd494ea0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,19 @@ +updates: + - commit-message: + prefix: build(actions) + directory: / + package-ecosystem: github-actions + schedule: + interval: weekly + - commit-message: + prefix: build(requirements) + directory: / + groups: + dev: + dependency-type: development + prod: + dependency-type: production + package-ecosystem: pip + schedule: + interval: weekly +version: 2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..f94fa6bf --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,93 @@ +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + ci: + if: ${{ !cancelled() && ! failure() }} + needs: dependabot + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + submodules: recursive + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + cache: pip + python-version: ${{ matrix.python-version }} + - run: env | sort + - run: make dev + - env: + AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT: ${{ secrets.AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT }} + AZURE_DOCUMENT_INTELLIGENCE_KEY: ${{ secrets.AZURE_DOCUMENT_INTELLIGENCE_KEY }} + 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_OPENAI_API_KEY: ${{ secrets.CHAT_OPENAI_API_KEY }} + CHAT_TEMPERATURE: ${{ secrets.CHAT_TEMPERATURE }} + CONTINOUS_MODE: ${{ secrets.CONTINOUS_MODE }} + EMBEDDING_AZURE_API_BASE: ${{ secrets.CHAT_AZURE_API_BASE }} + EMBEDDING_AZURE_API_VERSION: ${{ secrets.CHAT_AZURE_API_VERSION }} + EMBEDDING_MODEL: ${{ secrets.EMBEDDING_MODEL }} + EMBEDDING_OPENAI_API_KEY: ${{ secrets.CHAT_OPENAI_API_KEY }} + MAX_RETRY: ${{ secrets.MAX_RETRY }} + RETRY_WAIT_SECONDS: ${{ secrets.RETRY_WAIT_SECONDS }} + USE_AZURE: ${{ secrets.USE_AZURE }} + name: lint test docs and build + run: make lint test docs build + strategy: + matrix: + python-version: + - '3.8' + - '3.9' + - '3.10' + - '3.11' + dependabot: + if: ${{ github.actor == 'dependabot[bot]' && startsWith(github.head_ref, 'dependabot/pip/') }} + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.head_ref }} + - name: Set up Git + run: | + git config --global user.name github-actions + git config --global user.email github-actions@github.com + - name: Set up Python with multiple versions. + uses: actions/setup-python@v5 + with: + cache: pip + python-version: | + 3.8 + 3.9 + 3.10 + 3.11 + - name: Install pipenv using pipx + run: pipx install pipenv + - name: Generate constraints for all supported Python versions + run: | + CI= PYTHON_VERSION=3.8 make constraints + CI= PYTHON_VERSION=3.9 make constraints + CI= PYTHON_VERSION=3.10 make constraints + CI= PYTHON_VERSION=3.11 make constraints + - name: Push changes if applicable + run: | + if [[ -n `git status --porcelain` ]]; then + git commit -a -m "build: Update constraints for dependabot." + git push + fi +name: CI +on: + pull_request: + types: + - opened + - synchronize + push: + branches: + - master diff --git a/.github/workflows/readthedocs-preview.yml b/.github/workflows/readthedocs-preview.yml new file mode 100644 index 00000000..39d55c32 --- /dev/null +++ b/.github/workflows/readthedocs-preview.yml @@ -0,0 +1,17 @@ +concurrency: + cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} +jobs: + documentation-links: + runs-on: ubuntu-latest + steps: + - uses: readthedocs/actions/preview@v1 + with: + project-slug: fincov2 +name: Read the Docs Pull Request Preview +on: + pull_request_target: + types: + - opened +permissions: + pull-requests: write diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..9be28887 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,91 @@ +jobs: + package: + needs: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + cache: pip + python-version: '3.8' + - run: env | sort + - run: make dev-package + - run: make build + - env: + TWINE_NON_INTERACTIVE: true + TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} + TWINE_USERNAME: ${{ vars.TWINE_USERNAME != '' && vars.TWINE_USERNAME || '__token__' }} + run: make upload + pages-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + cache: pip + python-version: '3.8' + - run: env | sort + - run: make dev-docs + - run: make docs + - name: Upload changelog + uses: actions/upload-artifact@v4 + with: + name: changelog + path: docs/changelog.md + - name: Upload pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: public + pages-deploy: + needs: release + permissions: + id-token: write + pages: write + runs-on: ubuntu-latest + steps: + - id: deployment + name: Deploy to GitHub Pages + uses: actions/deploy-pages@v4 + release: + needs: pages-build + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install git-changelog using pipx + run: pipx install git-changelog + - name: Remove changelog to avoid file already exists error + run: rm -v docs/changelog.md + - name: Download changelog + uses: actions/download-artifact@v4 + with: + name: changelog + path: docs/ + - name: Prepare release notes + run: make release-notes > release-notes.md + - id: prerelease + name: Determine prerelease + run: | + if [[ "${{ github.ref }}" =~ (a|b|rc)(0|[1-9][0-9]*)?$ ]]; then + echo "is_prerelease=true" > $GITHUB_OUTPUT + else + echo "is_prerelease=false" > $GITHUB_OUTPUT + fi + - name: Create GitHub release + uses: softprops/action-gh-release@v1 + with: + body_path: release-notes.md + prerelease: ${{ steps.prerelease.outputs.is_prerelease }} +name: Release +on: + push: + tags: + - v?[0-9]+.[0-9]+.[0-9]+ + - v?[0-9]+.[0-9]+.[0-9]+-?a[0-9]* + - v?[0-9]+.[0-9]+.[0-9]+-?b[0-9]* + - v?[0-9]+.[0-9]+.[0-9]+-?rc[0-9]* diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a2f36f10 --- /dev/null +++ b/.gitignore @@ -0,0 +1,155 @@ +# Custom +*.swp +.DS_Store +Pipfile +public +release-notes.md + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# all pkl files +*.pkl + +# all vs-code files +.vscode/ + +# reports +reports/ + +# git_ignore_folder +git_ignore_folder/ + +#cache +*cache*/ +*cache.json + +# DB files +*.db diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..8c2b4cf8 --- /dev/null +++ b/Makefile @@ -0,0 +1,178 @@ +.PHONY: clean deepclean install init-qlib-env dev constraints black isort mypy ruff toml-sort lint pre-commit test-run test build upload docs-autobuild changelog docs-gen docs-mypy docs-coverage docs +#You can modify it according to your terminal +SHELL := /bin/bash + +######################################################################################## +# Variables +######################################################################################## + +# Determine whether to invoke pipenv based on CI environment variable and the availability of pipenv. +PIPRUN := $(shell [ "$$CI" != "true" ] && command -v pipenv > /dev/null 2>&1 && echo "pipenv run") + +# Get the Python version in `major.minor` format, using the environment variable or the virtual environment if exists. +PYTHON_VERSION := $(shell echo $${PYTHON_VERSION:-$$(python -V 2>&1 | cut -d ' ' -f 2)} | cut -d '.' -f 1,2) + +# Determine the constraints file based on the Python version. +CONSTRAINTS_FILE := constraints/$(PYTHON_VERSION).txt + +# Documentation target directory, will be adapted to specific folder for readthedocs. +PUBLIC_DIR := $(shell [ "$$READTHEDOCS" = "True" ] && echo "$$READTHEDOCS_OUTPUT/html" || echo "public") + +# URL and Path of changelog source code. +CHANGELOG_URL := $(shell echo $${CI_PAGES_URL:-https://peteryang1.github.io/fincov2}/_sources/changelog.md.txt) +CHANGELOG_PATH := docs/changelog.md + +######################################################################################## +# Development Environment Management +######################################################################################## + +# Remove common intermediate files. +clean: + -rm -rf \ + $(PUBLIC_DIR) \ + .coverage \ + .mypy_cache \ + .pytest_cache \ + .ruff_cache \ + Pipfile* \ + coverage.xml \ + dist \ + release-notes.md + find . -name '*.egg-info' -print0 | xargs -0 rm -rf + find . -name '*.pyc' -print0 | xargs -0 rm -f + find . -name '*.swp' -print0 | xargs -0 rm -f + find . -name '.DS_Store' -print0 | xargs -0 rm -f + find . -name '__pycache__' -print0 | xargs -0 rm -rf + +# Remove pre-commit hook, virtual environment alongside itermediate files. +deepclean: clean + if command -v pre-commit > /dev/null 2>&1; then pre-commit uninstall --hook-type pre-push; fi + if command -v pipenv >/dev/null 2>&1 && pipenv --venv >/dev/null 2>&1; then pipenv --rm; fi + +# Install the package in editable mode. +install: + $(PIPRUN) pip install -e . -c $(CONSTRAINTS_FILE) + +# Install the package in editable mode with specific optional dependencies. +dev-%: + $(PIPRUN) pip install -e .[$*] -c $(CONSTRAINTS_FILE) + +# Prepare the development environment. +# Build submodules. +# Install the pacakge in editable mode with all optional dependencies and pre-commit hook. +init-qlib-env: + # note: You may need to install torch manually + # todo: downgrade ruamel.yaml in pyqlib + conda create -n qlibFinCo python=3.8 -y + @source $$(conda info --base)/etc/profile.d/conda.sh && conda activate qlibFinCo && which pip && pip install pyqlib && pip install ruamel-yaml==0.17.21 && pip install torch==2.1.1 && pip install catboost==0.24.3 && conda deactivate + +dev: + $(PIPRUN) pip install -e .[docs,lint,package,test] -c $(CONSTRAINTS_FILE) + if [ "$(CI)" != "true" ] && command -v pre-commit > /dev/null 2>&1; then pre-commit install --hook-type pre-push; fi + +# Generate constraints for current Python version. +constraints: deepclean + $(PIPRUN) --python $(PYTHON_VERSION) pip install --upgrade -e .[docs,lint,package,test] + $(PIPRUN) pip freeze --exclude-editable > $(CONSTRAINTS_FILE) + +######################################################################################## +# Lint and pre-commit +######################################################################################## + +# Check lint with black. +black: + $(PIPRUN) python -m black --check . --exclude finco --extend-exclude test/scripts --extend-exclude git_ignore_folder -l 120 + +# Check lint with isort. +isort: + $(PIPRUN) python -m isort --check . -s FinCo -s finco -s git_ignore_folder -s test/scripts + +# Check lint with mypy. +mypy: + $(PIPRUN) python -m mypy . --exclude FinCo --exclude finco --exclude rdagent/scripts --exclude test/scripts --exclude git_ignore_folder + +# Check lint with ruff. +ruff: + $(PIPRUN) python -m ruff . --exclude FinCo,finco,rdagent/scripts,test/scripts,git_ignore_folder --ignore ANN101,ANN401,TCH003,D,ERA001,PLR0913,S101 --line-length 120 + +# Check lint with toml-sort. +toml-sort: + $(PIPRUN) toml-sort --check pyproject.toml + +# Check lint with all linters. +lint: black isort mypy ruff toml-sort + +# Run pre-commit with autofix against all files. +pre-commit: + pre-commit run --all-files + +######################################################################################## +# Test +######################################################################################## + +# Clean and run test with coverage. +test-run: + $(PIPRUN) python -m coverage erase + $(PIPRUN) python -m coverage run --concurrency=multiprocessing -m pytest --ignore FinCo --ignore test/finco --ignore test/scripts + $(PIPRUN) python -m coverage combine + +# Generate coverage report for terminal and xml. +test: test-run + $(PIPRUN) python -m coverage report --fail-under 80 + $(PIPRUN) python -m coverage xml --fail-under 80 + +######################################################################################## +# Package +######################################################################################## + +# Build the package. +build: + $(PIPRUN) python -m build + +# Upload the package. +upload: + $(PIPRUN) python -m twine upload dist/* + +######################################################################################## +# Documentation +######################################################################################## + +# Generate documentation with auto build when changes happen. +docs-autobuild: + $(PIPRUN) python -m sphinx_autobuild docs $(PUBLIC_DIR) \ + --watch README.md \ + --watch rdagent + +# Generate changelog from git commits. +# NOTE(xuan.hu): Need to be run before document generation to take effect. +changelog: + @if wget -q --spider $(CHANGELOG_URL); then \ + echo "Existing Changelog found at '$(CHANGELOG_URL)', download for incremental generation."; \ + wget -q -O $(CHANGELOG_PATH) $(CHANGELOG_URL); \ + fi + $(PIPRUN) git-changelog -ETrio $(CHANGELOG_PATH) -c conventional -s build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test + +# Generate release notes from changelog. +release-notes: + @$(PIPRUN) git-changelog --input $(CHANGELOG_PATH) --release-notes + +# Build documentation only from rdagent. +docs-gen: + $(PIPRUN) python -m sphinx.cmd.build docs $(PUBLIC_DIR) + +# Generate mypy reports. +docs-mypy: docs-gen + $(PIPRUN) python -m mypy rdagent test --exclude FinCo --exclude git_ignore_folder --exclude finco --exclude rdagent/scripts --exclude test/scripts --html-report $(PUBLIC_DIR)/reports/mypy + +# Generate html coverage reports with badge. +docs-coverage: test-run docs-gen + $(PIPRUN) python -m coverage html -d $(PUBLIC_DIR)/reports/coverage --fail-under 80 + $(PIPRUN) bash scripts/generate-coverage-badge.sh $(PUBLIC_DIR)/_static/badges + +# Generate all documentation with reports. +docs: changelog docs-gen docs-mypy docs-coverage + + +######################################################################################## +# End +######################################################################################## diff --git a/constraints/3.10.txt b/constraints/3.10.txt new file mode 100644 index 00000000..e11a59f0 --- /dev/null +++ b/constraints/3.10.txt @@ -0,0 +1,153 @@ +aiohttp==3.9.1 +aiosignal==1.3.1 +alabaster==0.7.13 +annotated-types==0.6.0 +anyio==4.2.0 +appdirs==1.4.4 +async-timeout==4.0.3 +attrs==23.2.0 +autodoc-pydantic==2.0.1 +azure-ai-formrecognizer==3.3.2 +azure-common==1.1.28 +azure-core==1.29.6 +Babel==2.14.0 +beautifulsoup4==4.12.2 +black==23.12.1 +build==1.0.3 +certifi==2023.11.17 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +coverage==7.4.0 +cryptography==41.0.7 +Cython==3.0.7 +dataclasses-json==0.6.3 +distro==1.9.0 +docutils==0.20.1 +exceptiongroup==1.2.0 +filelock==3.13.1 +fire==0.5.0 +frozenlist==1.4.1 +fsspec==2023.12.2 +furo==2023.9.10 +fuzzywuzzy==0.18.0 +git-changelog==2.4.0 +greenlet==3.0.3 +h11==0.14.0 +httpcore==1.0.2 +httpx==0.26.0 +idna==3.6 +imagesize==1.4.1 +importlib-metadata==7.0.1 +iniconfig==2.0.0 +isodate==0.6.1 +isort==5.13.2 +jaraco.classes==3.3.0 +jeepney==0.8.0 +Jinja2==3.1.2 +jsonpatch==1.33 +jsonpointer==2.4 +keyring==24.3.0 +langchain==0.0.353 +langchain-community==0.0.7 +langchain-core==0.1.4 +langsmith==0.0.75 +livereload==2.6.3 +loguru==0.7.2 +lxml==5.0.0 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +marshmallow==3.20.1 +mdit-py-plugins==0.4.0 +mdurl==0.1.2 +more-itertools==10.1.0 +mpmath==1.3.0 +msrest==0.7.1 +multidict==6.0.4 +mypy==1.8.0 +mypy-extensions==1.0.0 +myst-parser==2.0.0 +networkx==3.2.1 +nh3==0.2.15 +numpy==1.26.2 +nvidia-cublas-cu12==12.1.3.1 +nvidia-cuda-cupti-cu12==12.1.105 +nvidia-cuda-nvrtc-cu12==12.1.105 +nvidia-cuda-runtime-cu12==12.1.105 +nvidia-cudnn-cu12==8.9.2.26 +nvidia-cufft-cu12==11.0.2.54 +nvidia-curand-cu12==10.3.2.106 +nvidia-cusolver-cu12==11.4.5.107 +nvidia-cusparse-cu12==12.1.0.106 +nvidia-nccl-cu12==2.18.1 +nvidia-nvjitlink-cu12==12.3.101 +nvidia-nvtx-cu12==12.1.105 +oauthlib==3.2.2 +openai==1.6.1 +packaging==23.2 +pandas==2.1.4 +pathspec==0.12.1 +pkginfo==1.9.6 +platformdirs==4.1.0 +pluggy==1.3.0 +pycparser==2.21 +pydantic==2.5.3 +pydantic-settings==2.1.0 +pydantic_core==2.14.6 +Pygments==2.17.2 +pypdf==3.17.4 +pyproject_hooks==1.0.0 +pytest==7.4.4 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +pytz==2023.3.post1 +PyYAML==6.0.1 +readme-renderer==42.0 +requests==2.31.0 +requests-oauthlib==1.3.1 +requests-toolbelt==1.0.0 +rfc3986==2.0.0 +rich==13.7.0 +ruamel.yaml==0.18.5 +ruamel.yaml.clib==0.2.8 +ruff==0.1.9 +scipy==1.11.4 +SecretStorage==3.3.3 +semver==3.0.2 +setuptools-scm==8.0.4 +shellingham==1.5.4 +six==1.16.0 +sniffio==1.3.0 +snowballstemmer==2.2.0 +soupsieve==2.5 +Sphinx==7.2.6 +sphinx-autobuild==2021.3.14 +sphinx-basic-ng==1.0.0b2 +sphinx-click==5.1.0 +sphinx-togglebutton==0.3.2 +sphinxcontrib-applehelp==1.0.7 +sphinxcontrib-devhelp==1.0.5 +sphinxcontrib-htmlhelp==2.0.4 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.6 +sphinxcontrib-serializinghtml==1.1.9 +SQLAlchemy==2.0.24 +sympy==1.12 +tenacity==8.2.3 +termcolor==2.4.0 +toml-sort==0.23.1 +tomli==2.0.1 +tomlkit==0.12.3 +torch==2.1.2 +tornado==6.4 +tqdm==4.66.1 +triton==2.1.0 +twine==4.0.2 +typer==0.9.0 +typing-inspect==0.9.0 +typing_extensions==4.9.0 +tzdata==2023.4 +urllib3==2.1.0 +yarl==1.9.4 +zipp==3.17.0 diff --git a/constraints/3.11.txt b/constraints/3.11.txt new file mode 100644 index 00000000..f8da2921 --- /dev/null +++ b/constraints/3.11.txt @@ -0,0 +1,150 @@ +aiohttp==3.9.1 +aiosignal==1.3.1 +alabaster==0.7.13 +annotated-types==0.6.0 +anyio==4.2.0 +appdirs==1.4.4 +attrs==23.2.0 +autodoc-pydantic==2.0.1 +azure-ai-formrecognizer==3.3.2 +azure-common==1.1.28 +azure-core==1.29.6 +Babel==2.14.0 +beautifulsoup4==4.12.2 +black==23.12.1 +build==1.0.3 +certifi==2023.11.17 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +coverage==7.4.0 +cryptography==41.0.7 +Cython==3.0.7 +dataclasses-json==0.6.3 +distro==1.9.0 +docutils==0.20.1 +filelock==3.13.1 +fire==0.5.0 +frozenlist==1.4.1 +fsspec==2023.12.2 +furo==2023.9.10 +fuzzywuzzy==0.18.0 +git-changelog==2.4.0 +greenlet==3.0.3 +h11==0.14.0 +httpcore==1.0.2 +httpx==0.26.0 +idna==3.6 +imagesize==1.4.1 +importlib-metadata==7.0.1 +iniconfig==2.0.0 +isodate==0.6.1 +isort==5.13.2 +jaraco.classes==3.3.0 +jeepney==0.8.0 +Jinja2==3.1.2 +jsonpatch==1.33 +jsonpointer==2.4 +keyring==24.3.0 +langchain==0.0.353 +langchain-community==0.0.7 +langchain-core==0.1.4 +langsmith==0.0.75 +livereload==2.6.3 +loguru==0.7.2 +lxml==5.0.0 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +marshmallow==3.20.1 +mdit-py-plugins==0.4.0 +mdurl==0.1.2 +more-itertools==10.1.0 +mpmath==1.3.0 +msrest==0.7.1 +multidict==6.0.4 +mypy==1.8.0 +mypy-extensions==1.0.0 +myst-parser==2.0.0 +networkx==3.2.1 +nh3==0.2.15 +numpy==1.26.2 +nvidia-cublas-cu12==12.1.3.1 +nvidia-cuda-cupti-cu12==12.1.105 +nvidia-cuda-nvrtc-cu12==12.1.105 +nvidia-cuda-runtime-cu12==12.1.105 +nvidia-cudnn-cu12==8.9.2.26 +nvidia-cufft-cu12==11.0.2.54 +nvidia-curand-cu12==10.3.2.106 +nvidia-cusolver-cu12==11.4.5.107 +nvidia-cusparse-cu12==12.1.0.106 +nvidia-nccl-cu12==2.18.1 +nvidia-nvjitlink-cu12==12.3.101 +nvidia-nvtx-cu12==12.1.105 +oauthlib==3.2.2 +openai==1.6.1 +packaging==23.2 +pandas==2.1.4 +pathspec==0.12.1 +pkginfo==1.9.6 +platformdirs==4.1.0 +pluggy==1.3.0 +pycparser==2.21 +pydantic==2.5.3 +pydantic-settings==2.1.0 +pydantic_core==2.14.6 +Pygments==2.17.2 +pypdf==3.17.4 +pyproject_hooks==1.0.0 +pytest==7.4.4 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +pytz==2023.3.post1 +PyYAML==6.0.1 +readme-renderer==42.0 +requests==2.31.0 +requests-oauthlib==1.3.1 +requests-toolbelt==1.0.0 +rfc3986==2.0.0 +rich==13.7.0 +ruamel.yaml==0.18.5 +ruamel.yaml.clib==0.2.8 +ruff==0.1.9 +scipy==1.11.4 +SecretStorage==3.3.3 +semver==3.0.2 +setuptools-scm==8.0.4 +shellingham==1.5.4 +six==1.16.0 +sniffio==1.3.0 +snowballstemmer==2.2.0 +soupsieve==2.5 +Sphinx==7.2.6 +sphinx-autobuild==2021.3.14 +sphinx-basic-ng==1.0.0b2 +sphinx-click==5.1.0 +sphinx-togglebutton==0.3.2 +sphinxcontrib-applehelp==1.0.7 +sphinxcontrib-devhelp==1.0.5 +sphinxcontrib-htmlhelp==2.0.4 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.6 +sphinxcontrib-serializinghtml==1.1.9 +SQLAlchemy==2.0.24 +sympy==1.12 +tenacity==8.2.3 +termcolor==2.4.0 +toml-sort==0.23.1 +tomlkit==0.12.3 +torch==2.1.2 +tornado==6.4 +tqdm==4.66.1 +triton==2.1.0 +twine==4.0.2 +typer==0.9.0 +typing-inspect==0.9.0 +typing_extensions==4.9.0 +tzdata==2023.4 +urllib3==2.1.0 +yarl==1.9.4 +zipp==3.17.0 diff --git a/constraints/3.8.txt b/constraints/3.8.txt new file mode 100644 index 00000000..bd6a80d1 --- /dev/null +++ b/constraints/3.8.txt @@ -0,0 +1,154 @@ +aiohttp==3.9.1 +aiosignal==1.3.1 +alabaster==0.7.13 +annotated-types==0.6.0 +anyio==4.2.0 +appdirs==1.4.4 +async-timeout==4.0.3 +attrs==23.2.0 +autodoc-pydantic==2.0.1 +azure-ai-formrecognizer==3.3.2 +azure-common==1.1.28 +azure-core==1.29.6 +Babel==2.14.0 +beautifulsoup4==4.12.2 +black==23.12.1 +build==1.0.3 +certifi==2023.11.17 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +coverage==7.4.0 +cryptography==41.0.7 +Cython==3.0.7 +dataclasses-json==0.6.3 +distro==1.9.0 +docutils==0.20.1 +exceptiongroup==1.2.0 +filelock==3.13.1 +fire==0.5.0 +frozenlist==1.4.1 +fsspec==2023.12.2 +furo==2023.9.10 +fuzzywuzzy==0.18.0 +git-changelog==2.4.0 +greenlet==3.0.3 +h11==0.14.0 +httpcore==1.0.2 +httpx==0.26.0 +idna==3.6 +imagesize==1.4.1 +importlib-metadata==7.0.1 +importlib-resources==6.1.1 +iniconfig==2.0.0 +isodate==0.6.1 +isort==5.13.2 +jaraco.classes==3.3.0 +jeepney==0.8.0 +Jinja2==3.1.2 +jsonpatch==1.33 +jsonpointer==2.4 +keyring==24.3.0 +langchain==0.0.353 +langchain-community==0.0.7 +langchain-core==0.1.4 +langsmith==0.0.75 +livereload==2.6.3 +loguru==0.7.2 +lxml==5.0.0 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +marshmallow==3.20.1 +mdit-py-plugins==0.4.0 +mdurl==0.1.2 +more-itertools==10.1.0 +mpmath==1.3.0 +msrest==0.7.1 +multidict==6.0.4 +mypy==1.8.0 +mypy-extensions==1.0.0 +myst-parser==2.0.0 +networkx==3.1 +nh3==0.2.15 +numpy==1.24.4 +nvidia-cublas-cu12==12.1.3.1 +nvidia-cuda-cupti-cu12==12.1.105 +nvidia-cuda-nvrtc-cu12==12.1.105 +nvidia-cuda-runtime-cu12==12.1.105 +nvidia-cudnn-cu12==8.9.2.26 +nvidia-cufft-cu12==11.0.2.54 +nvidia-curand-cu12==10.3.2.106 +nvidia-cusolver-cu12==11.4.5.107 +nvidia-cusparse-cu12==12.1.0.106 +nvidia-nccl-cu12==2.18.1 +nvidia-nvjitlink-cu12==12.3.101 +nvidia-nvtx-cu12==12.1.105 +oauthlib==3.2.2 +openai==1.6.1 +packaging==23.2 +pandas==2.0.3 +pathspec==0.12.1 +pkginfo==1.9.6 +platformdirs==4.1.0 +pluggy==1.3.0 +pycparser==2.21 +pydantic==2.5.3 +pydantic-settings==2.1.0 +pydantic_core==2.14.6 +Pygments==2.17.2 +pypdf==3.17.4 +pyproject_hooks==1.0.0 +pytest==7.4.4 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +pytz==2023.3.post1 +PyYAML==6.0.1 +readme-renderer==42.0 +requests==2.31.0 +requests-oauthlib==1.3.1 +requests-toolbelt==1.0.0 +rfc3986==2.0.0 +rich==13.7.0 +ruamel.yaml==0.18.5 +ruamel.yaml.clib==0.2.8 +ruff==0.1.9 +scipy==1.10.1 +SecretStorage==3.3.3 +semver==3.0.2 +setuptools-scm==8.0.4 +shellingham==1.5.4 +six==1.16.0 +sniffio==1.3.0 +snowballstemmer==2.2.0 +soupsieve==2.5 +Sphinx==7.1.2 +sphinx-autobuild==2021.3.14 +sphinx-basic-ng==1.0.0b2 +sphinx-click==5.1.0 +sphinx-togglebutton==0.3.2 +sphinxcontrib-applehelp==1.0.4 +sphinxcontrib-devhelp==1.0.2 +sphinxcontrib-htmlhelp==2.0.1 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.3 +sphinxcontrib-serializinghtml==1.1.5 +SQLAlchemy==2.0.24 +sympy==1.12 +tenacity==8.2.3 +termcolor==2.4.0 +toml-sort==0.23.1 +tomli==2.0.1 +tomlkit==0.12.3 +torch==2.1.2 +tornado==6.4 +tqdm==4.66.1 +triton==2.1.0 +twine==4.0.2 +typer==0.9.0 +typing-inspect==0.9.0 +typing_extensions==4.9.0 +tzdata==2023.4 +urllib3==2.1.0 +yarl==1.9.4 +zipp==3.17.0 diff --git a/constraints/3.9.txt b/constraints/3.9.txt new file mode 100644 index 00000000..e11a59f0 --- /dev/null +++ b/constraints/3.9.txt @@ -0,0 +1,153 @@ +aiohttp==3.9.1 +aiosignal==1.3.1 +alabaster==0.7.13 +annotated-types==0.6.0 +anyio==4.2.0 +appdirs==1.4.4 +async-timeout==4.0.3 +attrs==23.2.0 +autodoc-pydantic==2.0.1 +azure-ai-formrecognizer==3.3.2 +azure-common==1.1.28 +azure-core==1.29.6 +Babel==2.14.0 +beautifulsoup4==4.12.2 +black==23.12.1 +build==1.0.3 +certifi==2023.11.17 +cffi==1.16.0 +charset-normalizer==3.3.2 +click==8.1.7 +colorama==0.4.6 +coverage==7.4.0 +cryptography==41.0.7 +Cython==3.0.7 +dataclasses-json==0.6.3 +distro==1.9.0 +docutils==0.20.1 +exceptiongroup==1.2.0 +filelock==3.13.1 +fire==0.5.0 +frozenlist==1.4.1 +fsspec==2023.12.2 +furo==2023.9.10 +fuzzywuzzy==0.18.0 +git-changelog==2.4.0 +greenlet==3.0.3 +h11==0.14.0 +httpcore==1.0.2 +httpx==0.26.0 +idna==3.6 +imagesize==1.4.1 +importlib-metadata==7.0.1 +iniconfig==2.0.0 +isodate==0.6.1 +isort==5.13.2 +jaraco.classes==3.3.0 +jeepney==0.8.0 +Jinja2==3.1.2 +jsonpatch==1.33 +jsonpointer==2.4 +keyring==24.3.0 +langchain==0.0.353 +langchain-community==0.0.7 +langchain-core==0.1.4 +langsmith==0.0.75 +livereload==2.6.3 +loguru==0.7.2 +lxml==5.0.0 +markdown-it-py==3.0.0 +MarkupSafe==2.1.3 +marshmallow==3.20.1 +mdit-py-plugins==0.4.0 +mdurl==0.1.2 +more-itertools==10.1.0 +mpmath==1.3.0 +msrest==0.7.1 +multidict==6.0.4 +mypy==1.8.0 +mypy-extensions==1.0.0 +myst-parser==2.0.0 +networkx==3.2.1 +nh3==0.2.15 +numpy==1.26.2 +nvidia-cublas-cu12==12.1.3.1 +nvidia-cuda-cupti-cu12==12.1.105 +nvidia-cuda-nvrtc-cu12==12.1.105 +nvidia-cuda-runtime-cu12==12.1.105 +nvidia-cudnn-cu12==8.9.2.26 +nvidia-cufft-cu12==11.0.2.54 +nvidia-curand-cu12==10.3.2.106 +nvidia-cusolver-cu12==11.4.5.107 +nvidia-cusparse-cu12==12.1.0.106 +nvidia-nccl-cu12==2.18.1 +nvidia-nvjitlink-cu12==12.3.101 +nvidia-nvtx-cu12==12.1.105 +oauthlib==3.2.2 +openai==1.6.1 +packaging==23.2 +pandas==2.1.4 +pathspec==0.12.1 +pkginfo==1.9.6 +platformdirs==4.1.0 +pluggy==1.3.0 +pycparser==2.21 +pydantic==2.5.3 +pydantic-settings==2.1.0 +pydantic_core==2.14.6 +Pygments==2.17.2 +pypdf==3.17.4 +pyproject_hooks==1.0.0 +pytest==7.4.4 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +pytz==2023.3.post1 +PyYAML==6.0.1 +readme-renderer==42.0 +requests==2.31.0 +requests-oauthlib==1.3.1 +requests-toolbelt==1.0.0 +rfc3986==2.0.0 +rich==13.7.0 +ruamel.yaml==0.18.5 +ruamel.yaml.clib==0.2.8 +ruff==0.1.9 +scipy==1.11.4 +SecretStorage==3.3.3 +semver==3.0.2 +setuptools-scm==8.0.4 +shellingham==1.5.4 +six==1.16.0 +sniffio==1.3.0 +snowballstemmer==2.2.0 +soupsieve==2.5 +Sphinx==7.2.6 +sphinx-autobuild==2021.3.14 +sphinx-basic-ng==1.0.0b2 +sphinx-click==5.1.0 +sphinx-togglebutton==0.3.2 +sphinxcontrib-applehelp==1.0.7 +sphinxcontrib-devhelp==1.0.5 +sphinxcontrib-htmlhelp==2.0.4 +sphinxcontrib-jsmath==1.0.1 +sphinxcontrib-qthelp==1.0.6 +sphinxcontrib-serializinghtml==1.1.9 +SQLAlchemy==2.0.24 +sympy==1.12 +tenacity==8.2.3 +termcolor==2.4.0 +toml-sort==0.23.1 +tomli==2.0.1 +tomlkit==0.12.3 +torch==2.1.2 +tornado==6.4 +tqdm==4.66.1 +triton==2.1.0 +twine==4.0.2 +typer==0.9.0 +typing-inspect==0.9.0 +typing_extensions==4.9.0 +tzdata==2023.4 +urllib3==2.1.0 +yarl==1.9.4 +zipp==3.17.0 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..2122ffdb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,122 @@ +[build-system] +build-backend = "setuptools.build_meta" +requires = [ + "setuptools", + "setuptools-scm", +] + +[project] +authors = [ + {email = "xuyang1@microsoft.com", name = "MSRA-MIIC"}, +] +classifiers = [ + "Development Status :: 3 - Alpha", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", +] +description = "Research & Development Agent" +dynamic = [ + "dependencies", + "optional-dependencies", + "version", +] +keywords = [ + "Autonomous Agents", + "Research and Development", + "Large Language Models", +] +name = "rdagent" +readme = "README.md" +requires-python = ">=3.8" + +[project.scripts] +rdagent-cli = "rdagent.cli:app" + +[project.urls] +homepage = "https://github.com/microsoft/RD-Agent/" +issue = "https://github.com/microsoft/RD-Agent/issues" + +[tool.coverage.report] +fail_under = 80 + +[tool.coverage.run] +source = [ + "rdagent", +] + +[tool.isort] +color_output = true +profile = "black" + +[tool.mypy] +check_untyped_defs = true +disallow_any_unimported = true +disallow_untyped_defs = true +enable_error_code = [ + "ignore-without-code", +] +no_implicit_optional = true +show_error_codes = true +warn_return_any = true +warn_unused_ignores = true + +[tool.pytest.ini_options] +addopts = "-l -s --durations=0" +log_cli = true +log_cli_level = "info" +log_date_format = "%Y-%m-%d %H:%M:%S" +log_format = "%(asctime)s %(levelname)s %(message)s" +minversion = "6.0" + +[tool.ruff] +fix = true +ignore = [ + # https://docs.astral.sh/ruff/rules/#pydocstyle-d + "D203", + "D204", + "D213", + "D215", + "D400", + "D404", + "D406", + "D407", + "D408", + "D409", + "D413", + "ANN101", + "ANN401", + "TCH003", + "D", + "ERA001", + "PLR0913", + "S101", +] +select = ["ALL"] +src = ["rdagent"] + +[tool.ruff.per-file-ignores] +"docs/conf.py" = ["INP001"] +"test/*" = ["S101"] + +[tool.setuptools] +py-modules = ["rdagent"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} + +[tool.setuptools.dynamic.optional-dependencies] +docs = {file = ["requirements/docs.txt"]} +lint = {file = ["requirements/lint.txt"]} +package = {file = ["requirements/package.txt"]} +test = {file = ["requirements/test.txt"]} + +[tool.setuptools_scm] + +[tool.tomlsort] +all = true +in_place = true +trailing_comma_inline_array = true diff --git a/rdagent/app/CI/ci.ipynb b/rdagent/app/CI/ci.ipynb new file mode 100644 index 00000000..e69de29b diff --git a/rdagent/app/factor_extraction_and_implementation/factor_extract_and_implement.ipynb b/rdagent/app/factor_extraction_and_implementation/factor_extract_and_implement.ipynb new file mode 100644 index 00000000..e69de29b diff --git a/rdagent/core/conf.py b/rdagent/core/conf.py new file mode 100644 index 00000000..e69de29b diff --git a/rdagent/core/evolving_framework.py b/rdagent/core/evolving_framework.py new file mode 100644 index 00000000..e69de29b diff --git a/rdagent/data_driven_code_generation/__init__.py b/rdagent/data_driven_code_generation/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/rdagent/document_analysis/__init__.py b/rdagent/document_analysis/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/rdagent/oai/llm_utils.py b/rdagent/oai/llm_utils.py new file mode 100644 index 00000000..e69de29b diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..9b68b3cc --- /dev/null +++ b/requirements.txt @@ -0,0 +1,26 @@ +# Requirements for runtime. +pydantic-settings +typer[all] + +loguru +black +isort +mypy +ruff + +numpy +pandas +cython +langchain +scipy +tiktoken +python-Levenshtein +scikit-learn + +# PDF related +pypdf +azure-core +azure-ai-formrecognizer + +# factor implementations +tables diff --git a/requirements/docs.txt b/requirements/docs.txt new file mode 100644 index 00000000..84e45adb --- /dev/null +++ b/requirements/docs.txt @@ -0,0 +1,12 @@ +# Requirements for docs. +autodoc-pydantic +coverage +furo +git-changelog +mypy[reports] +myst-parser +pytest +Sphinx +sphinx-autobuild +sphinx-click +sphinx-togglebutton diff --git a/requirements/lint.txt b/requirements/lint.txt new file mode 100644 index 00000000..8b8f70fe --- /dev/null +++ b/requirements/lint.txt @@ -0,0 +1,6 @@ +# Requirements for lint. +black +isort +mypy +ruff +toml-sort diff --git a/requirements/package.txt b/requirements/package.txt new file mode 100644 index 00000000..8840f3c5 --- /dev/null +++ b/requirements/package.txt @@ -0,0 +1,18 @@ +# Requirements for package. +build +setuptools-scm +twine +fire +fuzzywuzzy +openai +ruamel-yaml +torch +tabulate # Convert pandas dataframe to markdown table to make it more readable to LLM +tables # we use hd5 as default data format. So we have to install pytables +feedparser +matplotlib +pandas + +# TODO: dependencies for implementing factors. +# I think it is for running insteading of implementing. The dependency should be in +statsmodels diff --git a/requirements/test.txt b/requirements/test.txt new file mode 100644 index 00000000..4b4fbc0b --- /dev/null +++ b/requirements/test.txt @@ -0,0 +1,3 @@ +# Requirements for test. +coverage +pytest diff --git a/test/oai/test_completion.py b/test/oai/test_completion.py new file mode 100644 index 00000000..e69de29b diff --git a/test/oai/test_embedding.py b/test/oai/test_embedding.py new file mode 100644 index 00000000..e69de29b diff --git a/test/oai/test_embedding_similarity.py b/test/oai/test_embedding_similarity.py new file mode 100644 index 00000000..e69de29b