Skip to content

add_set_params_and_corresponding_tests #1102

Merged
merged 18 commits into from
Feb 22, 2023

Conversation

GooseIt
Copy link
Contributor

@GooseIt GooseIt commented Feb 7, 2023

Before submitting (must do checklist)

  • Did you read the contribution guide?
  • Did you update the docs? We use Numpy format for all the methods and classes.
  • Did you write any new necessary tests?
  • Did you update the CHANGELOG?

Proposed Changes

See issue #1025

Closing issues

closes #1025

@codecov-commenter
Copy link

codecov-commenter commented Feb 8, 2023

Codecov Report

Merging #1102 (855dfdc) into master (7b58e3c) will increase coverage by 0.13%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #1102      +/-   ##
==========================================
+ Coverage   86.99%   87.13%   +0.13%     
==========================================
  Files         170      170              
  Lines        9326     9340      +14     
==========================================
+ Hits         8113     8138      +25     
+ Misses       1213     1202      -11     
Impacted Files Coverage Δ
etna/core/mixins.py 98.63% <100.00%> (+0.14%) ⬆️
etna/auto/runner/utils.py 50.00% <0.00%> (-50.00%) ⬇️
etna/libs/tsfresh/relevance.py 78.09% <0.00%> (+1.90%) ⬆️
etna/libs/tsfresh/significance_tests.py 47.82% <0.00%> (+15.94%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@GooseIt
Copy link
Contributor Author

GooseIt commented Feb 8, 2023

I request a review

@martins0n martins0n requested a review from Mr-Geekman February 9, 2023 07:07
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

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

As I can see from the #1025, it is expected that we create a new object, not change the current.

@GooseIt
Copy link
Contributor Author

GooseIt commented Feb 13, 2023

In case you worry that I left the project silently, I'm still working on the issue and will submit code tomorrow.

@GooseIt GooseIt requested a review from Mr-Geekman February 14, 2023 14:44
@GooseIt
Copy link
Contributor Author

GooseIt commented Feb 14, 2023

Changed implementation to creating new object instead of modifying self
Added tests to check that self is not modified
Fixed small issues

etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

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

I described the problem with deepcopy and inplace modification.

Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

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

Look at comments above.

@GooseIt GooseIt requested a review from Mr-Geekman February 21, 2023 22:18
etna/core/mixins.py Outdated Show resolved Hide resolved
"""
params_dict = self.to_dict()

# we need to change specification into list of nested params, "model.depth" to nested structure
Copy link
Contributor

Choose a reason for hiding this comment

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

This description is not very easy to understand.
Let's write something like:

We need to change specification into list of nested params, e.g. {"model.depth": value} to {"model": {"depth": value}}.

I think that we should extract this logic into private method for better readability. For example, _convert_dict_flat_to_nested.

Copy link
Contributor

@Mr-Geekman Mr-Geekman Feb 22, 2023

Choose a reason for hiding this comment

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

May be we should also write a couple of tests for this conversion.

Copy link
Contributor Author

@GooseIt GooseIt Feb 22, 2023

Choose a reason for hiding this comment

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

I agree, I'll change the specification and write tests. It is generally a good idea to isolate code performing interpretable side tasks into distinct functions.

Copy link
Contributor Author

@GooseIt GooseIt Feb 22, 2023

Choose a reason for hiding this comment

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

I'm going to create _update_nested_dict_with_flat_dict(self, params_dict: dict, flat_dict: dict) -> dict method.

I think the problem with _convert_dict_flat_to_nested is that once we have two nested dicts, standart python dict merge overrides values with same keys. As example
dict_1 = {"model" : {"learning_rate": 3e-4}}
dict_2 = {"model" : {"depth" : 8}}
dict_1.update(dict_2)
will result in
dict_1 = {"model" : {"depth" : 8}}
instead of desired {"learning_rate": 3e-4, "model" : {"depth" : 8}}.

So I believe the private method should perform two operations simultaneously: convert from "model.param" : val to "model" : {"param" : val} and immediately update params_dict.

Are you okay with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably, it can be solved by:

  1. obj -> nested dict
  2. nested dict -> flat dict
  3. update flat dict
  4. flat dict -> nested dict
  5. creating object from nested dict

But we don't need this complexity right now. Probably we will made something like this in the future.

Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

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

Look at comments above. It is already working good.

etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@GooseIt GooseIt requested a review from Mr-Geekman February 22, 2023 13:59
@GooseIt GooseIt requested a review from Mr-Geekman February 22, 2023 14:33
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
etna/core/mixins.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Mr-Geekman Mr-Geekman left a comment

Choose a reason for hiding this comment

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

Looks good.

@Mr-Geekman Mr-Geekman merged commit cdf1ee3 into tinkoff-ai:master Feb 22, 2023
@GooseIt GooseIt deleted the base_mixin_set_params branch February 22, 2023 17:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

set_params method
4 participants