Skip to content

qek.data.graphs

source module qek.data.graphs

Loading graphs as raw data.

Attributes

  • EPSILON_RADIUS_UM Assumption of rounding error when determining whether a graph is a disk graph.

  • EPSILON_RESCALE_FACTOR A correction factor, attempting to cover for rounding error when rescaling a graph.

Classes

source class BaseGraph(id: int, data: pyg_data.Data, device: pl.devices.Device, target: int | None = None)

A graph being prepared for embedding on a quantum device.

Create a graph from geometric data.

Parameters

  • id : int An identifier for this graph, used mostly for error messages.

  • data : pyg_data.Data A homogeneous graph, in PyTorch Geometric format. Unchanged. It MUST have attributes 'pos'.

  • device : pl.devices.Device The device for which the graph is prepared.

Methods

  • is_disk_graph A predicate to check if self is a disk graph with the specified radius, i.e. self is a connected graph and, for every pair of nodes A and B within graph, there exists an edge between A and B if and only if the positions of A and B within self are such that |AB| <= radius.

  • is_embeddable A predicate to check if the graph can be embedded in the quantum device.

  • compile_register Create a Quantum Register based on a graph.

  • compile_pulse Extract a Pulse for this graph.

source method BaseGraph.is_disk_graph(radius: float)bool

A predicate to check if self is a disk graph with the specified radius, i.e. self is a connected graph and, for every pair of nodes A and B within graph, there exists an edge between A and B if and only if the positions of A and B within self are such that |AB| <= radius.

Parameters

  • radius : float The maximal distance between two nodes of self connected be an edge.

Returns

  • bool True if the graph is a disk graph with the specified radius, False otherwise.

source method BaseGraph.is_embeddable()bool

A predicate to check if the graph can be embedded in the
quantum device.

For a graph to be embeddable on a device, all the following
criteria must be fulfilled:
- the graph must be non-empty;
- the device must have at least as many atoms as the graph has
    nodes;
- the device must be physically large enough to place all the
    nodes (device.max_radial_distance);
- the nodes must be distant enough that quantum interactions
    may take place (device.min_atom_distance)

Returns

  • bool True if possible, False if not

source method BaseGraph.compile_register()targets.Register

Create a Quantum Register based on a graph.

Returns

  • pulser.Register register

Raises

source method BaseGraph.compile_pulse(normalized_amplitude: float | None = None, normalized_duration: float | None = None)targets.Pulse

Extract a Pulse for this graph.

A Pulse represents the laser applied to the atoms on the device.

Parameters

  • normalized_amplitude : optional The normalized amplitude for the laser pulse, as a value in [0, 1], where 0 is no pulse and 1 is the maximal amplitude for the device. By default, use the value demonstrated in the companion paper.

  • normalized_duration : optional The normalized duration of the laser pulse, as a value in [0, 1], where 0 is the shortest possible duration and 1 is the longest possible duration. By default, use the value demonstrated in the companion paper.

Raises

  • ValueError

source class MoleculeGraph(id: Any, data: pyg_data.Data, device: pl.devices.Device, node_mapping: dict[int, str], edge_mapping: dict[int, Chem.BondType], target: int | None = None)

Bases : BaseGraph

A graph based on molecular data, being prepared for embedding on a quantum device.

Compute the geometry for a molecule graph.

Parameters

  • data : pyg_data.Data A homogeneous graph, in PyTorch Geometric format. Unchanged.

  • blockade_radius The radius of the Rydberg Blockade. Two connected nodes should be at a distance < blockade_radius, while two disconnected nodes should be at a distance > blockade_radius.

  • node_mapping : dict[int, str] A mapping of node labels from numbers to strings, e.g. 5 => "Cl". Used when building molecules, e.g. to compute distances between nodes.

  • edge_mapping : dict[int, Chem.BondType] A mapping of edge labels from number to chemical bond types, e.g. 2 => DOUBLE. Used when building molecules, e.g. to compute distances between nodes.

  • target : int | None If specified, a target for machine learning, as a value 0 or 1.

source class PTCFMGraph(id: Any, data: pyg_data.Data, device: pl.devices.Device)

Bases : MoleculeGraph

An ingester for molecule graphs using PTC-FM dataset conventions.

Compute the geometry for a molecule graph.

Parameters

  • data : pyg_data.Data A homogeneous graph, in PyTorch Geometric format. Unchanged.

  • blockade_radius The radius of the Rydberg Blockade. Two connected nodes should be at a distance < blockade_radius, while two disconnected nodes should be at a distance > blockade_radius.

  • node_mapping A mapping of node labels from numbers to strings, e.g. 5 => "Cl". Used when building molecules, e.g. to compute distances between nodes.

  • edge_mapping A mapping of edge labels from number to chemical bond types, e.g. 2 => DOUBLE. Used when building molecules, e.g. to compute distances between nodes.

  • target If specified, a target for machine learning, as a value 0 or 1.

source class BaseGraphCompiler()

Bases : abc.ABC, Generic[GraphType]

Abstract class, used to load a graph and compile a Pulser sequence for a device.

You should probably use one of the subclasses.

Methods

source method BaseGraphCompiler.ingest(graph: GraphType, device: pl.devices.Device, id: int)BaseGraph

Raises

  • Exception

source class PygWithPosCompiler()

Bases : BaseGraphCompiler[pyg_data.Data]

A compiler able to ingest torch_geometric graphs with positions.

Methods

  • ingest Compile a Pulser sequence from a torch_geometric graph with position.

source method PygWithPosCompiler.ingest(graph: pyg_data.Data, device: pl.devices.Device, id: int)BaseGraph

Compile a Pulser sequence from a torch_geometric graph with position.

Parameters

  • graph : pyg_data.Data A graph with positions (specified as attribute pos) and optionally a prediction target (specified as attribute y, which must be an int). The graph will not be changed.

  • device : pl.devices.Device The device for which the sequence must be compiled.

  • id : int A unique identifier for the graph, used mostly for logging and displaying error messages.

source class MoleculeGraphCompiler(node_mapping: dict[int, str], edge_mapping: dict[int, Chem.BondType])

Bases : BaseGraphCompiler[tuple[pyg_data.Data, int | None]]

A compiler able to ingest torch_geometric molecules with a target.

Setup a molecule graph compiler.

Parameters

  • node_mapping : dict[int, str] A mapping from node labels (as integers) to atom names (e.g. "C", "Ar", ...).

  • edge_mapping : dict[int, Chem.BondType] A mapping from node labels (as integers) to chemical bond types (e.g. simple bound, double bound).

Methods

source method MoleculeGraphCompiler.ingest(graph: tuple[pyg_data.Data, int | None], device: pl.devices.Device, id: int)MoleculeGraph

source class PTCFMCompiler()

Bases : BaseGraphCompiler[pyg_data.Data]

Methods

source method PTCFMCompiler.ingest(graph: pyg_data.Data, device: pl.devices.Device, id: int)PTCFMGraph

source dataclass NXWithPos(graph: nx.Graph, positions: dict[Any, np.ndarray], target: int | None)

A networkx graph and its position

source class NXGraphCompiler()

source method NXGraphCompiler.ingest(graph: NXWithPos, device: pl.devices.Device, id: int)BaseGraph