Skip to content
Pasqal Documentation

Quantum registers

In Qadence, quantum programs can be executed by specifying the layout of a register of resources as a lattice. Built-in Register types can be used or constructed for arbitrary topologies. Common register topologies are available and illustrated in the plot below.

2025-06-04T09:56:49.516742 image/svg+xml Matplotlib v3.10.3, https://matplotlib.org/

Built-in topologies are directly accessible in the Register methods:

from qadence import Register
reg = Register.all_to_all(n_qubits = 4)
reg_line = Register.line(n_qubits = 4)
reg_circle = Register.circle(n_qubits = 4)
reg_squre = Register.square(qubits_side = 2)
reg_rect = Register.rectangular_lattice(qubits_row = 2, qubits_col = 2)
reg_triang = Register.triangular_lattice(n_cells_row = 2, n_cells_col = 2)
reg_honey = Register.honeycomb_lattice(n_cells_row = 2, n_cells_col = 2)

The Register class builds on top of the NetworkX Graph, and the graphs can be visualized with the reg.draw() method

Qubit coordinates are saved as node properties in the underlying NetworkX graph, but can be accessed directly with the coords property.

reg = Register.square(2)
print(reg.coords)
{0: (0.5, -0.5), 1: (0.5, 0.5), 2: (-0.5, 0.5), 3: (-0.5, -0.5)}
spacingrescale_coords
scaled_reg_1 = Register.square(2, spacing = 4.0)
scaled_reg_2 = reg.rescale_coords(scaling = 4.0)
print(scaled_reg_1.coords)
print(scaled_reg_2.coords)
{0: (2.0, -2.0), 1: (2.0, 2.0), 2: (-2.0, 2.0), 3: (-2.0, -2.0)}
{0: (2.0, -2.0), 1: (2.0, 2.0), 2: (-2.0, 2.0), 3: (-2.0, -2.0)}

The distance between qubits can also be directly accessed with the distances and edge_distances properties.

print(reg.distances)
print(reg.edge_distances)
Distance between all qubit pairs:
{(0, 1): 1.0, (0, 2): 1.4142135623730951, (0, 3): 1.0, (1, 2): 1.0, (1, 3): 1.4142135623730951, (2, 3): 1.0}
Distance between qubits connect by an edge in the graph
{(0, 1): 1.0, (0, 3): 1.0, (1, 2): 1.0, (2, 3): 1.0}

By calling the Register directly, either the number of nodes or a specific graph can be given as input. If passing a custom graph directly, the node positions will not be defined automatically, and should be previously saved in the "pos" node property. If not, reg.coords will return empty tuples and all distances will be 0.

import networkx as nx
# Same as Register.all_to_all(n_qubits = 2):
reg = Register(2)
# Register from a custom graph:
graph = nx.complete_graph(3)
# Set node positions, in this case a simple line:
for i, node in enumerate(graph.nodes):
graph.nodes[node]["pos"] = (1.0 * i, 0.0)
reg = Register(graph)
print(reg.distances)
{(0, 1): 1.0, (0, 2): 2.0, (1, 2): 1.0}

Alternatively, arbitrarily shaped registers can also be constructed by providing the node coordinates. In this case, there will be no edges automatically created in the connectivity graph.

import numpy as np
from qadence import Register, PI
reg = Register.from_coordinates(
[(x, np.sin(x)) for x in np.linspace(0, 2*PI, 10)]
)
reg.draw(show=False)
2025-06-04T09:56:49.728696 image/svg+xml Matplotlib v3.10.3, https://matplotlib.org/

Register topology is often assumed in digital simulations to be an all-to-all qubit connectivity. When running on real devices that enable the digital-analog computing paradigm, qubit interactions must be specified either by specifying distances between qubits, or by defining edges in the register connectivity graph.

The abstract graph nodes and edges are accessible for direct usage.

from qadence import Register
reg = Register.rectangular_lattice(2,3)
reg.nodes = NodeView((0, 1, 2, 3, 4, 5))
reg.edges = EdgeView([(0, 2), (0, 1), (1, 3), (2, 4), (2, 3), (3, 5), (4, 5)])

There is also an all_node_pairs property for convenience:

print(reg.all_node_pairs)
[(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 2), (1, 3), (1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)]

More details about the usage of Register types in the digital-analog paradigm can be found in the digital-analog basics section.