You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
defget_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. """returntuple(
req.attribute_nameforreqin (self.required_models+self.required_connections)
ifgetattr(self, req.attribute_name) isNoneand (optionalorreq.hard)
)
This would give:
importbrimasbmbike=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 beprint((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.frombrim.coreimportRegistryreg=Registry()
print(reg.get_from_requirement(bike.required_models[0]))
# -> [<class 'brim.bicycle.rear_frames.RigidRearFrameMoore'>, <class 'brim.bicycle.rear_frames.RigidRearFrame'>]
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:
ModelBase.get_unspecified_components
and have it return:Here is an example implementation:
This would give:
@moorepants what is your preference?
The text was updated successfully, but these errors were encountered: