def resolve_parameter_identifier(instrument: InstrumentBase, identifier: str) -> Parameter: parts = identifier.split('.') try: for level in parts[:-1]: instrument = checked_getattr(instrument, level, InstrumentBase) except TypeError: raise RuntimeError( f'Cannot resolve `{level}` in {identifier} to an ' f'instrument/channel for base instrument ' f'{instrument!r}.') try: return checked_getattr(instrument, parts[-1], Parameter) except TypeError: raise RuntimeError( f'Cannot resolve parameter identifier `{identifier}` to ' f'a parameter on instrument {instrument!r}.')
def resolve_parameter_identifier(instrument: ChannelOrInstrumentBase, identifier: str) -> _BaseParameter: parts = identifier.split('.') if len(parts) > 1: instrument = resolve_instrument_identifier( instrument, '.'.join(parts[:-1])) try: return checked_getattr(instrument, parts[-1], _BaseParameter) except TypeError: raise RuntimeError( f'Cannot resolve parameter identifier `{identifier}` to ' f'a parameter on instrument {instrument!r}.')
def resolve_instrument_identifier( instrument: ChannelOrInstrumentBase, identifier: str) -> ChannelOrInstrumentBase: """ Get the instrument, channel or channel_list described by a nested string. E.g: 'dac.ch1' will return the instance of ch1. """ try: for level in identifier.split('.'): instrument = checked_getattr(instrument, level, (InstrumentBase, ChannelList)) except TypeError: raise RuntimeError( f'Cannot resolve `{level}` in {identifier} to an ' f'instrument/channel for base instrument ' f'{instrument!r}.') return instrument