Skip to content

Components refers to models of a specific lib#75

Merged
tbittar merged 13 commits intomainfrom
feature/allow-multiple-lib-import
Apr 3, 2025
Merged

Components refers to models of a specific lib#75
tbittar merged 13 commits intomainfrom
feature/allow-multiple-lib-import

Conversation

@tbittar
Copy link
Collaborator

@tbittar tbittar commented Apr 2, 2025

Update the libraries and system yaml files to be fully compatible with the one defined in C++:

  • In system file, model are refered as lib_id.model
  • In library file, the key model-librairies is allowed, although it is not used now (nor is it in the C++ version for now)

The Python format is still ahead of the C++ format (as of 2 April 2025) as it allows to handle dependencies between librairies to import port type declarations

@tbittar tbittar requested a review from sylvlecl April 2, 2025 16:49
Copy link

@pet-mit pet-mit left a comment

Choose a reason for hiding this comment

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

ok for yml updates

Copy link
Member

@sylvlecl sylvlecl 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 overall:
one typo + minor improvement suggestions which are not "must have"

def resolve_library(
input_libs: List[InputLibrary], preloaded_libs: Optional[List[Library]] = None
) -> Library:
) -> Dict[str, Library]:
Copy link
Member

Choose a reason for hiding this comment

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

would be even better to create a new container class for the libraries, like:

class LibrariesRepository:
    ...
    def find_model(lib_id: str, model_name: str):
        ...

    def find_fully_qualified_model(fq_model_name: str): 
        ... # also checks validity of the FQ name and split it

which would internally have the dictionary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agree, will do it in another PR


return output_lib
if first_dependency in import_stack:
raise Exception("Circular import in yaml libraries")
Copy link
Member

Choose a reason for hiding this comment

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

In practice circular imports are not a blocking issue because models only depend on ports, and ports don't depend on other ports.
So it would work to first create ports of all libraries in a first step, and then resolve all models of all libraries in a second step.

But ok to leave it this way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, however I find it cleaner to avoid circular import (maybe in the future we could define model extensions, or having other feature for which circular imports are blocking). And also I do not want to spend too much time now changing the logic of imports, will do it only if it is needed to replicate the C++ behavior.

def _resolve_component(
libraries: dict[str, Library], component: InputComponent
) -> Component:
lib_id, model_id = component.model.split(".")
Copy link
Member

Choose a reason for hiding this comment

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

Should we accept multiple levels of lib, and only split on the last dot ?
like rte.drd.model-of-the-future ?
If not we should check that there is indeed only one dot.
Optionally this could be delegated to a container of libraries, see proposition above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Like the previous comment, I let the reflexions on this question for the industrial part, the Python code will just follow C++ choices

@tbittar tbittar merged commit 7771b64 into main Apr 3, 2025
2 checks passed
@tbittar tbittar deleted the feature/allow-multiple-lib-import branch April 3, 2025 11:20
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