PySequencer: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
No edit summary
Line 51: Line 51:
** '''seq.wait_func(func, check_period_secs=0.1)'''
** '''seq.wait_func(func, check_period_secs=0.1)'''
** '''seq.wait_clients_running(client_names, timeout_secs=10)
** '''seq.wait_clients_running(client_names, timeout_secs=10)
** '''seq.wait_events(target)''' retrieves a parameter ''name'' from the sequence start
** '''seq.wait_events(target)'''
** '''seq.set_run_description(desc)'''
** '''seq.set_run_description(desc)'''
* Run control
* Run control

Revision as of 22:51, 4 September 2025

Introduction

Midas contains a Sequencer that can be used to automate data-taking (e.g. starting and stopping many runs with different settings). The original Seqeuncer uses the custom Midas Script Language (MSL), which has a limited syntax. For more demanding tasks requiring complex calculations, a Python-based sequencer has been developed in 2025. The idea is very similar to the MSL sequencer and the user interface is exactly the same, but instead of MSL commands the PySequencer accepts python programs. The interaction with the midas system is done via a special "seq" object. Following example illustrates a simple script asking for a number of runs and then starting/stopping these runs, each lasting 60 seconds:

# This is PySequencer test file

def define_params(seq):
    seq.register_param("runs", "Number of runs", 3)

def sequence(seq):
    runs = seq.get_param("runs")

    for r in seq.range(runs):
        seq.start_run()
        seq.wait_seconds(60)
        seq.stop_run()

The parameters are optional and can be committed. If defined, a dialog box opens when the user starts the sequence and prompts the user to input the parameter values to use.

The user can track the state of the sequence via a webpage that shows:

  • the current line in the script, highlighted in yellow
  • the value of any parameters/variables, shown in a table
  • the progress of any loops or waits, shown as progress bars

Pysequencer.png

Installation

Before the PySequencer can be used, python must be installed and enabled for midas. See Python Installation for details.

Next, the PySequencer menu must be enabled in the ODB with /Experiment/Menu/PySequencer = 1. Now one can click on the "PySequencer" menu item and use the GUI in a similar way than the MSL sequencer. Syntax highlighting happens according to python, and all python variables are shown at the right side of the page for debugging purposes. If the PySequencer is not running, the GUI asks to start python3 $MIDASSYS/python/midas/sequencer.py -D. If this command failed, the user should try to execute it manually to see if there are any errors.

seq Object Reference

Users have access to the seq object in their scripts, which is a midas.sequencer.SequenceClient object. This class inherits from the standard midas.client.MidasClient object, and adds extra sequencer-specific tools.

Full documentation of these classes can be found in docstrings in the source code:

A summary of the available commands is:

  • Sequencer-specific:
    • seq.register_param(name, comment, default_value, options=[])
    • seq.get_param(name)
    • seq.sequencer_msg(text, wait=False)
    • seq.range(n)
    • seq.wait_seconds(n)
    • seq.wait_odb(path, op, target, between_upper_target=None, stable_for_n_secs=None)
    • seq.wait_func(func, check_period_secs=0.1)
    • seq.wait_clients_running(client_names, timeout_secs=10)
    • seq.wait_events(target)
    • seq.set_run_description(desc)
  • Run control
    • seq.start_run()
    • seq.stop_run()
    • seq.pause_run()
    • seq.resume_run()
  • ODB access
    • seq.odb_get(path, recurse_dir=True, include_key_metadata=False)
    • seq.odb_set(path, contents) - many optional parameters!
    • seq.odb_exists(path)
    • seq.odb_delete(path, follow_links=False)
    • seq.odb_link(link_path, destination_path)
    • seq.odb_get_link_destination(link_path)
    • seq.odb_rename(current_path, new_name)
    • seq.odb_last_update_time(path)
  • Event buffers
    • ...
  • Controlling other clients
    • seq.start_client()
    • seq.stop_client()
    • seq.get_all_required_program_names()
    • seq.start_all_required_programs()
    • seq.client_exists()
    • seq.clients_exist()
    • seq.connect_to_other_client()
    • seq.disconnect_from_other_client()
    • seq.jrpc_client_call()
    • seq.brpc_client_call()
  • Alarms
    • ...
  • History
    • ...
  • Messages
    • seq.msg(message, is_error=False, facility="midas")
    • ...
  • Misc
    • seq.get_midas_version()
    • seq.get_experiment_dir()
  • Functions that are in MidasClient, but may NOT be used in a sequencer script
    • seq.odb_watch()
    • seq.register_jrpc_callback()
    • seq.register_brpc_callback()