Looper

The conditional loop executor: decides automatically, from measurement results, whether to repeat, jump or end an experiment loop.

Overview

Looper is a tab in the top dock of the experiment browser (Browser) (quatm/GUI/looper/). It manages groups of experiment tasks, executes the items of a group in order, and decides whether to jump or to stop based on the measurement results. Loop definitions are persisted in configuration/browser/looper/loopfile.json, and the same file is shared with the experiment console on the browser side (Web remote control).

Core logic

LoopManager.run_loop(): loop from the start group forever until terminate
  └─→ run the items of the group in order
       ├─ Task: submit to the experiment queue and advance after it finishes
       │        (max count / max consecutive count can be set; reaching either ends the loop)
       └─ Conditional: read a data-stream field → compare (> >= == != =< <)
                ├─ true → jump to the given item / end of group / end of loop
                └─ false → jump to the else item

Components

ComponentDescription
LoopGroupA loop group (one tab), containing the item list and the loop builder
LoopItemItem base class (delete/up/down/run counter/indicator LED)
TaskItemTask item: points to a staged task, supports max count/max consecutive/skip
ListItemTask list item: expands a task list and runs the tasks one by one
ConditionalItemData condition item: compares a field and then jumps (if/else)
ConditionalReachedItemReached-index condition item: jumps once the current time reaches the N-th cycle’s h5 save time
ConditionalDateTimeItemTime condition item
CallerItem / GroupItemInter-group jump and end-of-group items
DataManagerSubscribes to data streams and accumulates the latest measurement values
LoopManagerThe loop executor (run_loop() / terminate(), running in a background thread)
AutoSaveEditorConfiguration of the automatic HDF5 save schedule

How to use

Operate interactively through the Looper tab in the experiment browser (Browser):

  1. Add a group: create a new tab (New Tab #N), which can be renamed;
  2. Add items: each group can contain Task / List / Conditional / ConditionalDateTime / ConditionalReached / Caller and other items;
  3. Configure items: for Task, select the staged task number and set the maximum count; for Conditional, select the data field, comparison operator and threshold, and configure the if/else jump targets (item index / end box / end loop);
  4. Run: select the starting group and click run; LoopManager executes in a background thread and the terminate button stops it at any time.
# core classes (used internally by the GUI)
from quatm.GUI.looper import Looper, LoopManager

looper = Looper(parent=browser)
looper.loopManager.run_loop()      # start looping from the start group
looper.loopManager.terminate()     # terminate the loop

Persistence and sharing

  • Loop definitions are saved automatically to configuration/browser/looper/loopfile.json ({group name: [item dictionaries, ...]}) and restored automatically when the browser restarts;
  • The desktop GUI and the web remote-control platform share the same file, so changes made on either side are immediately visible on the other; the browser side likewise supports group management, Task/Conditional item editing and starting/stopping loops.