Skip to content

[ENH] Move BaseFixtureGenerator to pytorch-forecasting/tests/_base #1919

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

PranavBhatP
Copy link
Contributor

What does this implement/fix? Explain your changes.

Currently we use the BaseFixtureGenerator for generating fixtures for tests involving estimators and recently metrics (#1907). But the current import location is inside test_all_estimators.py. This PR aims to make this class a true "base" class by moving it to a new location. This will be stacked upon by #1907 and #1908 to respectively implement child classes which inherit from this base class.

Current state of PR does not implement a full base class, it is just a copy-paste for now, next steps to ensure that the base class can be extended as a fixture generator for both models and metrics.

PR checklist

  • The PR title starts with either [ENH], [MNT], [DOC], or [BUG]. [BUG] - bugfix, [MNT] - CI, test framework, [ENH] - adding or improving code, [DOC] - writing or improving documentation or docstrings.
  • Added/modified tests
  • Used pre-commit hooks when committing to ensure that code is compliant with hooks. Install hooks with pre-commit install.
    To run hooks independent of commit, execute pre-commit run --all-files

@PranavBhatP PranavBhatP changed the title [ENH] Move BaseFixtureGenerator to a pytorch-forecasting/tests/_base [ENH] Move BaseFixtureGenerator to pytorch-forecasting/tests/_base Jul 14, 2025
@PranavBhatP
Copy link
Contributor Author

FYI @phoeenniixx @fkiraly

# call _generate_estimator_class to get all the classes
all_model_pkgs, _ = self._generate_object_pkg(test_name=test_name)

all_cls = [est.get_model_cls() for est in all_model_pkgs]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here either we could change the name from get_model_cls to get_cls (this would work for both metrics and models) or
We could implement the _generate_obj_class, _generate_object_pkg and _generate_trainer_kwargs independently in respective child classes for metrics and models.

I am a little biased towards the second option as the logic to generate instances, params etc are little different for metrics and models, imo.
This is because in models, base-params are paired with different losses, and idts this is the case with metrics, they are quite independent from the models (@PranavBhatP please correct me if I am wrong!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, ur reasoning makes sense, object_class and object_pkg are mostly having similar logic for both metrics and models but again, your changes might require having child class-specific implementations for the _generate_<fixture-name> methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, to generate base_params (from model_pkg) paired with each compatible loss and also to add test skips for specific fixture, fixture generation functions will have a little different logic as compared to metrics.

@PranavBhatP
Copy link
Contributor Author

PranavBhatP commented Jul 14, 2025

@phoeenniixx do I completely remove the BaseFixtureGenerator in test_all_estimators.py(as it is currently) , or should I leave it and only focus on the BaseFixtureGenerator inside tests/_base? Since your changes are specific to test_all_estimators.py, which workflow would make it easy for your changes to stack on this PR?

I am okay with any workflow since TestAllPtMetric works just fine, only depends on the import location of BaseFixtureGenerator in the current state.

@phoeenniixx
Copy link
Contributor

@phoeenniixx do I completely remove the BaseFixtureGenerator in test_all_estimators.py(as it is currently) , or should I leave it and only focus on the BaseFixtureGenerator inside tests/_base? Since your changes are specific to test_all_estimators.py, which workflow would make it easy for your changes to stack on this PR?

I am okay with any workflow since TestAllPtMetric works just fine, only depends on the import location of BaseFixtureGenerator in the current state.

Well, imo, the best way is to move BaseFixtureGenerator to tests/_base and then we could inherit from there (creating a new child class like BaseFixtureGenerator_models (or some other better name)).

@phoeenniixx
Copy link
Contributor

I think the way you are doing right now (completely removing the BaseFixtureGenerator from test_all_estimators) is the best way. As the BaseFixtureGenerator for the metrics should either lie in test_all_metrics or _base and not in test_all_estimators.

Any change that should happen, imo, in the current state should be the removal of fixture generation functions and leaving them to the child fixture generators for implementation.

Copy link

codecov bot commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@18f5f95). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1919   +/-   ##
=======================================
  Coverage        ?   86.44%           
=======================================
  Files           ?       96           
  Lines           ?     7828           
  Branches        ?        0           
=======================================
  Hits            ?     6767           
  Misses          ?     1061           
  Partials        ?        0           
Flag Coverage Δ
cpu 86.44% <ø> (?)
pytest 86.44% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Pranav Bhat added 2 commits July 16, 2025 00:25
the previous commit would have left to lots of merge conflicts with existing workflows and hence it is decided to only move the fixture generator as a true base class to _base
@PranavBhatP PranavBhatP marked this pull request as ready for review July 15, 2025 19:03
@PranavBhatP
Copy link
Contributor Author

@phoeenniixx @fkiraly I think this PR is ready for review and merge. To ensure minimal conflicts with the existing copy of BaseFixtureGenerator in test_all_estimators.py, for now I have just implemented the true base class version of BaseFixtureGenerator. This PR can be stacked on the changes made to the test_all_estimators.py and test_all_metrics.py in the PR #1907 and #1908 and the scoped of these PRs can be broadened to implement the child fixture generator classes.

@PranavBhatP PranavBhatP moved this from PR in progress to PR under review in May - Sep 2025 mentee projects Jul 16, 2025
Copy link
Contributor

@phoeenniixx phoeenniixx left a comment

Choose a reason for hiding this comment

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

Thanks! I think this should work.... We can make changes in future if we could generalize some more methods (like tests skips) for both metrics and models...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR under review
Development

Successfully merging this pull request may close these issues.

2 participants