Conversation
fedebotu
reviewed
May 12, 2026
Member
There was a problem hiding this comment.
Would it make sense to call this positional_encodings.py instead? Or do you think pe is good already?
| return out | ||
|
|
||
|
|
||
| class RotaryPE(nn.Module): |
Member
There was a problem hiding this comment.
General comment: I thik these would be great as documents in the mkdocs too!
| flat_src = src.reshape(-1, src.shape[-1]) | ||
| flat_dst = dst.reshape(-1, dst.shape[-1]) | ||
| flat_w = w.reshape(-1, w.shape[-1]) | ||
| for b in range(flat_adj.shape[0]): |
| "\n", | ||
| "This notebook demonstrates how to *use* and *visualize* every positional encoding (PE) in\n", | ||
| "[`rl4co/utils/pe.py`](../../rl4co/utils/pe.py). It is organized around the three desiderata\n", | ||
| "that the survey/method paper uses to characterize PEs for neural combinatorial optimization\n", |
Member
There was a problem hiding this comment.
Let's add the citations too! 🔝
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a new self-contained module rl4co/utils/pe.py implementing a broad taxonomy of positional encodings (PEs) relevant to Neural Combinatorial Optimization, plus tests and a demonstration notebook.
Motivation and Context
NCO models benefit from positional/structural encodings that respect the geometry of routing problems (closed-tour circularity, multi-route hierarchy, pairwise graph distances). Existing PE code in the repo (rl4co/models/nn/pos_embeddings.py, rl4co/models/nn/ops.py) is tightly coupled to the improvement-policy / env-embedding pipelines. This PR provides a standalone, well-tested library of PE building blocks (classic baselines + proposed IPE/XPE/Hierarchical methods) plus a factory, so they can be reused and composed independently — and a notebook documenting their behavior. Nothing under rl4co/models/** or configs/** is changed; wiring a selected PE into an encoder forward pass is left as a follow-up.
Types of changes
What types of changes does your code introduce? Remove all that do not apply:
Checklist
Go over all the following points, and put an
xin all the boxes that apply.If you are unsure about any of these, don't hesitate to ask. We are here to help!