Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameter set to improvements #1749

Conversation

WilliamHPNielsen
Copy link
Contributor

@WilliamHPNielsen WilliamHPNielsen commented Oct 4, 2019

This PR fixes a bug in parameter.set_to and reduces the amount of instrument communication (calls to parameter.set) that happens in the context manager.

The bugfix: if a parameter has been initialized, but not yet gotten, it will have a _latest["value"] of None. When exiting the context manager, the value that the parameter is restored to should not be None, but instead the result of parameter.get.

The improvement: if parameter has value X, then with parameter.set_to(X) is now a NOOP.

The improvement allows us to write parameter getters that hinge on other parameters without introducing unnecessary communication. An example (simplified) for a DMM that can be in voltage or current mode:

def _voltage_getter(self):
    with self.mode.set_to("voltage"):
        value = self.ask("READ?")
    return value

def _current_getter(self):
    with self.mode.set_to("current"):
        value = self.ask("READ?")
    return value

Imagine getting the voltage or current in a tight loop. In that case, we do not want the communication to be

MODE:VOLTAGE
READ?
MODE:VOLTAGE

for each get call.

@QCoDeS/core

@codecov
Copy link

codecov bot commented Oct 4, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@9bf9494). Click here to learn what that means.
The diff coverage is 100%.

@@            Coverage Diff            @@
##             master    #1749   +/-   ##
=========================================
  Coverage          ?   67.59%           
=========================================
  Files             ?      146           
  Lines             ?    18266           
  Branches          ?        0           
=========================================
  Hits              ?    12346           
  Misses            ?     5920           
  Partials          ?        0

self._value_is_changing = self._value != self._original_value

if self._original_value is None and self._value_is_changing:
self._original_value = self._parameter.get() # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the merge of #1738 please don't use bare ignores. use --show-error-codes to get the error code needed and do ignore[errorcode]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants