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
Make user interface for components more friendly #99
Comments
Current thoughts on approaches to this, mainly so I can pick it up again at some point without having to revisit it all. Is it just the dunder methods you want to avoid? As it's currently set up, the type specified in the yaml file has to be a subclass of In rough order of complexity/magic Change the name of the methodThis avoids using the @dataclass
class Amplifier(ComponentConfig):
init_amp: float
def build(self) -> Component:
return DeviceSimulation(
name=self.name,
device=AmplifierDevice(init_amp),
adapters=AmplifierAdapter(),
) then, in the - [config().run_forever(*get_interface(backend)) for config in configs]
+ [config.build().run_forever(*get_interface(backend)) for config in configs] On the plus side, there is very little that needs to change and it prevents the Create a new class at runtime via a decoratorI think this is closest to the example in the issue. With a decorator we'd somehow convert a function such as def amplifier(name: str, inputs: Dict[PortID, ComponentPort], init_amp: float) -> Component:
return DeviceSimulation(
...
) into a class that would otherwise look something like class amplifier(ComponentConfig):
init_amp: float
def __call__(self):
return DeviceSimulation(
...
)
Given the end result of this, the rest of the code would remain the same (and existing implementations would not have to change either). I also doubt it would play nicely with any type checking but not sure if that's an issue as these objects only seem to exist during the deserialisation and then the returned Component is used for everything else. Add Magic to the deserialisationThe current This approach has the potential to make the end user facing bit the simplest at the expense of being very tightly coupled to a particular deserialisation library. With the change from apischema to pydantic to pydantic2, this doesn't seem like a route we want to follow. Refactor config loadingWe're currently deserialising the yaml config to a list of ComponentConfigs which are then called in turn to create the Components. We could instead change the yaml format and deserialisation target to something like The Components could then be created via It would mean a lot of change across the whole project though so maybe best avoided if we're otherwise happy with the design. |
Closed as won't do for now. Can be reopened as a 'redesign ComponentConfig' ticket Is this is wanted in the future. |
Currently to set up a component you have to override the
__call__
method ofComponentConfig
. This is user facing so should be made to avoid a dunder method.Maybe something like:
The text was updated successfully, but these errors were encountered: