Parameter system

From SweepMe! Wiki
(Redirected from Parameter Picker)
Jump to navigation Jump to search

Starting from SweepMe! version 1.5.5, a parameter system allows you to use placeholders in many input fields of the program, so that values can depend on other modules, sweep values, or the date and time.

A list of all defined parameters and their current values can be found using the widget Parameters.

To use a parameter in an input field, put its key in curly brackets {...}. Whenever SweepMe! detects curly brackets, the content of the brackets is replaced. There are two cases:

  1. The content is exactly a known parameter key. For example, using {Y} in a text field inserts the current year.
  2. If the content is not a known parameter key, SweepMe! evaluates it as a Python expression, e.g. { 2+2 } inserts 4.

Brackets are resolved from the innermost pair outwards, so parameters and inline evaluation can be combined, e.g. { int({Y}) + int({m}) } adds the current year and the current month as integers.

Parameter keys

Keys of module variables are built from the module label, the variable name and the unit, joined by underscores: <Label>_<Variable>_<Unit>. Spaces are replaced by underscores and the unit is omitted if it is empty, e.g. SMU1_Voltage_V, Time_elapsed_s or Time_index.

Each module with a label further provides:

  • <Label>_SweepValue: the current sweep value of the module
  • <Label>_SweepIndex: the index of the current sweep value, starting at 1
  • <Label>_is_active: True if the module is part of the branch that is currently measured

System parameters:

  • Date and time (as text): Y (year), y (year, 2 digits), m (month), d (day), H (hour), I (hour, 12h), p (AM/PM), M (minute), S (second)
  • folder and filename: the folder and the file name entered for saving data
  • datapath: the folder in which measurement data is saved
  • profile: the current profile
  • run_index: the number of the current run

Parameter picker

From version 1.6.1.2, input fields that support the parameter syntax show a "{}" button when the mouse is over the field. It opens a list of all available parameters with their current values, grouped by "this branch", "other modules", "time & system" and "session & file". Selecting an entry inserts its key in curly brackets. The list can also be opened via right-click -> Insert parameter…, with Ctrl+Space, or by typing "{" in the field, which shows the matching parameters while you type.

When the input contains curly brackets, the field checks it while you type:

  • A warning icon appears if a key is unknown, the brackets are unbalanced, or a module is referenced that runs later in the sequence. Move the mouse over the field to see the reason.
  • Otherwise, the tooltip shows the resolved value, e.g. "Resolves to: ...". Expressions are only evaluated during the run.

Values and types

A parameter keeps the type of its value, e.g. a float, an integer, a string or a list. When a parameter is inserted into a text, its value is converted to text. String values are inserted without quotation marks. Therefore, to compare a string parameter, put the parameter in quotation marks and use the Python comparison operator "==":

{ "{my_parameter}" == "dog" }

The date and time parameters are strings. Use int(...) to calculate with them, as shown in the example above.

Dictionaries are not supported by the parameter syntax.

Inline evaluation

For security reasons, the inline evaluation does not have access to the Python built-in functions, modules or imports. Only the following functions and constants can be used:

  • General: abs, len, min, max, int, float, round, str, repr, type, print
  • Date and time: now (current date and time)
  • Math: pi, ceil, floor, fabs, fmod, frexp, hypot, ldexp, modf, pow, degrees, radians, sqrt, exp, log, ln, log10, sign
  • Trigonometry: sin, cos, tan, asin, acos, atan, atan2, arcsin, arccos, arctan, arctan2, sinh, cosh, tanh
  • Complex numbers: absolute, real, imag, angle, conj
  • Arrays: mean, average, sum, arange, linspace, logspace, divide, trapz
  • Random numbers: random, randint
  • Other: isnan

log and ln both calculate the natural logarithm.

When are values available?

  • System parameters such as date and time, folder or profile are available at any time.
  • The sweep value, the sweep index and the active state of a module are set before the module and the modules below it are configured. They can be used in the configuration fields of the modules in the same branch.
  • Measured values of a module are only published after the measurement of a measurement point has finished. Configuration fields and sweep values are read before the measurement, so a measured value of the same measurement point is not available yet. You get the value of the previous measurement point or nothing at the first point.
  • Some modules provide their values before the measurement: Form, ReadValues, and Calc if its execution is set to run before the branch or before each point. Use them for values that are needed in configuration fields and sweep values.
  • Parameters of modules that are unchecked in the sequencer are not available. At the start of a run, the parameters of the previous run are removed.

Creation of individual parameters

Individual parameters can be defined using the Pro module Form that is used to create form-like widgets.

ParameterManager

The ParameterManager is a library that comes with SweepMe! and can be used to query individual parameters in your script, e.g. a CustomFunction script.

Here is an example how to use it:

import ParameterManager
ParM = ParameterManager.ParameterManager()

# retrieve a list of keys to check whether a key exists
keys = ParM.get_all_keys()  
print("Keys:")
print(keys)

# retrieve a value for a given key
key = "Time_elapsed_s"
value = ParM.get_parameter(key)
print("Elapsed time:", value)

# Attention: Please be cautious with using this possibility as it can break and is often not very much reusable.
# set an existing key
key = "Calc1_Parameter_unit"
value = "a new value"
ParM.set_parameter(key, value)

The key can be any key as listed in the Parameters widget.