Skip to content

Add flexible metadata system#580

Merged
AdrianSosic merged 59 commits intomainfrom
feat/metadata
Jul 28, 2025
Merged

Add flexible metadata system#580
AdrianSosic merged 59 commits intomainfrom
feat/metadata

Conversation

@tobiasploetz
Copy link
Copy Markdown
Contributor

@tobiasploetz tobiasploetz commented Jun 27, 2025

Summary

This PR implements a flexible metadata system for annotating BayBE objects with a description, unit, and other information. So far integrated into Parameter only.

Usage Example

from baybe.parameters import NumericalDiscreteParameter, ParameterMetadata
from baybe.utils.metadata import to_metadata

# Using dict
# (Gets automatically converted and entries are separated into known and misc fields)
dct = {"description": "Reaction temperature", "unit": "°C", "custom_field": "value"}
param = NumericalDiscreteParameter(
    name="temperature", values=[90, 105, 120], metadata=dct
)

# Using Metadata class directly
meta = ParameterMetadata(
    description="Reaction temperature", unit="°C", misc={"custom_field": "value"}
)
param = NumericalDiscreteParameter(
    name="temperature", values=[90, 105, 120], metadata=meta
)

assert meta == to_metadata(dct, ParameterMetadata) == ParameterMetadata.from_dict(dct)

# Accessing metadata
print(param.description)  # "Reaction temperature"
print(param.unit)  # "°C"

AdrianSosic

This comment was marked as resolved.

@AdrianSosic AdrianSosic added enhancement Expand / change existing functionality new feature New functionality and removed enhancement Expand / change existing functionality labels Jun 27, 2025
AdrianSosic

This comment was marked as resolved.

@AdrianSosic AdrianSosic force-pushed the feat/metadata branch 2 times, most recently from 55d1543 to 48c2abc Compare July 4, 2025 07:18
@AdrianSosic

This comment was marked as resolved.

@AdrianSosic AdrianSosic changed the title Add flexible metadata system for Parameter class Add flexible metadata system Jul 4, 2025
@AdrianSosic AdrianSosic linked an issue Jul 4, 2025 that may be closed by this pull request
@AdrianSosic
Copy link
Copy Markdown
Collaborator

Hey @dasmy. This PR is basically ready for merge but since you also raised that same request, I wanted to hear your thoughts on whether it aligns with your expectations. Anything missing? Regarding the idea to generalize this to all classes --> we can follow up on this in a separate PR. This one here is just to provide the basic skeleton and necessary machinery for serialization so that @tobiasploetz can continue integrating the LLM recommender. But feel free to share any thoughts that come to your mind 🧠

@dasmy
Copy link
Copy Markdown
Contributor

dasmy commented Jul 7, 2025

Thanks for setting this up. This is exactly what I had in mind for #580 .
As noted there, I would love to see this for essentially all serializable objects: Targets will have similar needs like Parameters; Constraints, etc. will likely only need some kind of description support, but who knows what others need.
So definitely green light from my perspective as this is the right step into the right direction. - Will use it ASAP in MTPilot as well ;-)

@AdrianSosic
Copy link
Copy Markdown
Collaborator

Alright, waiting for @Scienfitz's opinion and then we can merge. One thing to discuss: as mentioned in one of the comments, I see the current Metadata class directly applicable to Parameter and Target, and I think they will always share the same set of fields. However, since we probably also want to extend this to Objective and other objects, the unit field is already too specific to have it in the base class. So perhaps it makes sense to split the class into an actual base class that only contains description and unit, and introduce a subclass that is then used for Parameter and Target? Not sure what would be a good name, but basically it would reflect the metadata for a sort of "basic univariate measureable component". Can discuss in the dev meeting

@AdrianSosic AdrianSosic force-pushed the feat/metadata branch 2 times, most recently from a88c3ed to bc1bcc2 Compare July 8, 2025 21:19
Copy link
Copy Markdown
Collaborator

@AVHopp AVHopp left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the work :)


# Folders that are temporarily created when building the documentation
docs/_autosummary
docs/_build
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.

@AdrianSosic could you please add ".env" as another exception as well? Did some cleaning and setup of my local IDE and that would be super helpful :)

We can ensure this through static type checking and our converters, no
unit tests needed
Roundtrip consistency is already tested in the serialization test module
The cases are already covered by the integration and converter tests
@AdrianSosic AdrianSosic merged commit c10e7d7 into main Jul 28, 2025
11 of 12 checks passed
@AdrianSosic AdrianSosic deleted the feat/metadata branch July 28, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature New functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Metadata for Parameters/Targets

6 participants