<jupyter_start><jupyter_text>DGL Walkthrough  Message Passing<jupyter_code>import dgl
import dgl.function as fn
import torch
import torch.nn.functional as F

g = dgl.graph(([0, 1, 2, 3], [1, 2, 3, 4]))
g.ndata['x'] = torch.randn(5, 2)

# we can send and receive messages using edge (u --> v)
# we cannot send messages to edges that do not exist, however
g.send_and_recv(([0, 1], [1, 2]), fn.copy_u('x', 'm'), fn.sum('m', 'h'))
g.ndata['h']
# we can send and receive messages using edge ids
g.send_and_recv([0], fn.copy_u('x', 'm'), fn.sum('m', 'h'))
g.ndata['h']
# **local scope**
# we can enter a local scope for a graph such that any mutations in the graph are not 
# reflected in the original graph
g = dgl.graph(([0, 1, 2, 3], [1, 2, 3, 4]))
with g.local_scope():
    g.ndata['x'] = torch.randn(5, 2)
    print(g.ndata)
print(g.ndata)<jupyter_output>{'x': tensor([[ 0.2903, -0.1730],
        [ 0.1695, -0.0738],
        [ 0.6497, -1.1092],
        [ 0.6976, -0.7749],
        [-0.6042,  0.7806]])}
{}
{'fraction_non_alphanumeric': 0.19820717131474103, 'fraction_numerical': 0.07470119521912351, 'mean_word_length': 3.5475113122171944, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '578859', 'license': 'MIT', 'n_tokens_mistral': 457, 'n_tokens_neox': 413, 'n_words': 125, 'path': 'notebooks/annotated_universal_graph_transformer/Untitled.ipynb', 'repo_name': 'jvrana/deep-learning-guides', 'size': '1004'}