Skip to content

Analysis

AddressAnalysis

Bases: Forward[Address]


              flowchart TD
              bloqade.analysis.address.analysis.AddressAnalysis[AddressAnalysis]

              

              click bloqade.analysis.address.analysis.AddressAnalysis href "" "bloqade.analysis.address.analysis.AddressAnalysis"
            

This analysis pass can be used to track the global addresses of qubits and wires.

qubit_count property

qubit_count: int

Total number of qubits found by the analysis.

run_lattice

run_lattice(
    callee: Address,
    inputs: tuple[Address, ...],
    keys: tuple[str, ...],
    kwargs: tuple[Address, ...],
) -> Address

Run a callable lattice element with the given inputs and keyword arguments.

Parameters:

Name Type Description Default
callee Address

The lattice element representing the callable.

required
inputs tuple[Address, ...]

The input lattice elements.

required
kwargs tuple[str, ...]

The keyword argument names.

required

Returns:

Name Type Description
Address Address

The resulting lattice element after invoking the callable.

Source code in .venv/lib/python3.12/site-packages/bloqade/analysis/address/analysis.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def run_lattice(
    self,
    callee: Address,
    inputs: tuple[Address, ...],
    keys: tuple[str, ...],
    kwargs: tuple[Address, ...],
) -> Address:
    """Run a callable lattice element with the given inputs and keyword arguments.

    Args:
        callee (Address): The lattice element representing the callable.
        inputs (tuple[Address, ...]): The input lattice elements.
        kwargs (tuple[str, ...]): The keyword argument names.

    Returns:
        Address: The resulting lattice element after invoking the callable.

    """

    match callee:
        case PartialLambda(code=code):
            _, ret = self.call(
                code, callee, *inputs, **{k: v for k, v in zip(keys, kwargs)}
            )
        case ConstResult(const.Value(ir.Method() as method)):
            _, ret = self.call(
                method.code,
                self.method_self(method),
                *inputs,
                **{k: v for k, v in zip(keys, kwargs)},
            )
            return ret
        case _:
            return Address.top()

unpack_iterable

unpack_iterable(iterable: Address)

Extract the values of a container lattice element.

Parameters:

Name Type Description Default
iterable Address

The lattice element representing a container.

required

Returns:

Type Description

A tuple of the container type and the contained values.

Source code in .venv/lib/python3.12/site-packages/bloqade/analysis/address/analysis.py
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 unpack_iterable(self, iterable: Address):
    """Extract the values of a container lattice element.

    Args:
        iterable: The lattice element representing a container.

    Returns:
        A tuple of the container type and the contained values.

    """

    def from_constant(constant: const.Result) -> Address:
        return ConstResult(constant)

    def from_literal(literal: Any) -> Address:
        return ConstResult(const.Value(literal))

    match iterable:
        case PartialIList(data):
            return PartialIList, data
        case PartialTuple(data):
            return PartialTuple, data
        case AddressReg():
            return PartialIList, iterable.qubits
        case ConstResult(const.Value(IList() as data)):
            return PartialIList, tuple(map(from_literal, data))
        case ConstResult(const.Value(tuple() as data)):
            return PartialTuple, tuple(map(from_literal, data))
        case ConstResult(const.PartialTuple(data)):
            return PartialTuple, tuple(map(from_constant, data))
        case _:
            return None, ()