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

Feature request: get unspecified components #124

Open
tjstienstra opened this issue Dec 8, 2023 · 0 comments
Open

Feature request: get unspecified components #124

tjstienstra opened this issue Dec 8, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@tjstienstra
Copy link
Collaborator

In a tutorial session of BRiM (#122), it was noted that it would be nice if one could easily see what components should still be specified. This is in general not a difficult feature to implement. However, we should make a good choice of what the most optimal output is. Some options are:

  • Create a method ModelBase.get_unspecified_components and have it return:
    • An iterable of attribute strings, which should be specified (advantage is that it is nice and short, but lacks extra information, which can of course be requested)
    • An iterable of unsatisfied requirements (disadvantage is that printing this gives quite a repr)
  • Other options ...

Here is an example implementation:

    def get_unspecified_components(self, optional: bool = False) -> tuple[str]:
        """Get the unspecified components of the model.
        
        Parameters
        ----------
        optional : bool, optional
            Whether to include the optional components, by default False.
        """
        return tuple(
            req.attribute_name
            for req in (self.required_models + self.required_connections)
            if getattr(self, req.attribute_name) is None and (optional or req.hard)
            )

This would give:

import brim as bm
bike = bm.WhippleBicycle("bike")
print(bike.get_unspecified_components())
# -> ('rear_frame', 'front_frame', 'rear_wheel', 'front_wheel', 'ground', 'front_tire', 'rear_tire')
bike.rear_frame = bm.RigidRearFrame("rear_frame")
bike.front_frame = bm.RigidFrontFrame("front_frame")
bike.rear_wheel = bm.KnifeEdgeWheel("rear_wheel")
bike.front_wheel = bm.KnifeEdgeWheel("front_wheel")
bike.rear_tire = bm.NonHolonomicTire("rear_tire")
print(bike.get_unspecified_components())  # -> ('ground', 'front_tire')
print(bike.get_unspecified_components(True))  # -> ('cranks', 'ground', 'front_tire')

# Advantage of returning requirements would be
print((bike.required_models[0],))  # A lot of data
# -> (ModelRequirement(attribute_name='rear_frame', types=(<class 'brim.bicycle.rear_frames.RearFrameBase'>,), description='Submodel of the rear frame.', full_name='Rear frame', type_name='RearFrameBase'),)
# And it is easy to combine with the registry.
from brim.core import Registry
reg = Registry()
print(reg.get_from_requirement(bike.required_models[0]))
# -> [<class 'brim.bicycle.rear_frames.RigidRearFrameMoore'>, <class 'brim.bicycle.rear_frames.RigidRearFrame'>]

@moorepants what is your preference?

@tjstienstra tjstienstra added the enhancement New feature or request label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant