[docs]classArgumentProvider:static_arguments={}def__init__(self):""" Abstract base class to represent argument providers for experiments. """passdef_build_arguments(self,target_class:type,arguments:dict={})->dict:""" Build the argument dict. This is intended to be overwritten by subclasses to implement the logic for the respective backend Args: target_class: The class of the target for which to build the arguments arguments: arguments to be considered additionally """raiseNotImplementedError("Implement getting the arguments dict in a subclass")
[docs]defget_arguments(self,target_class:type)->dict:""" Query the arguments dict from the argument provider. Args: target_class: The class of the target for which to build the arguments Returns: dict: Argument dictionary in the format required by atomiq """logger.debug(f"Getting arguments for class {target_class.__name__}")returnself._build_arguments(target_class,copy(self.static_arguments))
[docs]defupdate_argument(self,name:str,arg_def:dict):""" Update the argument definition in the backend of the argument provider, i.e. store updated values Args: name: Name or identifier of the argument arg_def: dict with argument definition to be stored """raiseNotImplementedError("Implement updating in the backend in subclasses")
[docs]classNativeArgumentProvider(ArgumentProvider):def__init__(self):""" An argument provider that only returns the arguments defined by the `arguments` attribute in the target class and joins them with `static_arguments` (if defined) of this argument provider. """ArgumentProvider.__init__(self)def_build_arguments(self,target_class:type,arguments:dict={})->dict:""" Build the argument dict from the `arguments` attribute of the target class. This enables to just write a dict with the argument definition in the experiment class Args: target_class: The class of the target for which to build the arguments arguments: arguments to be considered additionally """ifhasattr(target_class,"arguments"):arguments.update(target_class.arguments)returnarguments