nulinspiratie / SilQ

Software for quantum control of donor atoms in silicon
Other
6 stars 1 forks source link

Qcodes: Creating a Parameter (not using add_parameter) for an instrument requires parent to be set manually #230

Open maij opened 4 years ago

maij commented 4 years ago

This may only apply to VISA instrument parameters, the error that arises is below.

This is a minimal working example from the Keithley SMU, in this case the get command fails but the set command is fine.

self.sense_mode = Parameter('sense_mode',
                                    parent=self,
                                    get_cmd=':SENS:FUNC?',
                                    set_cmd=self._set_sense_mode)

self.sense_mode_nopar = Parameter('sense_mode',
                                    get_cmd=':SENS:FUNC?',
                                    set_cmd=self._set_sense_mode)

In Jupyter I run

smu.sense_mode() # Output "VOLT"
smu.sense_mode_nopar() # raises err below

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-10-95b4ee551e2c> in <module>
----> 1 smu.sense_mode_nopar()

c:\users\labuser\documents\github\qcodes\qcodes\instrument\parameter.py in __call__(self, *args, **kwargs)
    405         if not args and not kwargs:
    406             if hasattr(self, 'get'):
--> 407                 return self.get()
    408             else:
    409                 raise NotImplementedError('no get cmd found in' +

c:\users\labuser\documents\github\qcodes\qcodes\instrument\parameter.py in get_wrapper(*args, **kwargs)
    628             except Exception as e:
    629                 e.args = e.args + ('getting {}'.format(self),)
--> 630                 raise e
    631 
    632         return get_wrapper

c:\users\labuser\documents\github\qcodes\qcodes\instrument\parameter.py in get_wrapper(*args, **kwargs)
    598             try:
    599                 # There might be cases where a .get also has args/kwargs
--> 600                 value = get_function(*args, **kwargs)
    601                 self.raw_value = value
    602 

c:\users\labuser\documents\github\qcodes\qcodes\utils\command.py in __call__(self, *args)
    175             raise TypeError(
    176                 'command takes exactly {} args'.format(self.arg_count))
--> 177         return self.exec_function(*args)

AttributeError: ("'Command' object has no attribute 'exec_function'", 'getting smu_sense_mode')

What's also strange is that instrument initialisation takes a lot longer (~ 30s, usually its < 1s) when I include the second sense_mode parameter.

maij commented 4 years ago

I've thought about this more and I don't think this is a bug, it's the expected behaviour because a Parameter created in an arbitrary context doesn't know about it's instrument or parent.

nulinspiratie commented 4 years ago

Well hold your horses, I think this is a bug and should be resolved. I understand that at the start the instantiated parameter does not have a parent and consequently get/set shouldn't work. However, once you attach it to a ParameterNode, its parent is set and so it shouldn't fail anymore.

I think the way to resolve this is by having the get/set cmd access the parameter parent. If this isn't defined it raises an error, but only once the get/set is called. This way, the parent can be defined later. What do you think?