Register
- class pulser.register.Register(qubits, **kwargs)
Bases:
BaseRegister
,RegDrawer
A 2D quantum register containing a set of qubits.
- Parameters:
qubits (Mapping[Any, ArrayLike | pm.TensorLike]) – Dictionary with the qubit names as keys and their position coordinates (in μm) as values (e.g. {‘q0’:(2, -1, 0), ‘q1’:(-5, 10, 0), …}).
Attributes
The dimensionality of the coordinates (2 or 3).
The layout used to define the register.
The qubit IDs of this register.
Dictionary of the qubit names and their position coordinates.
The sorted coordinates.
Methods
Returns the idempotent hash of the coordinates.
Defines a DetuningMap for some qubits of the register.
Draws the entire register.
Computes indices of qubits.
Deserialize a register from an abstract JSON object.
Creates the register from an array of coordinates.
Creates the register with the qubits in a hexagonal layout.
Initializes the register with maximum connectivity for a device.
Creates a rectangular array of qubits on a square lattice.
Creates a rectangular array of qubits on a rectangular lattice.
Makes a new rotated register.
Creates the register with the qubits in a square array.
Serializes the register into an abstract JSON object.
Creates the register with the qubits in a triangular lattice.
Replicates the register with an automatically generated layout.
Signatures
- coords_hex_hash()
Returns the idempotent hash of the coordinates.
- Returns:
An hexstring encoding the hash.
- Return type:
str
Note
This hash will be returned as an hexstring without the ‘0x’ prefix (unlike what is returned by ‘hex()’).
- define_detuning_map(detuning_weights, slug=None)
Defines a DetuningMap for some qubits of the register.
- Parameters:
detuning_weights (
Mapping
[str
,float
]) – A mapping between the IDs of the targeted qubits and detuning weights (between 0 and 1).slug (
str
|None
, default:None
) – An optional identifier for the detuning map.
- Return type:
- Returns:
A DetuningMap associating detuning weights to the trap coordinates of the targeted qubits.
- draw(with_labels=True, blockade_radius=None, draw_graph=True, draw_half_radius=False, qubit_colors={}, fig_name=None, kwargs_savefig={}, custom_ax=None, show=True)
Draws the entire register.
- Parameters:
with_labels (
bool
, default:True
) – If True, writes the qubit ID’s next to each qubit.blockade_radius (
float
|None
, default:None
) – The distance (in μm) between atoms below the Rydberg blockade effect occurs.draw_half_radius (
bool
, default:False
) – Whether or not to draw the half the blockade radius surrounding each atoms. If True, requires blockade_radius to be defined.draw_graph (
bool
, default:True
) – Whether or not to draw the interaction between atoms as edges in a graph. Will only draw if the blockade_radius is defined.qubit_colors (
Mapping
[str
,str
], default:{}
) – By default, atoms are drawn with a common default color. If this parameter is present, it replaces the colors for the specified atoms. Non-specified ones are stilled colored with the default value.fig_name (
str
|None
, default:None
) – The name on which to save the figure. If None the figure will not be saved.kwargs_savefig (
dict
, default:{}
) – Keywords arguments formatplotlib.pyplot.savefig
. Not applicable if fig_name isNone
.custom_ax (
Axes
|None
, default:None
) – If present, instead of creating its own Axes object, the function will use the provided one. Warning: if fig_name is set, it may save content beyond what is drawn in this function.show (
bool
, default:True
) – Whether or not to call plt.show() before returning. When combining this plot with other ones in a single figure, one may need to set this flag to False.
- Return type:
None
Note
When drawing half the blockade radius, we say there is a blockade effect between atoms whenever their respective circles overlap. This representation is preferred over drawing the full Rydberg radius because it helps in seeing the interactions between atoms.
- find_indices(id_list)
Computes indices of qubits.
This can especially be useful when building a Pulser Sequence with a parameter denoting qubits.
Example
Let
reg
be a register with qubit Ids “a”, “b” and “c”:>>> reg.find_indices(["a", "b", "c", "a"])
It returns
[0, 1, 2, 0]
, following the qubit order of the register.Then, it is possible to use these indices when building a sequence, typically by assigning them to an array of variables that can be provided as an argument to
target_index
andphase_shift_index
.- Parameters:
id_list (
Sequence
[str
]) – IDs of the qubits to find.- Return type:
list
[int
]- Returns:
Indices of the qubits to denote, only valid for the given mapping.
- static from_abstract_repr(obj_str)
Deserialize a register from an abstract JSON object.
- Parameters:
obj_str (str) – the JSON string representing the register encoded in the abstract JSON format.
- Return type:
- classmethod from_coordinates(coords, center=True, prefix=None, labels=None, **kwargs)
Creates the register from an array of coordinates.
- Parameters:
coords (ArrayLike | pm.TensorLike) – The coordinates of each qubit to include in the register.
center (bool, default:
True
) – Whether or not to center the entire array around the origin.prefix (Optional[str], default:
None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …).labels (Optional[abcSequence[QubitId]], default:
None
) – The list of qubit ids. If defined, each qubit id will be set to the corresponding value.
- Return type:
T
- Returns:
A register with qubits placed on the given coordinates.
- classmethod hexagon(layers, spacing=4.0, prefix=None)
Creates the register with the qubits in a hexagonal layout.
- Parameters:
layers (
int
) – Number of layers around a central atom.spacing (
float
|TensorLike
, default:4.0
) – The distance between neighbouring qubits in μm.prefix (
str
|None
, default:None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …).
- Return type:
- Returns:
A register with qubits placed in a hexagonal layout.
- classmethod max_connectivity(n_qubits, device, spacing=None, prefix=None)
Initializes the register with maximum connectivity for a device.
In order to maximize connectivity, the basic pattern is the triangle. Atoms are first arranged as layers of hexagons around a central atom. Extra atoms are placed in such a manner that C3 and C6 rotational symmetries are enforced as often as possible.
- Parameters:
n_qubits (
int
) – Number of qubits.device (
BaseDevice
) – The device whose constraints must be obeyed.spacing (
float
|TensorLike
|None
, default:None
) – The distance between neighbouring qubits in μm. If omitted, the minimal distance for the device is used.prefix (
str
|None
, default:None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …).
- Return type:
- Returns:
A register with qubits placed for maximum connectivity.
- classmethod rectangle(rows, columns, spacing=4.0, prefix=None)
Creates a rectangular array of qubits on a square lattice.
- Parameters:
rows (
int
) – Number of rows.columns (
int
) – Number of columns.spacing (
float
|TensorLike
, default:4.0
) – The distance between neighbouring qubits in μm.prefix (
str
|None
, default:None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …)
- Return type:
- Returns:
A register with qubits placed in a rectangular array.
- classmethod rectangular_lattice(rows, columns, row_spacing=4.0, col_spacing=2.0, prefix=None)
Creates a rectangular array of qubits on a rectangular lattice.
- Parameters:
rows (
int
) – Number of rows.columns (
int
) – Number of columns.row_spacing (
float
|TensorLike
, default:4.0
) – The distance between rows in μm.col_spacing (
float
|TensorLike
, default:2.0
) – The distance between columns in μm.prefix (
str
|None
, default:None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …)
- Return type:
- Returns:
Register with qubits placed in a rectangular array on a rectangular lattice.
- rotated(degrees)
Makes a new rotated register.
All coordinates are rotated counter-clockwise around the origin.
- Parameters:
degrees (
float
) – The angle of rotation in degrees.- Returns:
A new register rotated around the origin by the given angle.
- Return type:
- classmethod square(side, spacing=4.0, prefix=None)
Creates the register with the qubits in a square array.
- Parameters:
side (
int
) – Side of the square in number of qubits.spacing (
float
|TensorLike
, default:4.0
) – The distance between neighbouring qubits in μm.prefix (
str
|None
, default:None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …).
- Return type:
- Returns:
A register with qubits placed in a square array.
- to_abstract_repr()
Serializes the register into an abstract JSON object.
- Return type:
str
- classmethod triangular_lattice(rows, atoms_per_row, spacing=4.0, prefix=None)
Creates the register with the qubits in a triangular lattice.
Initializes the qubits in a triangular lattice pattern, more specifically a triangular lattice with horizontal rows, meaning the triangles are pointing up and down.
- Parameters:
rows (
int
) – Number of rows.atoms_per_row (
int
) – Number of atoms per row.spacing (
float
|TensorLike
, default:4.0
) – The distance between neighbouring qubits in μm.prefix (
str
|None
, default:None
) – The prefix for the qubit ids. If defined, each qubit id starts with the prefix, followed by an int from 0 to N-1 (e.g. prefix=’q’ -> IDs: ‘q0’, ‘q1’, ‘q2’, …).
- Return type:
- Returns:
A register with qubits placed in a triangular lattice.
- with_automatic_layout(device, layout_slug=None)
Replicates the register with an automatically generated layout.
The generated RegisterLayout can be accessed via Register.layout.
- Parameters:
device (
Device
) – The device constraints for the layout generation.layout_slug (
str
|None
, default:None
) – An optional slug for the generated layout.
- Raises:
RuntimeError – If the automatic layout generation fails to meet the device constraints.
NotImplementedError – When the register has differentiable coordinates (ie torch Tensors with requires_grad=True).
- Returns:
A new register instance with identical qubit IDs and coordinates but also the newly generated RegisterLayout.
- Return type:
- property dimensionality: int
The dimensionality of the coordinates (2 or 3).
- property layout: RegisterLayout | None
The layout used to define the register.
- property qubit_ids: tuple[str, ...]
The qubit IDs of this register.
- property qubits: dict[str, AbstractArray]
Dictionary of the qubit names and their position coordinates.
- property sorted_coords: ndarray
The sorted coordinates.