Skip to content

processor ¤

Functions:

Name Description
process

processing data

process(raw_data, **kwds) ¤

processing data

Parameters:

Name Type Description Default
raw_data dict

result from devices

required

Returns:

Name Type Description
result dict

processed data in the form of {'key1':np.array,'key2':np.array, ...}

raw_data
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
{'main': {'DAx86_153': {'CH1.Waveform': None},
                        'DAx86_50': {'CH1.Waveform': None},
                        'ADx86_159': {'CH10.CaptureMode': None,
                                      'CH11.CaptureMode': None,
                                      'CH10.StartCapture': None,
                                      'CH11.StartCapture': None}},
 'tigger': {'Trigger': {'CH1.TRIG': None}},
 'READ': {'ADx86_159': {'CH10.IQ': (array([[16.62256833],
                                           ...,
                                           [14.58617952]]),
                                    array([[4.0120324 ],
                                           ...,
                                           [4.97671573]])),
                        'CH11.IQ': (array([[14.6038444],
                                           ...,
                                           [15.33774413]]),
                                    array([[10.76387584],
                                           ...,
                                           [11.23863306]]))}}
}
Source code in quark/runtime/processor.py
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def process(raw_data, **kwds):
    """processing data

    Args:
        raw_data (dict): result from devices

    Returns:
        result (dict): processed data in the form of {'key1':np.array,'key2':np.array, ...}

    Example: raw_data
        ``` {.py3 linenums="1"}
        {'main': {'DAx86_153': {'CH1.Waveform': None},
                                'DAx86_50': {'CH1.Waveform': None},
                                'ADx86_159': {'CH10.CaptureMode': None,
                                              'CH11.CaptureMode': None,
                                              'CH10.StartCapture': None,
                                              'CH11.StartCapture': None}},
         'tigger': {'Trigger': {'CH1.TRIG': None}},
         'READ': {'ADx86_159': {'CH10.IQ': (array([[16.62256833],
                                                   ...,
                                                   [14.58617952]]),
                                            array([[4.0120324 ],
                                                   ...,
                                                   [4.97671573]])),
                                'CH11.IQ': (array([[14.6038444],
                                                   ...,
                                                   [15.33774413]]),
                                            array([[10.76387584],
                                                   ...,
                                                   [11.23863306]]))}}
        }
        ```
    """
    dataMap = kwds.pop('dataMap', {'arch': 'baqis'})

    result = {}

    if kwds.get('mode', 'run') == 'debug':
        return result

    try:

        if 'arch' in dataMap and dataMap['arch'] == 'general':
            return raw_data['READ']['AD']
        elif 'arch' in dataMap and dataMap['arch'] == 'undefined':
            data = flatten_dict(raw_data)
            for k, v in data.items():
                if kwds['signal'] in k:
                    result[kwds['signal']] = v
        else:
            result = Workflow.analyze(raw_data, dataMap)

            for k, v in result.items():
                if isinstance(v, dict):  # k: count or remote_count
                    # v: {(0, 0): 100, (0, 1): 1, (1, 0): 2, (1, 1): 100}
                    base = np.array(tuple(v))
                    count = np.array(tuple(v.values()))
                    # result[k] = np.hstack((base, count[:, None]))
                    nb, nq, shots = *base.shape, kwds.get('shots', 1024)
                    # _k = k.removeprefix('remote_')
                    result[k] = np.zeros((min(2**nq, shots), nq + 1), int) - 1
                    result[k][:nb] = np.hstack((base, count[:, None]))
                else:
                    v = [v] if isinstance(v, (float, int)) else v
                    result[k] = np.asarray(v)
    except Exception as e:
        logger.error(
            f"{'>' * 10} 'Failed to process the result', {e}, {'<' * 10}")
        raise e
        result['error'] = [
            f'Failed to process the result, raise Exception: {e.__class__.__name__}("{str(e)}")',
            raw_data,
            dataMap
        ]

    if kwds.get('inreview', False):
        result.update({'raw': {'data': raw_data, 'dmap': dataMap}})

    return result