Reconfigure()
reconfigure() adapts a device's configuration to new experimental conditions during a run.
For example, a temperature module in the sequence sweeps a temperature, and a Logger needs to adjust its measurement mode depending on the temperature.
reconfigure() is only called if a GUI parameter of the module has changed its value, e.g. because it uses the parameter syntax {...}. SweepMe! checks this whenever the module signs in, i.e. when a module higher up in the sequencer varies its sweep value, and then calls reconfigure() right before signin().
When a module becomes active, i.e. part of an active branch, changed parameters are already handed over to the driver before configure() is called. Therefore, reconfigure() is not needed at this point.
Sequencer Example
Temperature - Eurotherm (Sweeps 10-50°C)
└── Logger - Multimeter
└── SMU - Keithley 4200-SCS (Sweeps 1.0 - 2.0 V)
The temperature module is higher than the logger.
Whenever the temperature sweep value changes, the signin() function of the Logger and SMU drivers is called. If one of their GUI parameters has changed, reconfigure() is called right before.
When the SMU sweeps, however, signin() and reconfigure() of the higher-up modules (Temperature and Logger) are not called.
Therefore, it is important to structure your sequencer in a way that signin() and reconfigure() are called only when appropriate.
Variable GUI Parameters
The Parameter system can be used to set dynamic configurations.
Example: Your logger can have a reference temperature, where you can set the set temperature of the temperature module by using
{Temperature1_SweepValue}
This allows a module to adapt automatically to another module's sweep value in real-time.
Programming
The standard implementation in pysweepme.EmptyDeviceClass is as follows:
def reconfigure(self, parameters: dict[str, Any] | None = None, keys: list[str] | None = None) -> None:
"""Function to be overridden if needed.
If a GUI parameter changes after replacement with global parameters, the device needs to be reconfigured.
Default behavior is that all parameters are set again and 'configure' is called.
The device class maintainer can redefine/overwrite 'reconfigure' with a more individual procedure.
Args:
parameters: Dictionary of all current GUI parameters.
keys: List of parameter keys that changed. Ignored in the base implementation, but available
for subclasses that want to reconfigure only the affected parameters.
"""
if parameters is None:
parameters = {}
if self.uses_update_gui_parameters:
if parameters:
self.apply_gui_parameters(parameters)
self.update_gui_parameters(parameters)
else:
self.get_GUIparameter(parameters)
self.configure()
By default, the GUI parameters of the module are read out again and given as parameters, and configure() is called again.
The keys argument is a list of parameter names that have changed.
This allows the driver to update only those parameters instead of reconfiguring everything.
Example Customization
Developers can overwrite reconfigure() in their own device class for more fine-grained control.
For example, a driver could update only those settings that have changed:
def reconfigure(self, parameters=None, keys=None):
if "Range" in keys:
self.set_range(parameters["Range"])
if "SamplingRate" in keys:
self.set_sampling_rate(parameters["SamplingRate"])
This approach improves performance when working with complex devices or time-critical systems, as only the relevant parts of the configuration are updated.
If you override reconfigure(), make sure that every parameter that can change via {...} is still sent to the instrument.