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

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()

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 src/bloqade/builder/parse/trait.py
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.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()

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 src/bloqade/builder/parse/trait.py
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.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()

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 src/bloqade/builder/parse/trait.py
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.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()

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 src/bloqade/builder/parse/trait.py
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.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=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 src/bloqade/builder/parse/trait.py
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)