Skip to content

add stream_acquire generator for incremental readout data streaming in addition to acquire#403

Open
gauravag99 wants to merge 3 commits intoopenquantumhardware:mainfrom
gauravag99:add_streaming
Open

add stream_acquire generator for incremental readout data streaming in addition to acquire#403
gauravag99 wants to merge 3 commits intoopenquantumhardware:mainfrom
gauravag99:add_streaming

Conversation

@gauravag99
Copy link
Copy Markdown

@gauravag99 gauravag99 commented Apr 10, 2026

This pull request adds another method stream_acquire() following already existing acquire() and instead of keeping received data in memory, yields it. The main use case is being able to push data directly to persistent storage rather than keeping in memory but also allows live plotting.

Changes: Add stream_acquire() generator method to AcquireMixin class.

The method yields dicts with incremental 'data' events as acquisition progresses (new_points, partial buffers).

Parameters
        ----------
        soc : QickSoc
            Qick object that executes the program
        rounds : int, optional
            Number of times to rerun the program, averaging results in software (aka "soft averages"). 
            Default is 1.
        load_envelopes : bool, optional
            If True, load pulse envelopes before executing. Default is True.
        start_src : str, optional
            Start source for the tProc. Can be "internal" (tProc starts immediately) or "external" 
            (each round waits for an external trigger). Default is "internal".
        progress : bool, optional
            If True, display progress bars for rounds and shots per round. Default is True.
        remove_offset : bool, optional
            If True, subtract the readout's IQ offset from the partial channel data. Default is True.
        len_normalize : bool, optional
            If True, normalize partial channel data by dividing by the readout window length. 
            Default is True.
        include_full : bool, optional
            If True, include the current state of full buffers in each 'data' event. Default is False.
        return_end_of_exp_raw : bool, optional
            If True, yield a final event with all rounds' raw buffer data. Default is False.

        Yields
        ------
        dict
            Event dictionaries describing acquisition progress. Possible event forms:
            
            - 'data' event: {'event': 'data', 'round': r, 'rep_slice': (start, stop),
              'partial': {ch: ndarray(new_points, nreads, 2)},
              'buffers': {ch: ndarray(*loop_dims, nreads, 2)} (optional)}
            
            - 'round-complete' event: {'event': 'round-complete', 'round': r, 
              'round_raw': [buffer_per_ch]}
            
            - 'complete' event: {'event': 'complete', 'rounds_raw': list_of_round_buffers}
        
        Returns
        -------
        None
            StopIteration value is None when all rounds complete.

The rep_slice refers to point number in total points to be collected and is calculated from the loops defined in the AveragerProgramV2.

The way to use it is:

tof = T1_Program(soccfg, cfg, final_delay, reps)
data = tof.stream_acquire(QP_cfg.soc, rounds=1)

for i in data:
    print(i.keys())
    print(i['event'])

one can re-construct easily the rep numbers and loop numbers and put together the data using methods like prog.loop_dict, prog.get_pulse_param etc to get loop_values.

@meeg
Copy link
Copy Markdown
Contributor

meeg commented Apr 10, 2026

Nice, thanks! At first glance this looks good. I'll review and merge next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants