Skip to content
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

refactor: use model classes and also refactor original config impleme… #48

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

Conversation

kapil-agnihotri
Copy link
Collaborator

…ntation to use model classes

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello @kapil-agnihotri, thank you for submitting a pull request. We will address it.

@kapil-agnihotri kapil-agnihotri force-pushed the refactor-use-model-classes-and-also-refactor-original-config-implementation-to-use-model-classes branch 2 times, most recently from a79aa2f to 1acb08a Compare September 9, 2024 15:41
@kapil-agnihotri kapil-agnihotri force-pushed the refactor-use-model-classes-and-also-refactor-original-config-implementation-to-use-model-classes branch from 1acb08a to 5790d7d Compare September 9, 2024 16:03
@kapil-agnihotri kapil-agnihotri marked this pull request as ready for review September 9, 2024 16:03
@kapil-agnihotri kapil-agnihotri force-pushed the refactor-use-model-classes-and-also-refactor-original-config-implementation-to-use-model-classes branch from c75409e to 02a26a5 Compare September 10, 2024 14:22
@kapil-agnihotri
Copy link
Collaborator Author

For now I have duplicated all model classes in here. I think later ranking-service can be modified to refer to the model classes from ProMCDA submodule. This will also reduce code duplication.
The only drawback would be to modify imports when there would be some change to model classes.

@Flaminietta
Copy link
Collaborator

Flaminietta commented Sep 18, 2024

@kapil-agnihotri
I suggest creating a branch named develop (or similar) and using it to merge the PRs that will lead to a refactored version of the package.

The main reasons are:

  • the attached paper in publication in JOSS that refers to the current version of the tool in main;
  • the software in main is thoroughly tested with some test cases (end-to-end controlled tests);
  • the current users of the package can keep referring to the working and tested version in main, and to its readme, while we accomplish a complete refactoring

@kapil-agnihotri
Copy link
Collaborator Author

@Flaminietta thank you for your feedback. I can create a new branch and push the changes to it once the review is complete. I believe that the review is still in progress?

@Flaminietta
Copy link
Collaborator

@kapil-agnihotri @mspada
I went through the entire PR. I am quite overwhelmed by the many changes. I would propose that the two or three (with @mspada) of us discuss together once briefly the new structure proposed. I believe that you @kapil-agnihotri can
explain to me/us the new needs and give an explanatory overview of all the changes.

Did you already perform also end-to-end controlled tests?

I still need to run it once. Do I run it from the terminal as before?

Copy link
Member

@thorsten-reitz thorsten-reitz left a comment

Choose a reason for hiding this comment

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

Though I didn't get around to running it, the principal structure is as I would have expected.

@Flaminietta
Copy link
Collaborator

The README needs to be updated too for the new refactoring.

For example, now the run is not initiated by typing:
python3 -m mcda.mcda_run -c configuration.json but by typing
python3 -m mcda.mcda_run -c python3 -m mcda.mcda_run -c car-data-from-ranking-service-robustness-on-weights-no-sensitivity.json, right?

However, for now I cannot run it, I should dig deeper to find the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand that this file represents a combination of the previous configuration.json. file and the input_matrix.cvs. I would name it referring to the idea of a configuration anyway, like "configuration_car_data_rank_robustness_on_weight_no_sensitivity.json"

In "robustness", what happens if the user selects "robustness": "indicators"? The entry "onWeightsLevel" will be then substituted with "on_indicators"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Additionally, in this example writing the input matrix is easy (even manually). What would the strategy be when the input matrix is a table with many more rows and columns?

@@ -7,21 +7,21 @@
Usage (from root directory):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess that we won't run it from CLI anymore.


def config_dict_to_configuration_model(input_config):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would move the function somewhere outside of this script. It's a utility, let's keep this running script clear.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a docstring to the function by following the format used for the other functions.
Something like:

"""
    Describe functionality.

    Parameters:
    - A (type): description.
    - B (type): description.

    Raises:
    - ValueError: when it happens.

    :param A: type
    :param B: type
    :return R: type
    """

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add the type hinting (that indicates the expected type of the value that the function will return).


def config_dict_to_configuration_model(input_config):
# Extracting relevant configuration values
config = Config(input_config)
input_matrix = read_matrix(config.input_matrix_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Retrieving the input_matrix_path is possible from the old version of the configuration file (configuration.json). But it's not valid anymore with the new kind of configuration that you created in input_files/toy_example. What is your plan?



# noinspection PyTypeChecker
def main_using_model(input_config: dict) -> dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor: I am unsure if main_using_model is the best function name. What do you think of main_using_config? Is the config that makes a difference, the model is always the same (i.e., MCDA).

T = typing.TypeVar('T')


class Model(object):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a docstring and in summary explain something like:
The class Model is designed to represent a data model with serialization and deserialization capabilities. It provides a framework for representing data models that can be easily serialized to and from dictionaries. It supports operations for equality checks, and for creating more complex models in Python applications with data exchange.

from ProMCDA.mcda import util


class Configuration(Model):
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the original class Config stays too, we need perhaps to review naming. It's quite confusing for me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Additionally, adding short descriptions (docstrings) of the main functionalities helps navigate the various scripts.
For example:
The Configuration class encapsulates a configuration for MCDA, allowing for structured data representation and easy manipulation of attributes.


@property
def sensitivity(self) -> ConfigurationSensitivity:
"""Gets the sensitivity of this Configuration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please adjust the docstrings to be less misleading.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that these are all automatically generated scripts, and probably all necessary then. However, for me, the overall package structure became quite confusing. The name of this script is also confusing: why "modified"?

I am not sure we can make something different.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do I understand well that, if one day we want to modify something in the original configuration settings (e.g., by adding a new functionality), then all of these automatically created scripts won't be manually changed but Swagger will recreate them?

@@ -100,7 +104,7 @@ def get_list_random_input_matrices() -> list[pd.DataFrame]:
config = TestMCDA_with_robustness.get_test_config()
config = Config(config)
mcda_with_robustness = MCDAWithRobustness(config, input_matrix, is_exact_pdf_mask, is_poisson_pdf_mask)
output_list = mcda_with_robustness.convert_list(out_list)
output_list = MCDAWithRobustness.convert_list(out_list)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Weird, you instantiated MCDAWithRobustness in an object, why do you then use MCDAWithRobustness.convert_list(out_list)? I believe that it works if you made it...

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

Successfully merging this pull request may close these issues.

3 participants