Skip to content

Install 3rd party libraries in CI for lint#3580

Merged
contramundum53 merged 32 commits intooptuna:masterfrom
not522:lint-3rd-party
Jul 14, 2022
Merged

Install 3rd party libraries in CI for lint#3580
contramundum53 merged 32 commits intooptuna:masterfrom
not522:lint-3rd-party

Conversation

@not522
Copy link
Copy Markdown
Member

@not522 not522 commented May 23, 2022

Motivation

In the checks workflow, we have not installed 3rd party libraries for visualization, integration, benchmarks, etc. It skips some checks, especially in mypy.

Description of the changes

  • Install 3rd party libraries in CI for lint.

@not522
Copy link
Copy Markdown
Member Author

not522 commented May 25, 2022

pytest.warns(None) is deprecated. https://docs.pytest.org/en/7.0.x/deprecations.html#using-pytest-warns-none

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 25, 2022

Codecov Report

Merging #3580 (24cfda9) into master (e8b6922) will increase coverage by 0.00%.
The diff coverage is 19.04%.

@@           Coverage Diff           @@
##           master    #3580   +/-   ##
=======================================
  Coverage   90.56%   90.57%           
=======================================
  Files         164      164           
  Lines       12646    12652    +6     
=======================================
+ Hits        11453    11459    +6     
  Misses       1193     1193           
Impacted Files Coverage Δ
optuna/integration/pytorch_distributed.py 36.87% <0.00%> (ø)
optuna/integration/pytorch_lightning.py 0.00% <0.00%> (ø)
optuna/integration/xgboost.py 59.67% <0.00%> (ø)
optuna/integration/chainer.py 89.74% <80.00%> (-0.26%) ⬇️
optuna/samplers/_tpe/parzen_estimator.py 98.29% <0.00%> (+0.04%) ⬆️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

def on_init_start(self, trainer: Trainer) -> None:
self.is_ddp_backend = trainer._accelerator_connector.distributed_backend is not None
self.is_ddp_backend = (
trainer._accelerator_connector.distributed_backend is not None # type: ignore
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

distributed_backend has been removed. Lightning-AI/pytorch-lightning#10017
See also #3418.

@not522
Copy link
Copy Markdown
Member Author

not522 commented May 26, 2022

Checks CI passed. Now, this PR is ready for review.

@not522 not522 marked this pull request as ready for review May 26, 2022 01:10
@contramundum53
Copy link
Copy Markdown
Member

@toshihikoyanase Could you review this PR?

Copy link
Copy Markdown
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your PR. The type checking in Python is getting more and more popular, and it may be a good time to introduce more strict checking. On the other hand, I'm not confident with the change in terms of developers' experience.

The change will increase the duration of the checks jobs from 1 min to 15 min. I see some developers use the jobs instead of a local linter and their turn-around time will also increase. Also, the required CI jobs might be more fragile to the update of third-party libraries.

image

Not a strong opinion, but how about adding this strict checks job to daily CI?
Currently, the daily CI is mainly checked by the committers and it hardly affects external developers.

@toshihikoyanase toshihikoyanase added the CI Continuous integration. label May 31, 2022
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jun 7, 2022

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Jun 7, 2022
@toshihikoyanase
Copy link
Copy Markdown
Member

I talked with @not522 , and they will move this strict lint to daily CI. Keep this PR as it is, please.

@github-actions github-actions bot removed the stale Exempt from stale bot labeling. label Jun 8, 2022
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has not seen any recent activity.

@github-actions github-actions bot added the stale Exempt from stale bot labeling. label Jun 15, 2022
@contramundum53 contramundum53 removed the stale Exempt from stale bot labeling. label Jun 20, 2022
@toshihikoyanase
Copy link
Copy Markdown
Member

If we install recent xgboost, xgb.core.CallbackEnv is not defined, and the following errors are raised. So we need type: ignore there.

optuna/integration/xgboost.py:79: error: Name "xgb.core.CallbackEnv" is not defined
optuna/integration/xgboost.py:100: error: Name "xgb.core.CallbackEnv" is not defined

https://github.com/optuna/optuna/runs/6552734319?check_suite_focus=true

On the other hand, the errors will not be raised when we do not install xgboost since we ignore missing import.

optuna/integration/xgboost.py:7[9](https://github.com/optuna/optuna/runs/6912328489?check_suite_focus=true#step:8:10): error: Unused "type: ignore" comment
optuna/integration/xgboost.py:100: error: Unused "type: ignore" comment

https://github.com/optuna/optuna/runs/6912328489?check_suite_focus=true

IMO, we can omit the type check of older xgboost, for example, by using @typing.no_type_check. (But I'm not sure if it is expected usage of the annotation). And, I'm also wondering why we keep the callback since the other integration modules only support the latest version of the target libraries.

@not522
Copy link
Copy Markdown
Member Author

not522 commented Jul 1, 2022

I found following errors.

  1. xarray.Dataset.from_dict is an untyped function. (It will be fixed in the next xarray release.)
  2. chainer's and pytorch.distributed's functions are untyped.
  3. The latest PyTorchLightning is not supported.
  4. The latest XGBoost is not supported.
  5. Incompatible subclassing in test_pytorch_lightning.py.
  6. pytest.warns(None) is deprecated.

For 1, we need to wait.
2 is hard to resolve. I added type: ignore comments.
3 and 4 should be fixed in other PRs.
5 is hard to resolve. I recommend that we just ignore it.
6 should be fixed in this PR.

@not522 not522 marked this pull request as ready for review July 8, 2022 07:55
Comment on lines +33 to +39
python -m pip install -U pip
pip install --progress-bar off -U .[checking]
pip install --progress-bar off -U .[optional]
pip install --progress-bar off -U .[integration] --extra-index-url https://download.pytorch.org/whl/cpu
pip install --progress-bar off -U .[benchmark]
pip install --progress-bar off -U bayesmark
pip install --progress-bar off -U kurobako
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Skip installing naslib because it requires specific library versions.

@not522
Copy link
Copy Markdown
Member Author

not522 commented Jul 8, 2022

All checks are passed. PTAL.

@not522 not522 requested a review from contramundum53 July 8, 2022 08:00
check_untyped_defs = True
no_implicit_optional = True
warn_redundant_casts = True
warn_unused_ignores = True
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Notes] .github/workflows/checks-integration.yml checks with this option (warn_unused_ignores) and unnecessary # type: ignore will be detected there.

Copy link
Copy Markdown
Member

@toshihikoyanase toshihikoyanase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your update. The change looks great to me.
Some changes are not intuitive to me, and I left some notes just for reminder.

Comment on lines +59 to +61
accuracy = sum(
x["validation_accuracy"] for x in cast(List[Dict[str, torch.Tensor]], outputs)
) / len(outputs)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Notes] outputs can be List[torch.Tensor], but original code apparently expects List[Dict[str, torch.Tensor]] , so this fix is acceptable to me.

Comment on lines +19 to +20
steps:
- uses: actions/checkout@v2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scheduled run might not be intended to run in forks. But, we can work on it in a follow-up PR.

# Not intended for forks.
if: github.repository == 'optuna/optuna'

@toshihikoyanase
Copy link
Copy Markdown
Member

@not522 requested another review from @contramundum53 . Please merge after your review.

Copy link
Copy Markdown
Member

@contramundum53 contramundum53 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@contramundum53 contramundum53 added this to the v3.0.0-rc0 milestone Jul 14, 2022
@contramundum53 contramundum53 merged commit 1f9dd70 into optuna:master Jul 14, 2022
@not522 not522 deleted the lint-3rd-party branch August 19, 2022 10:53
@not522 not522 mentioned this pull request Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous integration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants