Skip to content

Add general condition feature

Zbigniew Reszela requested to merge github/fork/reszelaz/general_condition into develop

General condition is a feature used successfully at DESY for some years already. It allows the users to easily repeat the acquisitions if certain conditions are not satisfactory. The user simply writes a macro which return value decides if the acquisition should be repeated and set it via GeneralCondition environment variable. You can find the original implementation authored by @teresanunez in https://github.com/desy-fsec/sardana (mainly gscan.py module).

Today with @teresanunez we had a pair-programming session in which we came with the following ideas:

  • The step scan generator seems to already fullfill most of the requirements (not the part of not repeating the motion to the same position but this one would be covered if we go for https://github.com/sardana-org/sardana/issues/1159#issuecomment-764702323). The step scan generator however requires from the user to write a new scan macro. The general condition feature is for users with less programming skills who do not want to learn how to program a new scan macro.
  • The general condition feature is not for pausing the scan and waiting for optimal conditions to continue - for these kind of needs it is better to use pre-step, pre-move or pre-acq hooks.

This PR changes the approach from the original implementation and moves the condition execution to the step scan generator of the built-in scan macros (for the moment only aNscan) which we believe fits better to the current design of the scan framework - the SScan simply obeys what the generator ask it for.

Updated: Even if the PR is marked as WIP it is already operational but it will keep moving the motors to the same position in case of repeating the acquisition - again see https://github.com/sardana-org/sardana/issues/1159#issuecomment-764702323.

Before integrating it, apart from adding the documentation, I propose that we also clarify the following points:

  1. Think if simply having another hook-place e.g. repeat-acq repeat-step (still executed from the generator) wouldn't be simpler instead of adding a new environment variable GeneralCondition. We could still keep the environment variable for the backwards compatibility for DESY. This is more about recommendations for the new users of this feature.
  2. At DESY some users already asked about extending this feature with the possibility of not saving the acquisitions points which do to fullfill the condition. Maybe this should actually be the default behavior of this feature?
  3. Do we add this feature to the fscan and mesh macros as well?

It would be greate to hear your opinions about these points and this feature in general.

One important thing is that using the general condition automatically disables the deterministic scans optimizations.

Thanks @teresanunez for your patience! Sorry you had to wait so long until we finally found some time to deeply analyze the requirements and review your great work!

Fixes #201 (closed)

Edited by Zbigniew Reszela

Merge request reports