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.
Building and drawing registers
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.
spacing
argument can be used to set the minimum spacing. The rescale_coords
method can be used to create
a new register by rescaling the coordinates of an already created register.
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)
The distance between qubits can also be directly accessed with the distances
and edge_distances
properties.
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)
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)
Units for qubit coordinates
In general, Qadence makes no assumption about the units for qubit coordinates and distances. However, if used in the context of a Hamiltonian coefficient, care should be taken by the user to guarantee the quantity \(H.t\) is dimensionless for exponentiation in the PyQTorch backend, where it is assumed that \(\hbar = 1\). For registers passed to the Pulser backend, coordinates are in \(\mu \textrm{m}\).
Connectivity graphs
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.
There is also an all_node_pairs
property for convenience:
More details about the usage of Register
types in the digital-analog paradigm can be found in the digital-analog basics section.