The new proposed feature is to have trainers as generators. The usage pattern is: ```python trainer = OnPolicyTrainer(...) for epoch, epoch_stat, info in trainer: print(f"Epoch: {epoch}") print(epoch_stat) print(info) do_something_with_policy() query_something_about_policy() make_a_plot_with(epoch_stat) display(info) ``` - epoch int: the epoch number - epoch_stat dict: a large collection of metrics of the current epoch, including stat - info dict: the usual dict out of the non-generator version of the trainer You can even iterate on several different trainers at the same time: ```python trainer1 = OnPolicyTrainer(...) trainer2 = OnPolicyTrainer(...) for result1, result2, ... in zip(trainer1, trainer2, ...): compare_results(result1, result2, ...) ``` Co-authored-by: Jiayi Weng <trinkle23897@gmail.com>
61 lines
1.7 KiB
Makefile
61 lines
1.7 KiB
Makefile
SHELL=/bin/bash
|
|
PROJECT_NAME=tianshou
|
|
PROJECT_PATH=${PROJECT_NAME}/
|
|
LINT_PATHS=${PROJECT_PATH} test/ docs/conf.py examples/ setup.py
|
|
|
|
check_install = python3 -c "import $(1)" || pip3 install $(1) --upgrade
|
|
check_install_extra = python3 -c "import $(1)" || pip3 install $(2) --upgrade
|
|
|
|
pytest:
|
|
$(call check_install, pytest)
|
|
$(call check_install, pytest_cov)
|
|
$(call check_install, pytest_xdist)
|
|
pytest test --cov ${PROJECT_PATH} --durations 0 -v --cov-report term-missing
|
|
|
|
mypy:
|
|
$(call check_install, mypy)
|
|
mypy ${PROJECT_NAME}
|
|
|
|
lint:
|
|
$(call check_install, flake8)
|
|
$(call check_install_extra, bugbear, flake8_bugbear)
|
|
flake8 ${LINT_PATHS} --count --show-source --statistics
|
|
|
|
format:
|
|
$(call check_install, isort)
|
|
isort ${LINT_PATHS}
|
|
$(call check_install, yapf)
|
|
yapf -ir ${LINT_PATHS}
|
|
|
|
check-codestyle:
|
|
$(call check_install, isort)
|
|
$(call check_install, yapf)
|
|
isort --check ${LINT_PATHS} && yapf -r -d ${LINT_PATHS}
|
|
|
|
check-docstyle:
|
|
$(call check_install, pydocstyle)
|
|
$(call check_install, doc8)
|
|
$(call check_install, sphinx)
|
|
$(call check_install, sphinx_rtd_theme)
|
|
pydocstyle ${PROJECT_PATH} && doc8 docs && cd docs && make html SPHINXOPTS="-W"
|
|
|
|
doc:
|
|
$(call check_install, sphinx)
|
|
$(call check_install, sphinx_rtd_theme)
|
|
cd docs && make html && cd _build/html && python3 -m http.server
|
|
|
|
spelling:
|
|
$(call check_install, sphinx)
|
|
$(call check_install, sphinx_rtd_theme)
|
|
$(call check_install_extra, sphinxcontrib.spelling, sphinxcontrib.spelling pyenchant)
|
|
cd docs && make spelling SPHINXOPTS="-W"
|
|
|
|
doc-clean:
|
|
cd docs && make clean
|
|
|
|
clean: doc-clean
|
|
|
|
commit-checks: lint check-codestyle mypy check-docstyle spelling
|
|
|
|
.PHONY: clean spelling doc mypy lint format check-codestyle check-docstyle commit-checks
|