Skip to content

Trait

Module for parsing and displaying quantum computing program components using the bloqade library.

Parse

Bases: ParseRegister, ParseSequence, ParseCircuit, ParseRoutine

A composite class inheriting from ParseRegister, ParseSequence, ParseCircuit, and ParseRoutine. Provides a unified interface for parsing different components of the program.

n_atoms property

n_atoms: int

Return the number of atoms in the program.

Returns:

Name Type Description
int int

The number of atoms in the parsed register.

Raises:

Type Description
ValueError

If the register type is unsupported.

Note

If the register is of type ParallelRegister, the number of atoms is extracted from its internal register.

Example:

>>> class MyBuilder(Parse):
...     pass
>>> builder = MyBuilder()
>>> n_atoms = builder.n_atoms

ParseCircuit

A class providing functionality to parse the analog circuit from the program.

Example:

>>> class MyBuilder(ParseCircuit):
...     pass
>>> builder = MyBuilder()
>>> analog_circuit = builder.parse_circuit()

parse_circuit

parse_circuit() -> AnalogCircuit

Parse the analog circuit from the program.

Returns:

Name Type Description
AnalogCircuit AnalogCircuit

The parsed analog circuit.

Raises:

Type Description
ValueError

If the circuit cannot be parsed.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/parse/trait.py
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def parse_circuit(self: "Builder") -> "AnalogCircuit":
    """
    Parse the analog circuit from the program.

    Returns:
        AnalogCircuit: The parsed analog circuit.

    Raises:
        ValueError: If the circuit cannot be parsed.
    """
    from bloqade.analog.builder.parse.builder import Parser

    return Parser().parse_circuit(self)

ParseRegister

A class providing functionality to parse the arrangement of atoms in the program.

Example:

>>> class MyBuilder(ParseRegister):
...     pass
>>> builder = MyBuilder()
>>> atom_arrangement = builder.parse_register()

parse_register

parse_register() -> (
    Union[AtomArrangement, ParallelRegister]
)

Parse the arrangement of atoms in the program.

Returns:

Type Description
Union[AtomArrangement, ParallelRegister]

Union[AtomArrangement, ParallelRegister]: The parsed atom arrangement or parallel register.

Raises:

Type Description
ValueError

If the register cannot be parsed.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/parse/trait.py
31
32
33
34
35
36
37
38
39
40
41
42
43
def parse_register(self: "Builder") -> Union["AtomArrangement", "ParallelRegister"]:
    """
    Parse the arrangement of atoms in the program.

    Returns:
        Union[AtomArrangement, ParallelRegister]: The parsed atom arrangement or parallel register.

    Raises:
        ValueError: If the register cannot be parsed.
    """
    from bloqade.analog.builder.parse.builder import Parser

    return Parser().parse_register(self)

ParseRoutine

A class providing functionality to parse the program and return a Routine object.

Example:

>>> class MyBuilder(ParseRoutine):
...     pass
>>> builder = MyBuilder()
>>> routine = builder.parse()

parse

parse() -> Routine

Parse the program to return a Routine object.

Returns:

Name Type Description
Routine Routine

The parsed routine object.

Raises:

Type Description
ValueError

If the routine cannot be parsed.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/parse/trait.py
118
119
120
121
122
123
124
125
126
127
128
129
130
def parse(self: "Builder") -> "Routine":
    """
    Parse the program to return a Routine object.

    Returns:
        Routine: The parsed routine object.

    Raises:
        ValueError: If the routine cannot be parsed.
    """
    from bloqade.analog.builder.parse.builder import Parser

    return Parser().parse(self)

ParseSequence

A class providing functionality to parse the pulse sequence part of the program.

Example:

>>> class MyBuilder(ParseSequence):
...     pass
>>> builder = MyBuilder()
>>> sequence = builder.parse_sequence()

parse_sequence

parse_sequence() -> Sequence

Parse the pulse sequence part of the program.

Returns:

Name Type Description
Sequence Sequence

The parsed pulse sequence.

Raises:

Type Description
ValueError

If the sequence cannot be parsed.

Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/parse/trait.py
60
61
62
63
64
65
66
67
68
69
70
71
72
def parse_sequence(self: "Builder") -> "Sequence":
    """
    Parse the pulse sequence part of the program.

    Returns:
        Sequence: The parsed pulse sequence.

    Raises:
        ValueError: If the sequence cannot be parsed.
    """
    from bloqade.analog.builder.parse.builder import Parser

    return Parser().parse_sequence(self)

Show

A mixin class providing functionality to display the builder with given arguments and batch ID.

show

show(*args, batch_id: int = 0)

Display the current program being defined with the given arguments and batch ID.

Parameters:

Name Type Description Default
*args

Additional arguments for display.

()
batch_id int

The batch ID to be displayed. Defaults to 0.

0
Note

This method uses the display_builder function to render the builder's state.

Example:

>>> class MyBuilder(Show):
...     pass
>>> builder = MyBuilder()
>>> builder.show()
>>> builder.show(batch_id=1)
>>> builder.show('arg1', 'arg2', batch_id=2)
Source code in .venv/lib/python3.12/site-packages/bloqade/analog/builder/parse/trait.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
def show(self, *args, batch_id: int = 0):
    """
    Display the current program being defined with the given arguments and batch ID.

    Args:
        *args: Additional arguments for display.
        batch_id (int, optional): The batch ID to be displayed. Defaults to 0.

    Note:
        This method uses the `display_builder` function to render the builder's state.

    Example:

    ```python
    >>> class MyBuilder(Show):
    ...     pass
    >>> builder = MyBuilder()
    >>> builder.show()
    >>> builder.show(batch_id=1)
    >>> builder.show('arg1', 'arg2', batch_id=2)
    ```
    """
    display_builder(self, batch_id, *args)