Skip to content

feat(library <-> taxonomy check)#214

Open
dusanparipovic wants to merge 11 commits into
developfrom
models-taxonomy-check
Open

feat(library <-> taxonomy check)#214
dusanparipovic wants to merge 11 commits into
developfrom
models-taxonomy-check

Conversation

@dusanparipovic
Copy link
Copy Markdown
Contributor

No description provided.

… implement corresponding unit test for YAML parsing
…my category

- Introduced optional `properties` for components in `system.yml`, allowing key/value pairs that are normalized into a dictionary.
- Added optional `taxonomy-category` field for models in library YAML files, accessible via `ModelSchema.taxonomy_category`.
- Updated documentation to reflect these changes and provided examples in the user guide.
- Updated documentation to replace "key" with "id" in the context of component properties in `system.yml`.
- Adjusted test assertions to reflect the change from "key" to "id" for consistency with the updated documentation.
- Ensured that error messages for duplicate properties also refer to "id" instead of "key".
- Added a new `Study` dataclass that combines `System` and `DataBase`, centralizing consistency checks.
- Updated `build_problem()` and `build_decomposed_problems()` to accept `Study` directly.
- Refactored related functions and tests to utilize the new `Study` structure, ensuring seamless integration.
- Removed redundant parameters and streamlined the API for better clarity and usability.
@dusanparipovic
Copy link
Copy Markdown
Contributor Author

Open questions:

  • This PR opens again question about shared library which will be used across our gems eco system.
  • In fact we have duplicate of class for Taxonomy inside GVB and Gemspy.
  • Also this PR opens question: do we want to be able to have multiple taxonomies and do we want to reference it inside library file.
  • For more details see issue inside GVB

@dusanparipovic
Copy link
Copy Markdown
Contributor Author

Open questions:

  • This PR opens again question about shared library which will be used across our gems eco system.
  • In fact we have duplicate of class for Taxonomy inside GVB and Gemspy.
  • Also this PR opens question: do we want to be able to have multiple taxonomies and do we want to reference it inside library file.
  • For more details see issue inside GVB

@aoustry @tbittar

Copy link
Copy Markdown
Collaborator

@tbittar tbittar left a comment

Choose a reason for hiding this comment

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

  • You need to do more complete checks between the taxonomy and models (variables, parameters, constraints, properties, extra-outputs)
  • The models should declare a list of properties such as :
model: thermal
   properties:
        - id: carrier
        - id: technology

We need to check that each model declares the required properties from the taxonomy (but it could declare additional ones)

  • If a model defines a property, it should be defined for each component of this model within the system file. We need to add a check for this. A component in the system may define additional properties that are not required by the model

I think we should keep this PR on the checks model <-> taxonomy for everything but the properties and handle the work on the properties (which may modify the models, systems and tests) in another PR (check taxonomy <-> library and library <-> system)

Comment thread docs/user-guide/inputs.md

---

## System YAML: optional component `properties`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
## System YAML: optional component `properties`
## System YAML: optional field `properties` for components

Comment thread docs/user-guide/inputs.md
Comment on lines +61 to +62
At resolution time (`resolve_system` / `load_study`), this list is normalized into
a `dict[str, str]` stored on the resolved `Component`. Duplicate ids are rejected.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need these technical details here ? Only mentioning that duplicated ids are forbidden is sufficient ?

Comment thread docs/user-guide/inputs.md

---

## System YAML: optional component `properties`
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should the model declare the list of possible properties ?

Comment thread docs/CHANGELOG.md
---
- **System components: `properties`** - introduces optional `properties` on components in `system.yml` (a list of `id`/`value` pairs). These are normalized into a `dict[str, str]` on the resolved `Component` (duplicate ids raise a `ValueError`).
- **Model schema: `taxonomy-category`** - introduces optional `taxonomy-category` on models in library YAML files, exposed as `ModelSchema.taxonomy_category`.
- **Taxonomy check** - new `gems.model.taxonomy` module with `load_taxonomy(path)` and `check_library_against_taxonomy(library, taxonomy)`. Validates that every model declaring a `taxonomy-category` references a category that exists in the taxonomy file, and exposes all port IDs required by that category. Taxonomy classes (`TaxonomyItem`, `TaxonomyCategory`, `Taxonomy`) mirror the structure defined in GEMS-ViewsBuilder.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think the last sentence is relevant as we do not want to mention GEMSViewsBuilder within GemsPy

Comment thread docs/CHANGELOG.md
---
- **System components: `properties`** - introduces optional `properties` on components in `system.yml` (a list of `id`/`value` pairs). These are normalized into a `dict[str, str]` on the resolved `Component` (duplicate ids raise a `ValueError`).
- **Model schema: `taxonomy-category`** - introduces optional `taxonomy-category` on models in library YAML files, exposed as `ModelSchema.taxonomy_category`.
- **Taxonomy check** - new `gems.model.taxonomy` module with `load_taxonomy(path)` and `check_library_against_taxonomy(library, taxonomy)`. Validates that every model declaring a `taxonomy-category` references a category that exists in the taxonomy file, and exposes all port IDs required by that category. Taxonomy classes (`TaxonomyItem`, `TaxonomyCategory`, `Taxonomy`) mirror the structure defined in GEMS-ViewsBuilder.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- **Taxonomy check** - new `gems.model.taxonomy` module with `load_taxonomy(path)` and `check_library_against_taxonomy(library, taxonomy)`. Validates that every model declaring a `taxonomy-category` references a category that exists in the taxonomy file, and exposes all port IDs required by that category. Taxonomy classes (`TaxonomyItem`, `TaxonomyCategory`, `Taxonomy`) mirror the structure defined in GEMS-ViewsBuilder.
- **Taxonomy check** - new `gems.model.taxonomy` module with `load_taxonomy(path)` and `check_library_against_taxonomy(library, taxonomy)`. Validates that every model declaring a `taxonomy-category` references a category that exists in the taxonomy file, and exposes all variables, parameters, constraints, ports, extra-outputs and properties required by that category. Taxonomy classes (`TaxonomyItem`, `TaxonomyCategory`, `Taxonomy`) mirror the structure defined in GEMS-ViewsBuilder.

"""
Validates that every model declaring a taxonomy_category:
1. References a category that exists in the taxonomy.
2. Exposes all port IDs listed in that taxonomy category.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
2. Exposes all port IDs listed in that taxonomy category.
2. Exposes all variables, parameters, constraints, ports, extra-outputs and properties listed in that taxonomy category.

)

category = categories[cat_id]
model_port_ids = {p.id for p in model_schema.ports}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You need to check more than just the ports, see above comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These tests seem redundant (and less complete) than the one in test_components_parsing.py. Should we remove them ?

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.

2 participants