Skip to content

Register

Quantum Registers

Register(support, spacing=1.0, device_specs=DEFAULT_DEVICE)

A 2D register of qubits which includes their coordinates.

It is needed for e.g. analog computing. The coordinates are ignored in backends that don't need them. The easiest way to construct a register is via its classmethods like Register.triangular_lattice.

PARAMETER DESCRIPTION
support

A graph or number of qubits. Nodes can include a "pos" attribute such that e.g.: graph.nodes = {0: {"pos": (2,3)}, 1: {"pos": (0,0)}, ...} which will be used in backends that need qubit coordinates. See the classmethods for simple construction of some predefined lattices if you don't want to build a graph manually. If you pass an integer the resulting register is the same as Register.all_to_all(n_qubits).

TYPE: Graph | int

spacing

Value set as the distance between the two closest qubits.

TYPE: float | None DEFAULT: 1.0

Examples:

from qadence import Register

reg = Register.honeycomb_lattice(2,3)
reg.draw()

Source code in qadence/register.py
def __init__(
    self,
    support: nx.Graph | int,
    spacing: float | None = 1.0,
    device_specs: RydbergDevice = DEFAULT_DEVICE,
):
    """
    A 2D register of qubits which includes their coordinates.

    It is needed for e.g. analog computing.
    The coordinates are ignored in backends that don't need them. The easiest
    way to construct a register is via its classmethods like `Register.triangular_lattice`.

    Arguments:
        support: A graph or number of qubits. Nodes can include a `"pos"` attribute
            such that e.g.: `graph.nodes = {0: {"pos": (2,3)}, 1: {"pos": (0,0)}, ...}` which
            will be used in backends that need qubit coordinates.
            See the classmethods for simple construction of some predefined lattices if you
            don't want to build a graph manually.
            If you pass an integer the resulting register is the same as
            `Register.all_to_all(n_qubits)`.
        spacing: Value set as the distance between the two closest qubits.

    Examples:
    ```python exec="on" source="material-block" result="json"
    from qadence import Register

    reg = Register.honeycomb_lattice(2,3)
    reg.draw()
    ```
    """
    if device_specs is not None and not isinstance(device_specs, RydbergDevice):
        raise ValueError("Device specs are not valid. Please pass a `RydbergDevice` instance.")

    self.device_specs = device_specs

    self.graph = support if isinstance(support, nx.Graph) else alltoall_graph(support)

    if spacing is not None and self.min_distance != 0.0:
        _scale_node_positions(self.graph, self.min_distance, spacing)

line_graph(n_qubits)

Create graph representing linear lattice.

PARAMETER DESCRIPTION
n_qubits

number of nodes in the graph

TYPE: int

RETURNS DESCRIPTION
Graph

graph instance

Source code in qadence/register.py
def line_graph(n_qubits: int) -> nx.Graph:
    """Create graph representing linear lattice.

    Args:
        n_qubits (int): number of nodes in the graph

    Returns:
        graph instance
    """
    graph = nx.Graph()
    for i in range(n_qubits):
        graph.add_node(i, pos=(i, 0.0))
    for i, j in zip(range(n_qubits - 1), range(1, n_qubits)):
        graph.add_edge(i, j)
    return graph