-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4923: Move VoltageDivider into parameters and deprecate r=jenshnielsen a=jenshnielsen This is not an instrument but a Parameter so it makes more sense for it to live there. Since DelegateParamerer does the same more general and better deprecate this one Co-authored-by: Jens H. Nielsen <Jens.Nielsen@microsoft.com>
- Loading branch information
Showing
3 changed files
with
111 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
from .devices import VoltageDivider | ||
from qcodes.parameters.voltage_divider import VoltageDivider | ||
|
||
""" | ||
Deprecated alias will be removed | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,5 @@ | ||
from typing import Optional, Union | ||
""" | ||
Alias for backwards compatiblility. Will be deprecated and removed in a future version of QCoDeS | ||
""" | ||
|
||
from qcodes.instrument import Instrument | ||
from qcodes.parameters import Parameter | ||
|
||
|
||
class VoltageDivider(Parameter): | ||
""" | ||
Resitive voltage divider | ||
To be used when you use a physical voltage divider to set or get a voltage. | ||
Initialize the voltage diveder by passing the parameter to be measured | ||
and the value of the division (which should be calibrated beforehand) | ||
>>> vd = VoltageDivider(dac.chan0, 10) | ||
The voltage divider acts a your original parameter, but will set the right | ||
value, and store the division_value in the metadata. | ||
Set the value you want to set your device at 10 V | ||
>>> vd(10) | ||
This will set the dac.cha0 at 10*10, but upon measuring the divider | ||
the value returned is the voltage at the sample. | ||
>>> vd() | ||
10 | ||
To get the voltage that was actually set on the instrument: | ||
>>> vd.get_instrument_value() | ||
100 | ||
Args: | ||
v1: Parameter physically attached to the divider as input | ||
division_value: the divsion value of the divider | ||
label: label of this parameter, by default uses v1 label | ||
but attaches _attenuated | ||
name: name of this parameter, by default uses v1 name | ||
but attaches _attenuated | ||
""" | ||
|
||
def __init__(self, | ||
v1: Parameter, | ||
division_value: Union[int, float], | ||
name: Optional[str] = None, | ||
label: Optional[str] = None, | ||
instrument: Union[None, Instrument] = None) -> None: | ||
self.v1 = v1 | ||
self.division_value = division_value | ||
if label: | ||
self.label = label | ||
else: | ||
self.label = f"{self.v1.label}_attenuated" | ||
|
||
if not name: | ||
name = f"{self.v1.name}_attenuated" | ||
|
||
if not instrument: | ||
instrument = getattr(self.v1, "_instrument", None) | ||
super().__init__( | ||
name=name, | ||
instrument=instrument, | ||
label=self.label, | ||
unit=self.v1.unit, | ||
metadata=self.v1.metadata) | ||
|
||
# extend metadata | ||
self._meta_attrs.extend(["division_value"]) | ||
|
||
def set_raw(self, value: Union[int, float]) -> None: | ||
instrument_value = value * self.division_value | ||
self.v1.set(instrument_value) | ||
|
||
def get_raw(self) -> Union[int, float]: | ||
""" | ||
Returns: | ||
value at which was set at the sample | ||
""" | ||
value = self.v1.get() / self.division_value | ||
return value | ||
|
||
def get_instrument_value(self) -> Union[int, float]: | ||
""" | ||
Returns: | ||
value at which the attached parameter is (i.e. does | ||
not account for the scaling) | ||
""" | ||
return self.v1.get() | ||
from qcodes.parameters.voltage_divider import VoltageDivider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from qcodes.parameters import Parameter | ||
from qcodes.utils import deprecate | ||
|
||
if TYPE_CHECKING: | ||
from qcodes.instrument import Instrument | ||
|
||
|
||
@deprecate(alternative="DelegateParameter") | ||
class VoltageDivider(Parameter): | ||
""" | ||
Resitive voltage divider | ||
To be used when you use a physical voltage divider to set or get a voltage. | ||
Initialize the voltage diveder by passing the parameter to be measured | ||
and the value of the division (which should be calibrated beforehand) | ||
>>> vd = VoltageDivider(dac.chan0, 10) | ||
The voltage divider acts a your original parameter, but will set the right | ||
value, and store the division_value in the metadata. | ||
Set the value you want to set your device at 10 V | ||
>>> vd(10) | ||
This will set the dac.cha0 at 10*10, but upon measuring the divider | ||
the value returned is the voltage at the sample. | ||
>>> vd() | ||
10 | ||
To get the voltage that was actually set on the instrument: | ||
>>> vd.get_instrument_value() | ||
100 | ||
Args: | ||
v1: Parameter physically attached to the divider as input | ||
division_value: the divsion value of the divider | ||
label: label of this parameter, by default uses v1 label | ||
but attaches _attenuated | ||
name: name of this parameter, by default uses v1 name | ||
but attaches _attenuated | ||
""" | ||
|
||
def __init__( | ||
self, | ||
v1: Parameter, | ||
division_value: int | float, | ||
name: str | None = None, | ||
label: str | None = None, | ||
instrument: None | Instrument = None, | ||
) -> None: | ||
self.v1 = v1 | ||
self.division_value = division_value | ||
if label: | ||
self.label = label | ||
else: | ||
self.label = f"{self.v1.label}_attenuated" | ||
|
||
if not name: | ||
name = f"{self.v1.name}_attenuated" | ||
|
||
if not instrument: | ||
instrument = getattr(self.v1, "_instrument", None) | ||
super().__init__( | ||
name=name, | ||
instrument=instrument, | ||
label=self.label, | ||
unit=self.v1.unit, | ||
metadata=self.v1.metadata, | ||
) | ||
|
||
# extend metadata | ||
self._meta_attrs.extend(["division_value"]) | ||
|
||
def set_raw(self, value: int | float) -> None: | ||
instrument_value = value * self.division_value | ||
self.v1.set(instrument_value) | ||
|
||
def get_raw(self) -> int | float: | ||
""" | ||
Returns: | ||
value at which was set at the sample | ||
""" | ||
value = self.v1.get() / self.division_value | ||
return value | ||
|
||
def get_instrument_value(self) -> int | float: | ||
""" | ||
Returns: | ||
value at which the attached parameter is (i.e. does | ||
not account for the scaling) | ||
""" | ||
return self.v1.get() |