Data
rydberggpt.data
¶
dataclasses
¶
BaseGraph
dataclass
¶
Bases: ABC
A base dataclass representing a graph configuration.
Source code in src/rydberggpt/data/dataclasses.py
Batch
dataclass
¶
GridGraph
dataclass
¶
custom_collate(batch: List[Batch]) -> Batch
¶
Custom collate function to handle Batch objects when creating a DataLoader.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch |
List[Batch]
|
A list of Batch objects to be collated. |
required |
Returns:
Type | Description |
---|---|
Batch
|
A single Batch object containing the collated data. |
Source code in src/rydberggpt/data/dataclasses.py
graph_structures
¶
generate_grid_graph(n_rows: int, n_cols: int) -> nx.Graph
¶
Generates a fully connected grid graph with weights based on the reciprocal of Euclidean distance. Coordinates is in units of lattice constant a.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_rows |
int
|
The number of rows in the grid. |
required |
n_cols |
int
|
The number of columns in the grid. |
required |
Returns:
Type | Description |
---|---|
Graph
|
The generated grid graph with node positions and edge weights. |
Source code in src/rydberggpt/data/graph_structures.py
get_graph(config: BaseGraph) -> nx.Graph
¶
Generates a graph based on the given configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
BaseGraph
|
The graph configuration, an instance of a subclass of the BaseGraph dataclass. |
required |
Returns:
Type | Description |
---|---|
Graph
|
The generated graph based on the configuration. |
Raises:
Type | Description |
---|---|
NotImplementedError
|
If the graph name provided in the configuration is not implemented. |
Source code in src/rydberggpt/data/graph_structures.py
rydberg_dataset
¶
build_datapipes(root_dir: str, batch_size: int, buffer_size: int)
¶
Builds a data pipeline for processing files from a specified directory.
This function initializes a FileLister to list files from the specified directory and its subdirectories. It then demultiplexes the files into three separate data pipes for processing configuration, dataset, and graph files respectively. The configuration and graph files are opened, parsed as JSON, and processed using a custom selection function. The data pipes are then zipped together, shuffled, filtered, and buffered into batches using a custom collate function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_dir |
str
|
The root directory from which to list files. |
required |
batch_size |
int
|
The number of samples per batch. |
required |
buffer_size |
int
|
The buffer size to use when buffering data into batches. |
required |
Returns:
Type | Description |
---|---|
IterDataPipe
|
The final data pipe containing batches of processed data. |
Source code in src/rydberggpt/data/rydberg_dataset.py
utils_graph
¶
batch_pyg_data(data_list: List[Data]) -> Data
¶
Batch a list of PyTorch Geometric Data objects into a single Data object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_list |
List[Data]
|
List of PyTorch Geometric Data objects. |
required |
Returns:
Type | Description |
---|---|
Data
|
A single batched Data object containing all input Data objects. |
Source code in src/rydberggpt/data/utils_graph.py
dict_to_graph(graph_dict: Dict) -> nx.Graph
¶
graph_to_dict(graph: nx.Graph) -> Dict
¶
networkx_to_pyg_data(graph: nx.Graph, node_features: torch.Tensor) -> Data
¶
Convert a NetworkX graph to a PyTorch Geometric Data object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph |
Graph
|
NetworkX graph object. |
required |
Returns:
Type | Description |
---|---|
Data
|
A PyTorch Geometric Data object representing the input graph. |
Source code in src/rydberggpt/data/utils_graph.py
pyg_graph_data(config, graph_data)
¶
Convert a graph in node-link format to a PyG Data object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph_data |
Dict
|
The graph in node-link format. |
required |
config_data |
Dict
|
The configuration data for the graph. |
required |
Returns:
Type | Description |
---|---|
Data
|
The graph as a PyG Data object. |
Source code in src/rydberggpt/data/utils_graph.py
read_graph_from_json(file_path: str) -> Dict
¶
Read a JSON file and convert it to a dictionary representing a NetworkX graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
Path to the JSON file to read. |
required |
Returns:
Type | Description |
---|---|
Dict
|
A dictionary representing a NetworkX graph. |