Variables

Variables represent the quantities of interest in an experiment. The classes below provide a layer of abstraction away from the particular hardware or software origin of the variable value. Each variable has a value property which evaluates the variable when called, e.g. ‘foo = variable.value’. If the variable is settable, such as a Knob or Parameter, the value property can be set by assignment, e.g. knob.value = foo.

class empyric.variables.Variable

Base class representing a specific quantity of interest monitored in an experiment.

last_evaluation = None

time since the epoch of last evaluation in seconds, being equal to the result of time.time() being called upon the most recent evaluation of the value property

property type

Data type of the variable

property settable

Whether values can be assigned to the variable by the user

property value

The value of the variable

static setter_type_validator(setter)

Checks that set value is compatible with variable’s type

static getter_type_validator(getter)

Checks that get value is compatible with variable’s type


class empyric.variables.Knob(instrument: Instrument, knob: str, lower_limit: float | int = None, upper_limit: float | int = None, multiplier: float | int = 1, offset: float | int = 0)

Variable that can be directly controlled by an instrument, such as the voltage of a power supply.

The instrument argument specifies which instrument the knob is associated with.

The knob argument is the label of the knob on the instrument.

The optional lower_limit and upper_limit keyword arguments set the lower and upper limits for the knob. If an attempt it made to set a value above/below the upper/lower limit, it is set to the upper/lower limit value.

The optional multiplier and offset keyword arguments provide a means to affect a linear transformation of the raw knob value. Readings from the instrument will be multiplied by the multiplier and then increased by the offset. Set commands to the instrument will take the knob value, subtract the offset and divide by the multiplier.

_settable = True
property value

Value of the knob of an instrument


class empyric.variables.Meter(instrument: Instrument, meter: str, gate=None, multiplier: float | int = 1, offset: float | int = 0)

Variable that is measured by an instrument, such as temperature.

Some meters can be controlled directly or indirectly through an associated (but distinct) knob.

The instrument argument specifies which instrument the meter is associated with.

The meter argument is the label of the meter on the instrument.

The gate optional argument is another variable which gates measurements. This is useful for situations where indefinitely continuous measurement of the meter, as in the usual experiment loop, is not desirable. Generally, it should be a variable of integer, boolean or toggle type. When the gate variable evaluates to 1/True/On, the meter can be measured. Otherwise, attempts to measure the meter will have no effect (None is returned).

The optional multiplier and offset keyword arguments provide a means to affect a linear transformation of the raw meter value. Readings from the instrument will be multiplied by the multiplier and then increased by the offset.

_settable = False
property value

Measured value of the meter of an instrument


class empyric.variables.Expression(expression: str, definitions: dict = None)

Variable that is calculated based on other variables of the experiment

For example, the output power of a power supply could be recorded as an expression, where voltage is a knob and current is a meter: power = voltage * current.

The expression argument is a string that can be evaluated by the Python interpreter, replacing symbols with the values of variables according to the definitions argument.

The definitions argument is a dictionary mapping symbols in the expression argument to variables.

_settable = False
property value

Value of the expression

static fft(s)

Calculate the fast Fourier transform of a signal

static ifft(s)

Calculate the inverse fast Fourier transform of a signal

static carrier(s, dt, f0=0.0, bw=inf)

Find the carrier frequency of a signal

static ampl(s, dt, f0=0.0, bw=inf)

Calculate the amplitude of the carrier wave in a signal

static demod(s, dt, f0, bw=inf, cycles=inf, filt=None)

Demodulate an oscillatory signal


class empyric.variables.Remote(server: str, alias: int | str, protocol: str = None, settable: bool = False, lower_limit: float | int = None, upper_limit: float | int = None, multiplier: float | int = 1, offset: float | int = 0)

Variable controlled by an experiment (running a server routine) on a different process or computer.

The server argument is the IP address and port of the server, in the form ‘(ip address)::(port)’.

The alias argument identifies the particular variable on the server to link to. For socket servers, this is simply the name of the variable on the server. For Modbus servers, this is the starting address of the holding or input register for a read/write or readonly variable, respectively. For either set of registers, the starting address is 5*(n-1) for the nth variable in the knobs or meters of variables in the server routine definition.

The (optional) protocol argument indicates which kind of server to connect to. Setting protocol=’modbus’ indicates a Modbus server (controlled by a ModbusServer routine on the remote process/computer), and any other value or no value indicates a socket server (controlled by a SocketServer routine).

The settable argument is required for remote variables on a Modbus server, and is not used for a socket server. If settable is set to True, then the variable value is read from the holding registers (knobs), otherwise the variable value is read from the input registers (meters).

The optional multiplier and offset keyword arguments provide a means to affect a linear transformation of the raw variable value. Readings from the instrument will be multiplied by the multiplier and then increased by the offset. Set commands to the server will take the variable value, subtract the offset and divide by the multiplier.

property value

Value of the remote variable on a server

get_type()

Get the data type of the remote variable

get_settable()

Get settability of remote variable


class empyric.variables.Parameter(parameter: float | int | bool | str | Toggle | ndarray)

Variable whose value is assigned directly by the user or indirectly with a routine. An example is a unit conversion factor such as 2.54 cm per inch, a numerical constant like pi or a setpoint for a control routine.

The parameter argument is the given value of the parameter.

_settable = True
property value

Value of the parameter