Skip to content

Results are limited to Quantum Evolution Kernel v0.2.9

Product news
You are reading Quantum Evolution Kernel v0.2.9, an older version of this documentation. Go to the latest version (v0.3.4)

qek.data.graphs

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

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.

method
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.

method
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

method
compile_register () → pl.Register

Create a Quantum Register based on a graph.

Returns

  • pulser.Register — register

Raises

method
compile_pulse (amplitude: float = SEQUENCE_DEFAULT_AMPLITUDE_RAD_PER_US, duration: int = SEQUENCE_DEFAULT_DURATION_NS) → pl.Pulse

Extract a Pulse for this graph.

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

Parameters

  • amplitude : float — The amplitude for the laser pulse, in rad per microseconds. By default, use the value demonstrated in the companion paper.

  • duration : int — The duration of the laser pulse, in nanoseconds. By default, use the value demonstrated in the companion paper.

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.

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.

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

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

Raises

  • Exception

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.

method
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.

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

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

class
PTCFMCompiler ()

Bases : BaseGraphCompiler[pyg_data.Data]

Methods

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

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

A networkx graph and its position

class
NXGraphCompiler ()

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