diff --git a/qcodes/instrument/base.py b/qcodes/instrument/base.py index 1549f5ba079b..53359361816d 100644 --- a/qcodes/instrument/base.py +++ b/qcodes/instrument/base.py @@ -514,6 +514,26 @@ def __call__(cls, *args: Any, **kwargs: Any) -> Any: Overloads `type.__call__` to add code that runs only if __init__ completes successfully. """ + if len(args) >= 1: + name = args[0] + else: + name = kwargs.get("name", None) + existing_instr = None + if name is not None: + + try: + existing_instr = cls.find_instrument(name, cls) # type: ignore[attr-defined] + except (KeyError, TypeError): + pass + + if existing_instr is not None: + log.info(f"Reusing existing instrument {name}") + # todo this is only really safe if this is the same instrument + # e.g. address should be the same but that is a trait only implemented + # in subclasses + return existing_instr + + new_inst = super().__call__(*args, **kwargs) is_abstract = new_inst._is_abstract() if is_abstract: