Skip to content

Result

GeminiLogicalResult dataclass

GeminiLogicalResult(
    *,
    storage: StorageBackend,
    shot_filter: ShotFilter = _default_shot_filter()
)

Bases: Result


              flowchart TD
              bloqade.gemini.device.logical.result.GeminiLogicalResult[GeminiLogicalResult]
              bloqade.core.device.result.Result[Result]

                              bloqade.core.device.result.Result --> bloqade.gemini.device.logical.result.GeminiLogicalResult
                


              click bloqade.gemini.device.logical.result.GeminiLogicalResult href "" "bloqade.gemini.device.logical.result.GeminiLogicalResult"
              click bloqade.core.device.result.Result href "" "bloqade.core.device.result.Result"
            

Result view over stored Gemini logical shots.

Merge-oriented methods assume each selected task ID has the same subtask structure. Post-processing is applied to each selected subtask's flat shot array.

Attributes:

Name Type Description
storage StorageBackend

Storage backend that holds shots and task metadata.

shot_filter ShotFilter

Filter used when reading shots and deriving subtask scope. Defaults to the DETECTED frame type.

logical_results

logical_results(
    verify: bool = True,
    postprocessing_functions: (
        dict[int, Callable[[ndarray], RetType] | None]
        | None
    ) = None,
) -> list[RetType | np.ndarray]

Return logical results grouped by merged subtask.

Parameters:

Name Type Description Default
verify bool

Whether to validate that selected task IDs can be merged before reading shots. Defaults to True.

True
postprocessing_functions dict[int, Callable | None] | None

Optional mapping from program index to post-processing function. When None, functions are built from stored programs. Defaults to None.

None

Returns:

Type Description
list[RetType | ndarray]

list[RetType]: Post-processed results for each merged subtask. If a post-processing function is None, the physical shot array is returned for that subtask.

Raises:

Type Description
ValueError

If verify is True and selected task IDs cannot be merged.

Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/device/logical/result.py
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
def logical_results(
    self,
    verify: bool = True,
    postprocessing_functions: (
        dict[int, Callable[[np.ndarray], RetType] | None] | None
    ) = None,
) -> list[RetType | np.ndarray]:
    """Return logical results grouped by merged subtask.

    Args:
        verify (bool): Whether to validate that selected task IDs can be
            merged before reading shots. Defaults to True.
        postprocessing_functions (dict[int, Callable | None] | None):
            Optional mapping from program index to post-processing function.
            When None, functions are built from stored programs. Defaults
            to None.

    Returns:
        list[RetType]: Post-processed results for each merged subtask.
            If a post-processing function is None, the physical shot array is
            returned for that subtask.

    Raises:
        ValueError: If `verify` is True and selected task IDs cannot be
            merged.
    """
    ret_vals = []
    subtasks = self.subtasks(verify=verify)
    if postprocessing_functions is None:
        postprocessing_functions = self.postprocessing_functions()
    shot_results = self._shot_results_for_subtasks(subtasks)

    for shot_result, subtask in zip(shot_results, subtasks):
        func = postprocessing_functions[subtask["program_index"]]
        if func is None:
            ret_vals.append(shot_result)
        else:
            ret_vals.append(func(shot_result))

    return ret_vals

postprocessing_functions

postprocessing_functions() -> dict[int, Callable | None]

Decode stored programs and build post-processing functions.

Program records are scoped by shot_filter.task_ids. When multiple task IDs share a program_index, the first stored program at that index is used.

Returns:

Type Description
dict[int, Callable | None]

dict[int, Callable | None]: Mapping from program index to its generated post-processing function.

Source code in .venv/lib/python3.12/site-packages/bloqade/gemini/device/logical/result.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def postprocessing_functions(self) -> dict[int, Callable | None]:
    """Decode stored programs and build post-processing functions.

    Program records are scoped by `shot_filter.task_ids`. When multiple
    task IDs share a `program_index`, the first stored program at that index
    is used.

    Returns:
        dict[int, Callable | None]: Mapping from program index to its
            generated post-processing function.
    """
    task_ids = self.shot_filter.task_ids
    programs = self.storage.get_programs(task_ids=task_ids)
    postprocessing_functions = {}
    for program in programs:
        idx = program["program_index"]
        if idx in postprocessing_functions:
            # NOTE: merging across task_ids means we assume all of them identical
            continue
        kernel_json = program["content"]
        kernel_mt = logical.kernel.decode_json(kernel_json)
        postprocessing_function = generate_post_processing(kernel_mt)
        postprocessing_functions[idx] = postprocessing_function

    return postprocessing_functions