Skip to content

add_parameter() with DelegateParameter have inconsistent defaults for bind_to_instrument #6715

@thangleiter

Description

@thangleiter

Using the preferred pattern param = inst.add_parameter(...) together with param_cls=DelegateParameter defaults to bind_to_instrument=True, whereas DelegateParameter defaults to False. The latter's behavior is explicitly pointed out in the docs (which also makes sense to me).

However, forcing bind_to_instrument=False raises a QCoDeSDeprecationWarning.

MWE:

>>> from qcodes.instrument import Instrument
>>> from qcodes.parameters import DelegateParameter
>>> inst = Instrument('foo')
>>> param = inst.add_parameter('bar')
>>> delegate = inst.add_parameter('baz', DelegateParameter, source=param)
>>> inst.parameters
{'IDN': <qcodes.parameters.parameter.Parameter: IDN at 1349665492432>,
 'bar': <qcodes.parameters.parameter.Parameter: bar at 1349689473456>,
 'baz': <qcodes.parameters.delegate_parameter.DelegateParameter: baz at 1349691204784>}
>>> inst.remove_parameter('baz')
>>> delegate = inst.add_parameter('baz', DelegateParameter, source=param, bind_to_instrument=False)
2024-12-12 14:22:37,344 ¦ py.warnings ¦ WARNING ¦ warnings ¦ _showwarnmsg ¦ 112 ¦ ...\src\qcodes\instrument\instrument_base.py:184: QCoDeSDeprecationWarning: Parameter baz did not correctly register itself on instrument foo. Please check that `instrument` argument is passed from <class 'qcodes.parameters.delegate_parameter.DelegateParameter'> all the way to `ParameterBase`. This will be an error in the future.
  warnings.warn(

At the very least, the inconsistency should be resolved, however, I'd petition for allowing DelegateParameters not bound to instruments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions