Environments
EnvParams
Bases: _StructBase
Dataclass to hold environment parameters. Parameters are immutable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_requests
|
Scalar
|
Maximum number of requests in an episode |
required |
incremental_loading
|
Scalar
|
Incremental increase in traffic load (non-expiring requests) |
required |
end_first_blocking
|
Scalar
|
End episode on first blocking event |
required |
continuous_operation
|
Scalar
|
If True, do not reset the environment at the end of an episode |
required |
edges
|
Array
|
Two column array defining source-dest node-pair edges of the graph |
required |
slot_size
|
Scalar
|
Spectral width of frequency slot in GHz |
required |
consider_modulation_format
|
Scalar
|
If True, consider modulation format to determine required slots |
required |
link_length_array
|
Array
|
Array of link lengths |
required |
aggregate_slots
|
Scalar
|
Number of slots to aggregate into a single action (First-Fit with aggregation) |
required |
guardband
|
Scalar
|
Guard band in slots |
required |
directed_graph
|
bool
|
Whether graph is directed (one fibre per link per transmission direction) |
required |
temperature
|
Scalar
|
Temp. used for softmax differentiable approximation |
required |
window_size
|
Scalar
|
Window size for weighted average of neighbouring cells in differentiable indexing |
required |
Source code in xlron/environments/dataclasses.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
EnvState
Bases: _StructBase
Dataclass to hold environment state. State is mutable and arrays are traced on JIT compilation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
Scalar
|
Current time in environment |
required |
holding_time
|
Scalar
|
Holding time of current request |
required |
total_timesteps
|
Scalar
|
Total timesteps in environment |
required |
total_requests
|
Scalar
|
Total requests in environment |
required |
graph
|
GraphsTuple
|
Graph tuple representing network state |
required |
full_link_slot_mask
|
Array
|
Action mask for link slot action (including if slot actions are aggregated) |
required |
accepted_services
|
Array
|
Number of accepted services |
required |
accepted_bitrate
|
Array
|
Accepted bitrate |
required |
arrival_rate
|
Scalar
|
Arrival rate (load / mean_service_holding_time), traced for recompilation-free load sweeps |
required |
mean_service_holding_time
|
Scalar
|
Mean service holding time, traced for recompilation-free load sweeps |
required |
Source code in xlron/environments/dataclasses.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
RSAMultibandEnvParams
Bases: RSAEnvParams
Dataclass to hold environment parameters for MultiBandRSA (RBSA).
Source code in xlron/environments/dataclasses.py
464 465 466 467 468 469 | |
RSAMultibandEnvState
Bases: RSAEnvState
Dataclass to hold environment state for MultiBandRSA (RBSA).
Source code in xlron/environments/dataclasses.py
457 458 459 460 461 | |
Dataclasses
DeepRMSAEnvState
Bases: RSAEnvState
Dataclass to hold environment state for DeepRMSA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_stats
|
Array
|
Path stats array containing |
required |
Source code in xlron/environments/dataclasses.py
227 228 229 230 231 232 233 234 235 236 237 238 239 | |
EnvParams
Bases: _StructBase
Dataclass to hold environment parameters. Parameters are immutable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_requests
|
Scalar
|
Maximum number of requests in an episode |
required |
incremental_loading
|
Scalar
|
Incremental increase in traffic load (non-expiring requests) |
required |
end_first_blocking
|
Scalar
|
End episode on first blocking event |
required |
continuous_operation
|
Scalar
|
If True, do not reset the environment at the end of an episode |
required |
edges
|
Array
|
Two column array defining source-dest node-pair edges of the graph |
required |
slot_size
|
Scalar
|
Spectral width of frequency slot in GHz |
required |
consider_modulation_format
|
Scalar
|
If True, consider modulation format to determine required slots |
required |
link_length_array
|
Array
|
Array of link lengths |
required |
aggregate_slots
|
Scalar
|
Number of slots to aggregate into a single action (First-Fit with aggregation) |
required |
guardband
|
Scalar
|
Guard band in slots |
required |
directed_graph
|
bool
|
Whether graph is directed (one fibre per link per transmission direction) |
required |
temperature
|
Scalar
|
Temp. used for softmax differentiable approximation |
required |
window_size
|
Scalar
|
Window size for weighted average of neighbouring cells in differentiable indexing |
required |
Source code in xlron/environments/dataclasses.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
EnvState
Bases: _StructBase
Dataclass to hold environment state. State is mutable and arrays are traced on JIT compilation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_time
|
Scalar
|
Current time in environment |
required |
holding_time
|
Scalar
|
Holding time of current request |
required |
total_timesteps
|
Scalar
|
Total timesteps in environment |
required |
total_requests
|
Scalar
|
Total requests in environment |
required |
graph
|
GraphsTuple
|
Graph tuple representing network state |
required |
full_link_slot_mask
|
Array
|
Action mask for link slot action (including if slot actions are aggregated) |
required |
accepted_services
|
Array
|
Number of accepted services |
required |
accepted_bitrate
|
Array
|
Accepted bitrate |
required |
arrival_rate
|
Scalar
|
Arrival rate (load / mean_service_holding_time), traced for recompilation-free load sweeps |
required |
mean_service_holding_time
|
Scalar
|
Mean service holding time, traced for recompilation-free load sweeps |
required |
Source code in xlron/environments/dataclasses.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
GNModelEnvParams
Bases: RSAEnvParams
Dataclass to hold environment state for GN model environments.
Source code in xlron/environments/dataclasses.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
GNModelEnvState
Bases: RSAEnvState
Dataclass to hold environment state for RSA with GN model.
The blocked_* fields count blocked requests by cause (cumulative within an episode, like accepted_services). Causes are attributed with spectrum > SNR > power priority, so the counters are mutually exclusive and sum to the total number of blocked requests.
Source code in xlron/environments/dataclasses.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
LogEnvState
Dataclass to hold environment state for logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env_state
|
EnvState
|
Environment state |
required |
lengths
|
Scalar
|
Lengths |
required |
returns
|
Scalar
|
Returns |
required |
cum_returns
|
Scalar
|
Cumulative returns |
required |
accepted_services
|
Scalar
|
Accepted services |
required |
accepted_bitrate
|
Scalar
|
Accepted bitrate |
required |
total_bitrate
|
Scalar
|
Total bitrate requested |
required |
utilisation
|
Scalar
|
Network utilisation |
required |
fragmentation
|
Scalar
|
Mean external spectrum fragmentation across links |
required |
blocked_spectrum
|
Scalar
|
Requests blocked by spectrum contention (GN-model envs, else 0) |
required |
blocked_snr
|
Scalar
|
Requests blocked by insufficient SNR (GN-model envs, else 0) |
required |
blocked_power
|
Scalar
|
Requests blocked by the per-fibre power budget (GN-model envs, else 0) |
required |
terminal
|
Scalar
|
Terminal flag (true termination condition met) |
required |
truncated
|
Scalar
|
Truncated flag (max steps reached) |
required |
Source code in xlron/environments/dataclasses.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
MultiBandRSAEnvParams
Bases: RSAEnvParams
Dataclass to hold environment parameters for MultiBandRSA (RBSA).
Source code in xlron/environments/dataclasses.py
276 277 278 279 280 281 | |
MultiBandRSAEnvState
Bases: RSAEnvState
Dataclass to hold environment state for MultiBandRSA (RBSA).
Source code in xlron/environments/dataclasses.py
269 270 271 272 273 | |
RMSAGNModelEnvParams
Bases: GNModelEnvParams
Dataclass to hold environment params for RMSA with GN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_snr_array
|
Array
|
Link SNR array |
required |
Source code in xlron/environments/dataclasses.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
RMSAGNModelEnvState
Bases: GNModelEnvState
Dataclass to hold environment state for RMSA with GN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_snr_array
|
Array
|
Link SNR array |
required |
Source code in xlron/environments/dataclasses.py
442 443 444 445 446 447 448 449 450 451 452 453 454 | |
RSAEnvParams
Bases: EnvParams
Dataclass to hold environment parameters for RSA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
Scalar
|
Number of nodes |
required |
num_links
|
Scalar
|
Number of links |
required |
link_resources
|
Scalar
|
Number of link resources |
required |
k_paths
|
Scalar
|
Number of paths |
required |
mean_service_holding_time
|
Scalar
|
Mean service holding time |
required |
load
|
Scalar
|
Load |
required |
arrival_rate
|
Scalar
|
Arrival rate |
required |
path_link_array
|
Array
|
Path link array |
required |
random_traffic
|
bool
|
Random traffic matrix for RSA on each reset (else uniform or custom) |
required |
max_slots
|
Scalar
|
Maximum number of slots |
required |
path_se_array
|
Array
|
Path spectral efficiency array |
required |
deterministic_requests
|
bool
|
If True, use deterministic requests |
required |
multiple_topologies
|
bool
|
If True, use multiple topologies |
required |
mscl_interfering_k
|
int
|
Stored routes per node pair in the interfering route set of the multi-route MSCL heuristics (0 = all k paths) |
required |
arbr_alpha
|
float
|
Tuning parameter alpha of the ARBR heuristic (0 = static cost only, 1 = dynamic utilisation only) |
required |
Source code in xlron/environments/dataclasses.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
RSAEnvState
Bases: EnvState
Dataclass to hold environment state for RSA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_slot_array
|
Array
|
Link slot array |
required |
request_array
|
Array
|
Request array |
required |
link_slot_departure_array
|
Array
|
Link slot departure array |
required |
link_slot_mask
|
Array
|
Link slot mask |
required |
traffic_matrix
|
Array
|
Traffic matrix |
required |
Source code in xlron/environments/dataclasses.py
177 178 179 180 181 182 183 184 185 186 187 188 189 | |
RSAGNModelEnvParams
Bases: GNModelEnvParams
Dataclass to hold environment params for RSA with GN model.
Source code in xlron/environments/dataclasses.py
393 394 395 396 397 398 | |
RSAGNModelEnvState
Bases: GNModelEnvState
Dataclass to hold environment state for RSA with GN model.
Source code in xlron/environments/dataclasses.py
401 402 403 404 405 406 407 | |
RSAMultibandEnvParams
Bases: RSAEnvParams
Dataclass to hold environment parameters for MultiBandRSA (RBSA).
Source code in xlron/environments/dataclasses.py
464 465 466 467 468 469 | |
RSAMultibandEnvState
Bases: RSAEnvState
Dataclass to hold environment state for MultiBandRSA (RBSA).
Source code in xlron/environments/dataclasses.py
457 458 459 460 461 | |
RWALightpathReuseEnvState
Bases: RSAEnvState
Dataclass to hold environment state for RWA with lightpath reuse.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_index_array
|
Array
|
Contains indices of lightpaths in use on slots |
required |
path_capacity_array
|
Array
|
Contains remaining capacity of each lightpath |
required |
link_capacity_array
|
Array
|
Contains remaining capacity of lightpath on each link-slot |
required |
Source code in xlron/environments/dataclasses.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
VONEEnvParams
Bases: RSAEnvParams
Dataclass to hold environment parameters for VONE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_resources
|
Scalar
|
Number of node resources |
required |
max_edges
|
Scalar
|
Maximum number of edges |
required |
min_node_resources
|
Scalar
|
Minimum number of node resources |
required |
max_node_resources
|
Scalar
|
Maximum number of node resources |
required |
Source code in xlron/environments/dataclasses.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
VONEEnvState
Bases: RSAEnvState
Dataclass to hold environment state for VONE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_capacity_array
|
Array
|
Node capacity array |
required |
node_resource_array
|
Array
|
Node resource array |
required |
node_departure_array
|
Array
|
Node departure array |
required |
action_counter
|
Array
|
Action counter |
required |
action_history
|
Array
|
Action history |
required |
node_mask_s
|
Array
|
Node mask for source node |
required |
node_mask_d
|
Array
|
Node mask for destination node |
required |
virtual_topology_patterns
|
Array
|
Virtual topology patterns |
required |
values_nodes
|
Array
|
Values for nodes |
required |
Source code in xlron/environments/dataclasses.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 | |
Environment wrappers
JitProfiler
Wall-clock profiler for JAX JIT-compiled code.
On CPU
• Uses host callbacks for fine-grained section timing.
On GPU
• Automatically switches to first-call-only timing. • Measures compilation + first execution latency. • Fine-grained per-call timings are intentionally disabled to avoid misleading synchronization artifacts.
This profiler records host-side timestamps using jax.debug.callback,
allowing coarse wall-clock profiling of sections inside JIT-compiled code.
Profiling is designed to be gated by a static Python boolean (e.g.
params.profile) so that all profiling logic is resolved at trace time and
introduces zero runtime overhead when disabled.
Features
• Manual markers via mark(), start(), and end()
• Function-level profiling via call()
• Automatic jax.named_scope integration for clearer JAX traces
• Safety checks to ensure the profiling flag is static at trace time
• Aggregation across repeated calls with a readable summary table
Basic usage inside JIT (manual markers):
if params.profile:
jit_profiler.mark("process_action:start")
with jax.named_scope("process_action"):
...
if params.profile:
jit_profiler.mark("process_action:end")
Function-wrapping usage inside JIT (recommended):
action_mask = jit_profiler.call(
params.profile,
mask_slots,
state,
params,
name="mask_actions", # optional, defaults to fn.__name__
)
Block-style usage inside JIT:
jit_profiler.start(params.profile, "action_logic")
...
jit_profiler.end(params.profile, "action_logic")
Notes
• The enabled flag must be a Python bool known at trace time
(e.g. params.profile with pytree_node=False).
• Passing a traced or JAX boolean will raise a TypeError.
• All timing is wall-clock time measured on the host, not device time.
After execution (outside JIT):
jit_profiler.summary()
Source code in xlron/environments/wrappers.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
call(enabled, fn, *args, name=None, **kwargs)
Profile a function call inside JIT-compiled code.
CPU
Fine-grained section timing via callbacks.
GPU
Records only first-call (compile + first execution) latency.
Source code in xlron/environments/wrappers.py
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
end(enabled, name)
Insert an end marker for a block.
Source code in xlron/environments/wrappers.py
436 437 438 439 440 | |
mark(label)
Insert a timing marker. Safe to call inside JIT.
Source code in xlron/environments/wrappers.py
421 422 423 | |
reset()
Clear all recorded timestamps and first-call tracking.
Source code in xlron/environments/wrappers.py
425 426 427 428 | |
start(enabled, name)
Insert a start marker for a block.
Source code in xlron/environments/wrappers.py
430 431 432 433 434 | |
summary()
Print timing breakdown from collected start/end marker pairs.
Expects markers in the format "name:start" and "name:end". Aggregates across repeated calls (e.g. many step_env invocations).
Also reports GPU :first entries if present.
Source code in xlron/environments/wrappers.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | |
LogWrapper
Bases: GymnaxWrapper
Log the episode returns and lengths. Modified from: https://github.com/RobertTLange/gymnax/blob/master/gymnax/wrappers/purerl.py
Source code in xlron/environments/wrappers.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
Profiler
Simple wall-clock profiler that tracks named sections.
Usage
profiler = Profiler()
with profiler.section("compilation"): ...
for i in range(10): with profiler.section("training_step", frames=1000): ...
profiler.summary()
Source code in xlron/environments/wrappers.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
record(tag, elapsed, frames=None)
Record and print a section timed elsewhere (e.g. overlapping other work).
Source code in xlron/environments/wrappers.py
264 265 266 267 268 269 270 | |
section(tag, frames=None)
Return a context manager that times the enclosed block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
Name for this section. Repeated uses accumulate. |
required |
frames
|
int | None
|
Optional work-unit count (e.g. timesteps) for throughput. |
None
|
Source code in xlron/environments/wrappers.py
255 256 257 258 259 260 261 262 | |
summary()
Print a table summarising all recorded sections.
Source code in xlron/environments/wrappers.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
TimeIt
Context manager for timing execution of code blocks.
Source code in xlron/environments/wrappers.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
Environment functions
aggregate_slots(full_mask, params)
Aggregate slot mask via max-pooling.
Source code in xlron/environments/env_funcs.py
2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 | |
calculate_fragmentation(link_slot_array)
Calculate mean external spectrum fragmentation across links.
External fragmentation per link = 1 - largest_free_block / total_free_slots. It is 0 when each link's free capacity is contiguous (or the link is completely full/empty) and approaches 1 as free slots are scattered into many small blocks.
Occupancy follows the same convention as the utilisation metric: any non-zero value counts as occupied (in-service slots are stored as negative values). Uses an O(links x slots) cumulative-max scan (no NxN block-size matrices as in find_block_sizes), so it is cheap enough to compute on the hot path every step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_slot_array
|
Array
|
Link-slot occupancy array of shape (num_links, num_slots) |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Scalar mean external fragmentation across links |
Source code in xlron/environments/env_funcs.py
2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 | |
calculate_utilisation(link_slot_array)
Spectrum utilisation over usable slots.
Band-gap sentinels (-1) are neither occupied nor usable spectrum, so positively-occupied slots are counted over the usable (non-gap) slots only. Computed per logging increment from the final state (not per step: the two full-array reductions cost measurable time on the hot path and the value is a slowly-varying state property).
Source code in xlron/environments/env_funcs.py
2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 | |
channel_entries(bandwidth, power, centre, capacity, pallas=False)
Compact one link's per-slot channel row to one GN entry per channel.
Returns (take, expand): take(x, fill) gathers a per-slot array x (..., slots) at each channel's first signal slot, giving (..., capacity) entries in slot order, with fill beyond the last channel; expand(values, broadcast, fill) maps (capacity,) per-channel values back to slots: to every signal slot of the channel with broadcast, else to its first signal slot only, and fill on the other slots. capacity must bound the link's channels (max_channels_per_link); the GN model then evaluates capacity entries instead of one per slot, and the gather from the compact result is also the broadcast to the channel's slots. With pallas, the index and owner come from one compaction kernel (kernels.compact) instead of a scan and a search.
Source code in xlron/environments/env_funcs.py
4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 | |
channel_physics_rows(bandwidth, power, centre)
One GN entry per channel from per-slot channel rows (last axis = slots).
Returns (bandwidth, power, first, signal): bandwidth and power kept only on
each channel's first signal slot (first) and zero elsewhere, and signal,
True on every signal slot. A channel is a run of signal slots (nonzero
bandwidth) with one centre frequency; two channels on a link never share a
centre, so a change of centre separates adjacent ones.
Source code in xlron/environments/env_funcs.py
4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 | |
channel_slot_mask(initial_slot_index, num_slots, params)
(link_resources,) True on the signal slots of a channel (its guard slots excluded).
Source code in xlron/environments/env_funcs.py
4092 4093 4094 4095 4096 4097 4098 4099 | |
check_action_rmsa_gn_model(state, action_info, params)
Check if action is valid for RSA GN model Args: state (EnvState): Environment state params (EnvParams): Environment parameters action (Array): Action array Returns: bool: True if action is invalid, False if action is valid
Source code in xlron/environments/env_funcs.py
5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 | |
check_action_rmsa_gn_model_components(state, action_info, params)
Compute the individual acceptance checks for the RMSA GN model.
The three checks correspond to the possible blocking causes: spectrum contention, insufficient SNR, and per-fibre power budget. step_env uses the components to count blocking causes without recomputing them; check_action_rmsa_gn_model aggregates them into the overall validity check.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
action_info
|
ActionInfo
|
Action info |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns: tuple: (rsa_check, snr_sufficient_check, power_check) - each truthy if the corresponding check failed (action invalid)
Source code in xlron/environments/env_funcs.py
5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 | |
check_action_rsa(state, action_info, params)
Differentiable version of check_action_rsa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Current environment state |
required | |
temperature
|
Controls sharpness of sigmoid |
required |
Returns:
| Type | Description |
|---|---|
|
Continuous value that behaves like the original boolean check |
Source code in xlron/environments/env_funcs.py
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 | |
check_action_rsa_prestate(state, action_info, params)
Validity check for plain RSA/RMSA/RWA actions, evaluated on the PRE-implementation state (non-differentiable mode only; the differentiable mode needs the soft implement/check/undo flow for gradients).
Semantically identical to check_action_rsa run after implement_path_action: a plain-RSA action fails iff (a) any slot in the requested window [initial_slot, initial_slot + num_slots) is occupied (nonzero) on any path link -- exactly when the speculative allocation would produce a value > 1 -- or (b) the window overflows the spectrum end, or (c) the action is the no-op (path_index >= k_paths), or (d) the path is a dummy. Reads only a (num_links, max_slots) window of link_slot_array instead of speculatively writing and rescanning the full (num_links, link_resources) array. Relies on the same invariant as mask_slots: required slots for any request never exceed params.max_slots (max_slots is computed in make_env from max_bw at the worst spectral efficiency).
Source code in xlron/environments/env_funcs.py
2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 | |
check_no_op(state, action_info, params)
Check for the "NO OP" action. This will be the maximum valid action idex + 1, resulting in a path index exceeding K paths.
Source code in xlron/environments/env_funcs.py
2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 | |
check_no_spectrum_reuse(state, action_info, params)
slot-=1 when used, should be zero when unoccupied, so check if any < -1 in slot array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_slot_array
|
Link slot array (L x S) where L is number of links and S is number of slots |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if check failed, False if check passed |
Source code in xlron/environments/env_funcs.py
2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 | |
check_real_path(state, action_info, params)
Check if path is a dummy (all-zeros). A valid path always uses at least one link.
Source code in xlron/environments/env_funcs.py
2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 | |
check_slot_overflow(state, action_info, params)
If the action selects slot near the end, then the required slots can overflow and start filling from the start of the array, which might be free! To prevent this, we check the action index + required slots
Source code in xlron/environments/env_funcs.py
2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 | |
check_snr_sufficient(state, params, *, existing_required=None, live=None)
Check if SNR is sufficient for all active connections.
live optionally supplies live_lightpath_mask(state) (e.g. a baseline mask plus one inserted channel) to avoid recomputing it. Args: state (EnvState): Environment state params (EnvParams): Environment parameters Returns: jnp.array: 1 if any active connection has insufficient SNR, else 0
Source code in xlron/environments/env_funcs.py
4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 | |
complete_step_rmsa_gn_model(state, action_info, check, params)
Complete step for RMSA GN-model environments.
Same as RSA GN-model, plus modulation_format_index_array restoration.
Source code in xlron/environments/env_funcs.py
2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 | |
complete_step_rsa(state, action_info, check, params)
If the request is unsuccessful i.e. checks fail, then remove the partial (unfinalised) resource allocation. Partial resource allocation is indicated by negative time in link slot departure array. Check for values in link_slot_departure_array that are less than zero. If found, increase link_slot_array by +1 and link_slot_departure_array by current_time + holding_time of current request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
Returns:
| Type | Description |
|---|---|
EnvState
|
Updated environment state |
Source code in xlron/environments/env_funcs.py
2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 | |
complete_step_rsa_gn_model(state, action_info, check, params)
Complete step for RSA GN-model environments.
On failure (check==1), undo partial slot allocation and restore GN-model auxiliary arrays from their *_prev snapshots.
Source code in xlron/environments/env_funcs.py
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 | |
complete_step_rwalr(state, action_info, check, params)
Complete step for RWA-LR environments. Unlike complete_step_rsa, this does not modify link_slot_array on failure, because implement_action_rwalr already handles the undo via blending and link_slot_array stores a capacity mask (not an occupancy counter).
Source code in xlron/environments/env_funcs.py
2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 | |
compute_band_gaps_from_csv(link_resources, ref_lambda, slot_size, band_data_filepath=None)
Compute band gap slot positions from band definition CSV data.
Reads the band data CSV which defines frequency ranges for each optical band. Any slot whose centre frequency falls between bands is marked as a gap slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_resources
|
int
|
Number of frequency slots per link. |
required |
ref_lambda
|
float
|
Reference wavelength (m). |
required |
slot_size
|
float
|
Slot width in GHz. |
required |
band_data_filepath
|
str | None
|
Optional path to band data CSV file. Defaults to
built-in |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[list, list]
|
Tuple of (gap_start_slots, gap_width_slots) as Python lists of ints. |
Source code in xlron/environments/env_funcs.py
3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 | |
compute_band_layout(slot_size, band_preference, inter_band_gap_ghz=25.0, band_data_filepath=None, max_bandwidth_ghz=None, slots_per_band=None)
Compute band layout: link_resources, ref_lambda, slot centre frequencies, gaps, and orderings.
Given a slot size and selected bands, this function:
1. Determines how many slots fit in each band
2. Inserts 1 gap slot per inter-band boundary (representing inter_band_gap_ghz)
3. Computes absolute centre frequencies for every slot
4. Optionally trims bands to fit within a maximum bandwidth (e.g. for DRA)
5. Returns all derived quantities needed by make_env
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slot_size
|
float
|
Spectral width of a frequency slot in GHz. |
required |
band_preference
|
str
|
Comma-separated band names in preference order (e.g. "C,L,S"). |
required |
inter_band_gap_ghz
|
float
|
Physical spectral width of inter-band gap in GHz (~0.2 nm). |
25.0
|
band_data_filepath
|
str | None
|
Optional path to band data CSV. Defaults to built-in. |
None
|
max_bandwidth_ghz
|
float | None
|
If set, trim lowest-priority bands from the high-frequency end to keep total modulated bandwidth within this limit (e.g. 15000 for DRA). |
None
|
slots_per_band
|
str | None
|
If set, comma-separated slot counts per band (e.g. "45,45"). Overrides the default of filling each band's full spectral width. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys: link_resources, ref_lambda, slot_centre_freq_array (relative GHz), |
dict
|
gap_start_slots, gap_width_slots, band_slot_order_ff, band_slot_order_lf. |
Source code in xlron/environments/env_funcs.py
3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 | |
compute_band_slot_order(link_resources, ref_lambda, slot_size, band_preference, band_data_filepath=None)
Compute band-preference-ordered slot index arrays for first-fit and last-fit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_resources
|
int
|
Number of frequency slots per link. |
required |
ref_lambda
|
float
|
Reference wavelength (m). |
required |
slot_size
|
float
|
Slot width in GHz. |
required |
band_preference
|
str
|
Comma-separated band names in preference order (e.g. "C,L,S"). |
required |
band_data_filepath
|
str | None
|
Optional path to band data CSV. Defaults to built-in. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of (band_slot_order_ff, band_slot_order_lf) as numpy int32 arrays |
ndarray
|
of shape (link_resources,). |
Tuple[ndarray, ndarray]
|
band_slot_order_ff has slots ascending within each band, bands in preference order. |
Tuple[ndarray, ndarray]
|
band_slot_order_lf has slots descending within each band, bands in preference order. |
Source code in xlron/environments/env_funcs.py
3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 | |
compute_total_power_per_link(channel_power_array, path_index_array, channel_centre_freq_array)
Compute total optical power per link by summing one power value per channel.
Each channel spans multiple contiguous slots with the same power value, path_index and centre frequency. Channel starts are detected where path_index OR centre frequency changes: two concurrent connections on the same k-path in adjacent slot blocks share a path index, but their centre frequencies always differ, so the frequency transition keeps them distinct (path index alone merged them, dropping the second block's power from the max_power_per_fibre checks).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_power_array
|
(num_links, link_resources) per-channel power in linear Watts |
required | |
path_index_array
|
(num_links, link_resources) lightpath index (-1 for empty) |
required | |
channel_centre_freq_array
|
(num_links, link_resources) channel centre frequency |
required |
Returns: (num_links,) total optical power per link in linear Watts
Source code in xlron/environments/env_funcs.py
4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 | |
convert_node_probs_to_traffic_matrix(node_probs)
Convert list of node probabilities to symmetric traffic matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_probs
|
list
|
node probabilities |
required |
Returns:
| Name | Type | Description |
|---|---|---|
traffic_matrix |
Array
|
traffic matrix |
Source code in xlron/environments/env_funcs.py
2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 | |
count_until_next_one(array, position, temperature, differentiable=True)
Counts positions until the next 1 in the array. Made differentiable using straight-through gradient trick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
Input array |
required |
position
|
int
|
Starting position for counting |
required |
temperature
|
float
|
Temperature for differentiable approximation |
required |
differentiable
|
bool
|
If False, use non-differentiable operations |
True
|
Returns:
| Type | Description |
|---|---|
Array
|
Number of positions until the next 1 |
Source code in xlron/environments/env_funcs.py
2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 | |
count_until_previous_one(array, position, temperature, differentiable=True)
Counts positions until the previous 1 in the array. Made differentiable using straight-through gradient trick.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Array
|
Input array |
required |
position
|
int
|
Starting position for counting backwards |
required |
temperature
|
float
|
Temperature for differentiable approximation |
required |
differentiable
|
bool
|
If False, use non-differentiable operations |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Number of positions until the previous 1 |
Source code in xlron/environments/env_funcs.py
2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 | |
create_run_name(config)
Create name for run based on config flags
Source code in xlron/environments/env_funcs.py
3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 | |
differentiable_check_no_spectrum_reuse(state, action_info, params)
Differentiable version of check_no_spectrum_reuse with improved gradient properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_slot_array
|
Link slot array (L x S) where L is number of links and S is number of slots |
required | |
temperature
|
Controls the sharpness of the gradient response |
required | |
differentiable
|
If False, return hard result directly without gradient approximation |
required |
Returns:
| Type | Description |
|---|---|
|
A value that behaves like the original boolean check in forward pass |
|
|
but has zero gradient when there are no violations and otherwise |
|
|
has gradient pointing toward reducing violations |
Source code in xlron/environments/env_funcs.py
2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 | |
find_block_ends(path_slots)
Finds the end positions of blocks in the path slots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_slots
|
Array
|
Array of path slots |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array with 1s at the end positions of blocks |
Source code in xlron/environments/env_funcs.py
2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 | |
find_block_starts(path_slots)
Finds the starting positions of blocks in the path slots. Args: path_slots: Array of path slots
Returns:
| Type | Description |
|---|---|
Array
|
Array with 1s at the starting positions of blocks |
Source code in xlron/environments/env_funcs.py
2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 | |
first_true_indices(mask, size)
jnp.nonzero(mask, size=size, fill_value=0)[0] for a 1-D mask, by binary search.
nonzero lowers to a scatter of every element into the output, which costs as much as the whole mask however small size is; the running count is monotone, so the n-th True entry is found by searching it for n.
Source code in xlron/environments/env_funcs.py
5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 | |
generate_arrival_holding_times(key, params, arrival_rate, mean_service_holding_time)
Generate exponential arrival and holding times from a PRNG key.
Draws all required uniforms in a single fused call and applies inverse-transform sampling (see _arrival_holding_from_uniforms for the construction).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNG key |
required | |
params
|
Environment parameters |
required | |
arrival_rate
|
Traced arrival rate (load / mean_service_holding_time) |
required | |
mean_service_holding_time
|
Traced mean service holding time |
required |
Returns:
| Name | Type | Description |
|---|---|---|
arrival_time |
Arrival time |
|
holding_time |
Holding time |
Source code in xlron/environments/env_funcs.py
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 | |
get_best_modulation_format_simple(state, path, initial_slot_index, params)
Get modulation format for lightpath. Assume worst case (least Gaussian) modulation format when calculating SNR. Args: state (EnvState): Environment state path (Array): Path array initial_slot_index (int): Initial slot index params (EnvParams): Environment parameters Returns: jnp.array: Acceptable modulation format indices
Source code in xlron/environments/env_funcs.py
5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 | |
get_candidate_snr_evidence(state, candidate, affected, params, *, old_required=None, unchanged=None)
(minimum new-path SNR over affected slots, all existing paths sufficient).
old_required encodes inactive predicates as -inf; NaN/+inf thresholds keep rejecting. unchanged=(baseline_db, overlap_by_path) reuses the baseline SNR of paths that share no link with the candidate; their predicates still count.
Source code in xlron/environments/env_funcs.py
4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 | |
get_centre_frequency(initial_slot_index, num_slots, params)
Get centre frequency for new lightpath.
Looks up pre-computed per-slot centre frequencies from
params.slot_centre_freq_array and returns the midpoint of the first
and last slot in the channel. This correctly handles non-uniform slot
spacing (e.g. inter-band gap slots).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_slot_index
|
Array
|
Index of the first slot of the channel. |
required |
num_slots
|
float
|
Number of slots occupied by the channel. |
required |
params
|
RSAGNModelEnvParams
|
Environment parameters. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Centre frequency for new lightpath (relative GHz offset |
Array
|
from ref_lambda). |
Source code in xlron/environments/env_funcs.py
4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 | |
get_channel_launch_power(state, path_action, power_action, initial_slot_index, num_slots, params)
Launch power [W] of a new channel: get_launch_power x its signal slots.
Configured launch powers (power_per_channel, the per-slot table, tabular and RL powers) are references per slot of signal bandwidth, i.e. a power spectral density, so every channel width launches at the same PSD (GNpy's PSD equalisation). Single-slot channels launch exactly the reference power.
Source code in xlron/environments/env_funcs.py
4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 | |
get_channel_values(initial_slot_index, num_slots, params)
(signal slots, signal width [GHz], centre frequency [GHz]) of a new channel.
num_slots includes the guard band, which carries no signal, so the centre is that of the signal slots and the width is signal slots x slot_size.
Source code in xlron/environments/env_funcs.py
4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 | |
get_edge_disjoint_paths(graph)
Get edge disjoint paths between all nodes in graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
graph |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[int, Dict[int, List[Tuple[int, int]]]]
|
edge disjoint paths (path is list of edges) |
Source code in xlron/environments/env_funcs.py
2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 | |
get_existing_snr_requirements(state, params, baseline_path_snr=None)
Protect the target reserve, or remaining headroom after a departure.
A fixed reserve on an already depleted, unrelated path would itself freeze global admission. Cap the reserve at fresh pre-admission SNR, while always retaining the modulation minimum. Inactive predicates remain unconditional.
Source code in xlron/environments/env_funcs.py
4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 | |
get_launch_power(state, path_action, power_action, initial_slot_index, params)
Get launch power for new lightpath. N.B. launch power is specified in dBm but is converted to linear units when stored in channel_power_array. This func returns linear units (mW). Path action is used to determine the launch power in the case of tabular launch power type. Power action is used to determine the launch power in the case of RL launch power type. During masking, power action is set as state.launch_power_array[0], which is set by the RL agent. Args: state (EnvState): Environment state path_action (Array): Action specifying path index (0 to k_paths-1) power_action (Array): Action specifying launch power in dBm initial_slot_index (Array): Initial slot index of the placement params (EnvParams): Environment parameters Returns: Array: Launch power for new lightpath
Source code in xlron/environments/env_funcs.py
7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 | |
get_lightpath_snr(state, params)
Accumulate full path SNR only for the paths referenced by link/slot state.
The sparse gather uses (links, slots, max_path_hops) work/storage instead of producing (all_possible_paths, slots) matrices, including during candidate masking. Padding is selected out before summation, so zero-SNR links outside a path cannot contaminate it with 0 * inf NaNs. With the Pallas backend the gather, ROADM ASE and dB conversion run in one kernel.
Source code in xlron/environments/env_funcs.py
4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 | |
get_line_graph_laplacian(graph)
Compute the Laplacian matrix of the line graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
NetworkX graph (original topology) |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Laplacian matrix of the line graph as a JAX array |
Source code in xlron/environments/env_funcs.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
get_line_graph_spectral_features(graph, num_features)
Compute spectral features for edges using the line graph Laplacian.
These features are used as positional encodings for transformer architectures with WiRE (Wavelet-Induced Rotary Encodings).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
NetworkX graph (original topology) |
required |
num_features
|
int
|
Number of spectral features to compute |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array of shape (num_edges, num_features) containing eigenvectors of the |
Array
|
line graph Laplacian, ordered by ascending eigenvalue magnitude. |
Array
|
These serve as positional encodings for edge/link tokens. |
Source code in xlron/environments/env_funcs.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
get_link_relevance_array(paths, paths_quality, params)
Compute 4 link relevance features for the current request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
Array
|
(k, E) binary path-link indicators |
required |
paths_quality
|
Array
|
(k,) per-path quality score (higher = better). For RMSA: 1/required_slots (SE-derived). For RWA-LR: path capacity. |
required |
params
|
RSAEnvParams
|
environment parameters |
required |
Returns:
| Type | Description |
|---|---|
|
(E, 4) array with columns: 0: weighted_relevance - combined rank/quality weighted sum across paths 1: path_count - fraction of k paths using each link 2: best_rank - 1 - min_rank/k for links on any path, 0 otherwise 3: best_quality - max quality among paths through link, normalized |
Source code in xlron/environments/env_funcs.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | |
get_minimum_snr_of_channels_on_path(state, path, slot_index, req_slots, params)
Get the path SNR of the channel newly assigned at slot_index. N.B. this requires the link_snr_array to have already been calculated and present in state.
The channel has one SNR, broadcast to all its signal slots, so it is read at its first slot; req_slots (which includes the dark guard band) is kept for the API.
Source code in xlron/environments/env_funcs.py
5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 | |
get_obs_transformer(state, params)
Retrieves observation for transformer model.
Creates tokens for each link/edge. Column order: [wire_features | edge_features | traffic_marginals | request-specific...] where request-specific features are at the end so the critic can strip them.
Request-specific columns (stripped for critic): - holding_time (1 col, departure modes only) - request_size (1 col) - link_relevance (4 cols)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RSAEnvState
|
Environment state |
required |
params
|
RSAEnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tokens |
Array
|
Array of shape (num_links, input_size) |
Source code in xlron/environments/env_funcs.py
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 | |
get_path(params, nodes, k_path_index)
Get k paths between source and destination
Source code in xlron/environments/env_funcs.py
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 | |
get_path_and_se(params, nodes, k_path_index)
Get k paths and their spectral efficiencies between source and destination
Source code in xlron/environments/env_funcs.py
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 | |
get_path_from_path_index_array(path_index_array, path_link_array)
Get path from path index array. Args: path_index_array (Array): Path index array path_link_array (Array): Path link array
Returns:
| Type | Description |
|---|---|
Array
|
jnp.array: path index values replaced with binary path-link arrays |
Source code in xlron/environments/env_funcs.py
4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 | |
get_path_index(params, nodes, k_path_index)
Get k paths between source and destination
Source code in xlron/environments/env_funcs.py
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 | |
get_path_index_array(params, nodes)
Indices of paths between source and destination from path array
Source code in xlron/environments/env_funcs.py
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 | |
get_path_se(params, nodes, k_path_index)
Get k paths between source and destination
Source code in xlron/environments/env_funcs.py
1566 1567 1568 1569 1570 1571 1572 | |
get_path_slots(link_slot_array, params, nodes_sd, i, agg_func='max')
Get slots on each constitutent link of path from link_slot_array (L x S), then aggregate to get (S x 1) representation of slots on path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_slot_array
|
Array
|
link-slot array |
required |
params
|
EnvParams
|
environment parameters |
required |
nodes_sd
|
Array
|
source-destination nodes |
required |
i
|
int
|
path index |
required |
agg_func
|
str
|
aggregation function (max or sum). If max, result will be available slots on path. If sum, result will contain information on edge features. if mean, will be mean. |
'max'
|
Returns:
| Name | Type | Description |
|---|---|---|
slots |
Array
|
slots on path |
Source code in xlron/environments/env_funcs.py
2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 | |
get_paths(params, nodes)
Get k paths between source and destination
Source code in xlron/environments/env_funcs.py
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 | |
get_paths_obs_gn_model(state, params)
Get observation space for launch power optimization (with numerical stability).
Source code in xlron/environments/env_funcs.py
7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 | |
get_paths_se(params, nodes)
Get max. spectral efficiency of modulation format on k paths between source and destination
Source code in xlron/environments/env_funcs.py
1575 1576 1577 1578 1579 1580 1581 1582 | |
get_required_snr_se_kurtosis_array(modulation_format_index_array, col_index, params)
Convert modulation format index to required SNR or spectral efficiency. Modulation format index array contains the index of the modulation format used by the channel. The modulation index references a row in the modulations array, which contains SNR and SE values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modulation_format_index_array
|
Array
|
Modulation format index array |
required |
col_index
|
int
|
Column index for required SNR or spectral efficiency |
required |
params
|
RSAGNModelEnvParams
|
Environment parameters |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.array: Required SNR for each channel (min. SNR for empty channel (mod. index 0)) |
Source code in xlron/environments/env_funcs.py
4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 | |
get_snr_link_array(state, params, link_indices=None, rows=None, broadcast=True)
Get SNR per link Args: state (EnvState): Environment state params (EnvParams): Environment parameters link_indices: Optional subset of link rows; preserves their order and duplicates. rows: Optional (bandwidth, power, centre, modulation format) channel rows for link_indices, replacing the state's (e.g. a candidate insertion). A fifth entry, the rows' XPM before span accumulation (Pallas backend only), replaces the XPM calculation (see inserted_link_xpm). broadcast: copy each channel's SNR to all its signal slots. Without it only each channel's first signal slot holds its SNR (the other signal slots hold the empty-slot sentinel), which is all the admission checks read (live_lightpath_mask); the GN masks skip the copy for speed. Returns: jnp.array: SNR per link
Source code in xlron/environments/env_funcs.py
4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 | |
get_snr_link_array_fused(state, params, link_indices=None, broadcast=True)
Get SNR per link using fused computation (uniform spans, no mod_format_correction).
Drop-in replacement for get_snr_link_array that uses get_snr_fused to reduce XLA op count and kernel launch overhead on GPU.
Source code in xlron/environments/env_funcs.py
4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 | |
get_spectral_features(laplacian, num_features)
Compute spectral node features from symmetric normalized graph Laplacian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adj
|
Adjacency matrix of the graph |
required | |
num_features
|
int
|
Number of eigenvector features to extract |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array of shape (n_nodes, num_features) containing eigenvectors corresponding |
Array
|
to the smallest non-zero eigenvalues of the graph Laplacian. If the graph has |
Array
|
fewer nodes than num_features, the result is zero-padded to have num_features columns. |
Notes
- Skips trivial eigenvectors (those with near-zero eigenvalues)
- Eigenvectors are ordered by ascending eigenvalue magnitude
- Runtime is O(n^3) - use only for small/medium graphs
- Eigenvector signs are arbitrary (may vary between runs)
Source code in xlron/environments/env_funcs.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
held_lightpath_mask(state, params)
(links, slots) cells of lightpaths whose traffic has ended but are still lit.
Only the safe_release departure policy holds lightpaths (issue #67): an expired lightpath keeps its optical signal, and so its spectrum, power and interference, until switching it off leaves every live lightpath above its SNR threshold. Held cells are identified by an elapsed departure time on an occupied cell: departure <= current_time with absolute times, departure <= 0 with relative times (remaining time). Newly admitted lightpaths always depart in the future.
Source code in xlron/environments/env_funcs.py
4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 | |
implement_action_rmsa_gn_model(state, action_info, params)
Implement action for RSA GN model. Update following arrays: - link_slot_array - link_slot_departure_array - link_snr_array - modulation_format_index_array - channel_power_array - active_path_array Args: state (EnvState): Environment state action (Array): Action tuple (first is path action, second is launch_power) params (EnvParams): Environment parameters Returns: EnvState: Updated environment state
Source code in xlron/environments/env_funcs.py
5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 | |
implement_action_rsa(state, action_info, params)
Implement action to assign slots on links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RSAEnvState
|
current state |
required |
action
|
action to implement |
required | |
params
|
RSAEnvParams
|
environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
state |
EnvState
|
updated state |
Source code in xlron/environments/env_funcs.py
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 | |
implement_action_rsa_gn_model(state, action_info, params)
Implement action for RSA GN model. Update following arrays: - link_slot_array - link_slot_departure_array - link_snr_array - modulation_format_index_array - channel_power_array - active_path_array Args: state (EnvState): Environment state action (Array): Action tuple (first is path action, second is launch_power) params (EnvParams): Environment parameters Returns: EnvState: Updated environment state
Source code in xlron/environments/env_funcs.py
5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 | |
implement_and_complete_rsa(state, action_info, check, params)
Fused implement + finalise for the non-differentiable plain-RSA/RMSA/RWA step.
Equivalent to implement_path_action followed by complete_step_rsa, given check
already computed on the PRE-implementation state (check_action_rsa_prestate):
the allocation is applied exactly once, gated on success, so the speculative
write + undo passes of the implement/check/undo flow are not needed.
On success the arithmetic is bit-identical to the old flow
(mask * 1 == mask, and 0-valued deltas add exactly); on failure the state is
left untouched (the old flow's add-then-subtract round trip could perturb
occupied departure entries by float rounding; here they are never written).
Source code in xlron/environments/env_funcs.py
2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 | |
init_active_lightpaths_array(params)
Initialise active lightpath registry: rows of [path_index, initial_slot, num_slots].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
RSAGNModelEnvParams
|
Environment parameters |
required |
Returns: jnp.array: (M, 3) registry (default value -1, empty row)
Source code in xlron/environments/env_funcs.py
4263 4264 4265 4266 4267 4268 4269 4270 4271 | |
init_active_lightpaths_array_departure(params)
Initialise per-lightpath departure times, aligned row-wise with the registry.
Lifecycle: inserted NEGATIVE (-(current+holding)) as a pending marker by implement_action_rsa_gn_model; complete_step_rsa_gn_model flips it positive on success or zeroes the row on failure; remove_expired_services_rsa_gn_model expires 0 < dep <= t rows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
RSAGNModelEnvParams
|
Environment parameters |
required |
Returns: jnp.array: (M, 3) departure times (0 = empty) -> TIME tier
Source code in xlron/environments/env_funcs.py
4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 | |
init_active_path_array(params)
Initialise active path array. Stores details of full path utilised by lightpath on each frequency slot. Args: params (EnvParams): Environment parameters Returns: jnp.array: Active path array
Source code in xlron/environments/env_funcs.py
3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 | |
init_channel_centre_bw_array(params)
Initialise channel centre array. Args: params (EnvParams): Environment parameters Returns: jnp.array: Channel centre array
Source code in xlron/environments/env_funcs.py
3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 | |
init_channel_centre_freq_array(params)
Initialise channel centre frequency array. Args: params (EnvParams): Environment parameters Returns: jnp.array: Channel centre frequency array (GHz)
Source code in xlron/environments/env_funcs.py
3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 | |
init_channel_power_array(params)
Initialise channel power array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
EnvParams
|
Environment parameters |
required |
Returns: jnp.array: Channel power array
Source code in xlron/environments/env_funcs.py
3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 | |
init_graph_tuple(state, params, adj, exclude_source_dest=False)
Initialise graph tuple for use with Jraph GNNs. Args: state (EnvState): Environment state params (EnvParams): Environment parameters adj (jnp.array): Adjacency matrix of the graph Returns: jraph.GraphsTuple: Graph tuple
Source code in xlron/environments/env_funcs.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
init_link_capacity_array(params)
Initialise link capacity array. Represents available data rate for lightpath on each link. Default is high value (1e6) for unoccupied slots. Once lightpath established, capacity is determined by corresponding entry in path capacity array.
Source code in xlron/environments/env_funcs.py
3084 3085 3086 3087 3088 | |
init_link_length_array(graph)
Initialise link length array. Args: graph (nx.Graph): NetworkX graph Returns:
Source code in xlron/environments/env_funcs.py
393 394 395 396 397 398 399 400 401 402 403 | |
init_link_length_array_gn_model(graph, max_span_length, max_spans)
Initialise link length array for environements that use GN model of physical layer. We assume each link has spans of equal length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
NetworkX graph |
required |
max_span_length
|
int
|
Maximum span length in metres |
required |
max_spans
|
int
|
Maximum number of spans per link |
required |
Returns: jnp.array: Link length array (L x max_spans) in metres
Source code in xlron/environments/env_funcs.py
3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 | |
init_link_slot_array(params)
Initialize empty (all zeroes) link-slot array. 0 means slot is free, -1 means occupied. Args: params (EnvParams): Environment parameters Returns: jnp.array: Link slot array (E x S) where E is number of edges and S is number of slots
Source code in xlron/environments/env_funcs.py
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 | |
init_link_slot_mask(params, include_no_op=False, agg=1.0)
Initialize link mask
Source code in xlron/environments/env_funcs.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 | |
init_link_snr_array(params)
Initialise signal-to-noise ratio (SNR) array. Args: params (EnvParams): Environment parameters Returns: jnp.array: SNR array
Source code in xlron/environments/env_funcs.py
3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 | |
init_mod_format_mask(params)
Initialize link mask
Source code in xlron/environments/env_funcs.py
1221 1222 1223 1224 1225 1226 1227 1228 1229 | |
init_modulation_format_index_array(params)
Initialise modulation format index array. Args: params (EnvParams): Environment parameters Returns: jnp.array: Modulation format index array
Source code in xlron/environments/env_funcs.py
3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 | |
init_modulations_array(modulations_filepath=None)
Initialise array of maximum spectral efficiency for modulation format on path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modulations_filepath
|
str
|
Path to CSV file containing modulation formats. Defaults to None. |
None
|
Returns: jnp.array: Array of maximum spectral efficiency for modulation format on path. First two columns are maximum path length and spectral efficiency.
Source code in xlron/environments/env_funcs.py
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
init_path_capacity_array(link_length_array, path_link_array, min_request=1, scale_factor=1.0, alpha=0.0002, NF=4.5, B=10000000000000.0, R_s=100000000000.0, beta_2=-2.17e-26, gamma=0.0012, L_s=100000.0, lambda0=1.55e-06)
Calculated from Nevin paper: https://api.repository.cam.ac.uk/server/api/core/bitstreams/b80e7a9c-a86b-4b30-a6d6-05017c60b0c8/content
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_length_array
|
Array
|
Array of link lengths |
required |
path_link_array
|
Array
|
Array of links on paths |
required |
min_request
|
int
|
Minimum data rate request size. Defaults to 100 GBps. |
1
|
scale_factor
|
float
|
Scale factor for link capacity. Defaults to 1.0. |
1.0
|
alpha
|
float
|
Fibre attenuation coefficient. Defaults to 0.2e-3 /m |
0.0002
|
NF
|
float
|
Amplifier noise figure. Defaults to 4.5 dB. |
4.5
|
B
|
float
|
Total modulated bandwidth. Defaults to 10e12 Hz. |
10000000000000.0
|
R_s
|
float
|
Symbol rate. Defaults to 100e9 Baud. |
100000000000.0
|
beta_2
|
float
|
Dispersion parameter. Defaults to -21.7e-27 s^2/m. |
-2.17e-26
|
gamma
|
float
|
Nonlinear coefficient. Defaults to 1.2e-3 /W/m. |
0.0012
|
L_s
|
float
|
Span length. Defaults to 100e3 m. |
100000.0
|
lambda0
|
float
|
Wavelength. Defaults to 1550e-9 m. |
1.55e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Array of link capacities in Gbps |
Source code in xlron/environments/env_funcs.py
3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 | |
init_path_index_array(params)
Initialise path index array. Represents index of lightpath occupying each slot.
Source code in xlron/environments/env_funcs.py
3091 3092 3093 | |
init_path_length_array(path_link_array, graph)
Initialise path length array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_link_array
|
Array
|
Path-link array |
required |
graph
|
Graph
|
NetworkX graph |
required |
Returns: Array: Path length array
Source code in xlron/environments/env_funcs.py
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 | |
init_path_link_array(graph, k, disjoint=False, path_sort_criteria='', directed=False, modulations_array=None, rwa_lr=False, scale_factor=1.0, path_snr=False, n_workers=1, topology_name=None, cache_dir=None, maximum_path_length_km=None)
Optimized init_path_link_array.
Key optimizations over the original: 1. O(1) edge lookup via dictionary instead of O(E) linear scan per hop 2. Parallel path computation across node pairs via multiprocessing 3. Pre-allocated numpy array instead of list-of-lists append 4. Vectorized link_usage construction with numpy advanced indexing 5. Optional disk caching of computed arrays (cache_dir parameter)
Each path is defined by a link utilisation array (one row in the path-link array). 1 indicates link corresponding to index is used, 0 indicates not used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
NetworkX graph |
required |
k
|
int
|
Number of paths per node pair |
required |
disjoint
|
bool
|
Whether to use edge-disjoint paths |
False
|
path_sort_criteria
|
str
|
Sort paths by criterion |
''
|
directed
|
bool
|
Whether graph is directed |
False
|
modulations_array
|
None | Array
|
Array of maximum spectral efficiency for modulation format on path |
None
|
rwa_lr
|
bool
|
Whether the environment is RWA with lightpath reuse |
False
|
scale_factor
|
float
|
Scale factor for capacity calculation |
1.0
|
path_snr
|
bool
|
If GN model is used, include extra row of zeroes for unutilised paths |
False
|
n_workers
|
int
|
Number of parallel workers for path computation (1 = sequential) |
1
|
topology_name
|
str | None
|
Topology name for cache filename (required if cache_dir is set) |
None
|
cache_dir
|
str | Path | None
|
Directory for caching computed arrays. None disables caching. |
None
|
Returns:
| Type | Description |
|---|---|
Array
|
Path-link array (N(N-1)*k x E) where N is number of nodes, |
Array
|
E is number of edges, k is number of shortest paths |
Source code in xlron/environments/env_funcs.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 | |
init_path_se_array(path_length_array, modulations_array)
Initialise array of maximum spectral efficiency for highest-order modulation format on path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path_length_array
|
array
|
Array of path lengths |
required |
modulations_array
|
array
|
Array of maximum spectral efficiency for modulation format on path |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.array: Array of maximum spectral efficiency for on path |
Source code in xlron/environments/env_funcs.py
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 | |
init_rsa_request_array()
Initialize request array [source, datarate, dest].
Source code in xlron/environments/env_funcs.py
1199 1200 1201 1202 1203 1204 | |
init_traffic_matrix(key, params)
Initialize traffic matrix. Allows for random traffic matrix or uniform traffic matrix. Source-dest traffic requests are sampled probabilistically from the resulting traffic matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PRNGKey
|
PRNG key |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Type | Description |
|---|---|
Array
|
jnp.array: Traffic matrix |
Source code in xlron/environments/env_funcs.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 | |
init_transceiver_amplifier_noise_arrays(link_resources, ref_lambda, slot_size, noise_data_filepath=None, slot_frequencies_ghz=None)
Initialise transceiver, amplifier, and ROADM noise arrays from per-band CSV data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_resources
|
int
|
Number of link resources. |
required |
ref_lambda
|
float
|
Reference wavelength. |
required |
slot_size
|
float
|
Slot size in GHz. |
required |
noise_data_filepath
|
str
|
Path to CSV file. Defaults to None. |
None
|
slot_frequencies_ghz
|
ndarray
|
Pre-computed absolute slot centre frequencies in GHz. When provided, these are used directly instead of computing from the uniform formula. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Array, Array, Array, Array, Array]
|
Tuple of per-slot arrays: (transceiver_snr, amplifier_noise_figure, roadm_express_loss, roadm_add_drop_loss, roadm_noise_figure) |
Source code in xlron/environments/env_funcs.py
3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 | |
inserted_link_xpm(coefficients, rows, start, power, centre, width, params)
XPM rows of links after inserting one channel, for get_snr_link_array rows.
The rows are per channel entry (channel_physics_rows), as get_snr_link_array evaluates them: the inserted channel is the single entry at its first slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coefficients
|
(H, 3, S) link_xpm_coefficients of the links before insertion. |
required | |
rows
|
(bandwidth, power, centre, ...) (H, S) channel rows after insertion. |
required | |
start
|
the inserted channel's first slot; power, centre, width its values [W, GHz, GHz]. |
required |
Source code in xlron/environments/env_funcs.py
4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 | |
lightpath_representatives(state, params)
One (links, slots) cell per lightpath: its first slot on the first link of its path.
A lightpath is identified by its path index and centre frequency: two lightpaths on one path never share a centre frequency because their slots cannot overlap.
Source code in xlron/environments/env_funcs.py
4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 | |
link_snr_cache_is_fresh(params)
Whether state.link_snr_array always equals get_snr_link_array(state).
Link SNR depends only on that link's own channels. Under safe_release every change re-solves exactly the links it touches (admissions, releases, and rollbacks restore the snapshot), so consumers may read the cache directly. Immediate departures leave the remaining channels on their links stale.
Source code in xlron/environments/env_funcs.py
4538 4539 4540 4541 4542 4543 4544 4545 4546 | |
link_xpm_coefficients(state, params)
(links, 3, slots) polynomial XPM coefficients of every link (Pallas, uniform spans).
With inserted_link_xpm, a candidate insertion then re-solves its path links' XPM in O(slots) per link instead of a full interferer reduction.
Source code in xlron/environments/env_funcs.py
4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 | |
live_lightpath_mask(state, params)
Cells whose lightpath carries traffic and so must meet its SNR threshold.
A channel has one SNR, so only its first signal slot on each link is checked (channel_physics_rows); the GN masks rely on this to skip the SNR broadcast.
Source code in xlron/environments/env_funcs.py
4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 | |
make_graph(topology_name='conus', topology_directory=None)
Create graph from topology definition. Topologies must be defined in JSON format in the topologies directory and named as the topology name with .json extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topology_name
|
str
|
topology name |
'conus'
|
topology_directory
|
str | None
|
topology directory |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
graph |
graph |
Source code in xlron/environments/env_funcs.py
2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 | |
make_line_graph(graph)
Create the line graph of a NetworkX graph.
The line graph L(G) has: - One node for each edge in the original graph G - An edge between two nodes in L(G) if the corresponding edges in G share a node
This is used for transformer architectures where we treat edges (links) as tokens and need positional encodings based on edge relationships.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
NetworkX graph (original topology) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
line_graph |
Graph
|
NetworkX line graph where nodes correspond to edges in the original |
Source code in xlron/environments/env_funcs.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
mask_slots_rmsa_gn_model(state, params, request)
Compute the RMSA-GN action mask (see _mask_slots_rmsa_gn_model).
Under an outer environment vmap, all_slots masks are computed in chunks of gn_mask_env_batch_size environments (0: all of them) without changing policy batching. Each chunk runs in lockstep: its loops, switches and conds are shared, and with the Pallas endpoint screen its candidates go through shared queues (pooled_masks), so kernels cover the whole chunk without padding to the busiest environment. Chunks of 1, and first-fit masks without the endpoint screen, mask the environments one at a time.
Source code in xlron/environments/env_funcs.py
5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 | |
mask_slots_rwalr(state, params, request)
For use in RWALightpathReuseEnv. Each lightpath has a maximum capacity defined in path_capacity_array. This is updated when a lightpath is assigned. If remaining path capacity is less than current request, corresponding link-slots are masked out. If link-slot is in use by another lightpath for a different source and destination node (even if not full) it is masked out. Step 1: - Mask out slots that are not valid based on path capacity (check link_capacity_array) Step 2: - Mask out slots that are not valid based on lightpath reuse (check path_index_array)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RWALightpathReuseEnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
request
|
Array
|
Request array in format [source_node, data-rate, destination_node] |
required |
Returns:
| Name | Type | Description |
|---|---|---|
state |
RWALightpathReuseEnvState
|
Updated environment state |
Source code in xlron/environments/env_funcs.py
3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 | |
max_channels_per_link(params)
Static bound on the channels of one link: each takes a signal slot and its guard band.
Source code in xlron/environments/env_funcs.py
4155 4156 4157 | |
normalise_traffic_matrix(traffic_matrix)
Normalise traffic matrix to sum to 1
Source code in xlron/environments/env_funcs.py
1246 1247 1248 1249 | |
pad_array(array, fill_value)
Pad a ragged multidimensional array to rectangular shape. Used for training on multiple topologies. Source: https://codereview.stackexchange.com/questions/222623/pad-a-ragged-multidimensional-array-to-rectangular-shape
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
array to pad |
required | |
fill_value
|
value to fill with |
required |
Returns:
| Name | Type | Description |
|---|---|---|
result |
padded array |
Source code in xlron/environments/env_funcs.py
3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 | |
process_path_action(state, params, path_action)
Process path action to get path index and initial slot index. Args: state (State): current state params (Params): environment parameters path_action (int): path action Returns: int: path index int: initial slot index
Source code in xlron/environments/env_funcs.py
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 | |
read_rsa_request(request_array)
Read RSA request from request array. Return source-destination nodes and bandwidth request. Args: request_array: request array Returns: Tuple[Array, Array]: source-destination nodes and bandwidth request
Source code in xlron/environments/env_funcs.py
2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 | |
release_departures_safely(state, params)
Departure processing for departure_policy="safe_release" (issue #67).
Expired lightpaths are held (see held_lightpath_mask). Held lightpaths are then switched off oldest-first, each only if the GN model of the state without it (its path links re-solved; all other links are unchanged) and full end-to-end path SNR leave every live lightpath at or above its modulation threshold (and the existing_snr_margin reserve, capped at its current SNR, as for admissions). Every intermediate optical state is therefore safe, so live lightpaths never fall below threshold because of a departure. A rejected release is retried at later arrivals.
Source code in xlron/environments/env_funcs.py
4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 | |
remove_expired_services_rwalr(state, params)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RWALightpathReuseEnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Type | Description |
|---|---|
RWALightpathReuseEnvState
|
Updated environment state |
Source code in xlron/environments/env_funcs.py
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 | |
required_slots(bitrate, se, channel_width, guardband=1, temperature=1.0, differentiable=True)
Calculate required slots for a given bitrate and spectral efficiency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bit_rate
|
float
|
Bit rate in Gbps |
required |
se
|
float
|
Spectral efficiency in bps/Hz |
required |
channel_width
|
float
|
Channel width in GHz |
required |
guardband
|
int
|
Guard band. Defaults to 1. |
1
|
temperature
|
float
|
Temperature for differentiable approximation. Defaults to 1.0. |
1.0
|
differentiable
|
bool
|
If False, use non-differentiable operations. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Required slots |
Source code in xlron/environments/env_funcs.py
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 | |
set_band_gaps(link_slot_array, params, val)
Set band gaps in link slot array Args: link_slot_array (Array): Link slot array params (RSAGNModelEnvParams): Environment parameters val (int): Value to set Returns: Array: Link slot array with band gaps
Source code in xlron/environments/env_funcs.py
5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 | |
signal_slot_count(num_slots, params)
Signal slots of a channel occupying num_slots slots including its guard band.
Source code in xlron/environments/env_funcs.py
4087 4088 4089 | |
update_active_lightpaths_array(state, path_index, initial_slot_index, num_slots)
Update active lightpaths array with new path index. Find the first index of the array with value -1 and replace with path index. Args: state (RSAGNModelEnvState): Environment state path_index (int): Path index to add to active lightpaths array Returns: jnp.array: Updated active lightpaths array
Source code in xlron/environments/env_funcs.py
4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 | |
update_active_lightpaths_array_departure(state, time)
Write the departure time into the registry row chosen by update_active_lightpaths_array. Args: state (RSAGNModelEnvState): Environment state time (float): Departure time (negative = pending marker, see init docstring) Returns: jnp.array: Updated departure array
Source code in xlron/environments/env_funcs.py
4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 | |
update_graph_tuple(state, params)
Update graph tuple for use with Jraph GNNs.
Edge and node features are updated from link_slot_array and node_capacity_array respectively. Global features are updated as request_array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
state |
EnvState
|
Environment state with updated graph tuple |
Source code in xlron/environments/env_funcs.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
uses_pallas_kernels(params)
True when a GN environment selects the Pallas kernels (--gn_kernel_backend).
Source code in xlron/environments/env_funcs.py
4393 4394 4395 | |
Training Utilities
LossDiagnostics
Bases: NamedTuple
Per-step diagnostics emitted from the PPO loss when ENHANCED_LOGGING is on.
Auto-registered as a JAX pytree, so it stacks field-wise inside scan/vmap.
Add a field here and it flows through to the wandb registry below and to
the dict built in _update_step.
Source code in xlron/train/train_utils.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
TrainState
Bases: Module
Train state for Equinox models.
The model is stored but marked as non-pytree so JAX doesn't try to trace it.
Source code in xlron/train/train_utils.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
apply_gradients(grads)
Updates model parameters and opt_state.
Source code in xlron/train/train_utils.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
create(model, tx, lr_schedule=lambda x: jnp.array(0.0), ent_schedule=lambda x: jnp.array(0.0), vml_schedule=lambda x: jnp.array(0.0), prio_alpha=0.0, prio_beta0=1.0, prio_beta=1.0, reward_stepsize_init=0.001, initial_avg_reward=0.0)
staticmethod
Creates a new instance with step=0 and initialized opt_state.
Source code in xlron/train/train_utils.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
update_step_size()
Updates the step size used for reward centering.
Source code in xlron/train/train_utils.py
229 230 231 232 233 234 235 236 237 238 239 | |
build_run_summary(run_type, config, metrics_dict, timing=None)
Build a standardized run summary dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_type
|
str
|
One of "rl_training", "heuristic_eval", "model_eval", "cutset_bound", "reconfigurable_routing_bound". |
required |
config
|
dict
|
Dict of user-specified flags (from get_user_flags). |
required |
metrics_dict
|
Dict[str, Dict[str, float]]
|
{metric_name: {"mean": ..., "std": ..., "iqr_lower": ..., "iqr_upper": ...}}. |
required |
timing
|
Dict[str, Any] | None
|
Optional dict with "compilation_time_s", "execution_time_s", "fps". |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary ready for json.dumps serialization. |
Source code in xlron/train/train_utils.py
2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 | |
cast_model_for_compute(model)
Cast a model's float (inexact) leaves to COMPUTE_DTYPE for the forward pass.
Mixed-precision training: the master weights stay at PARAMS_DTYPE (float32) in the
TrainState and optimizer, and are cast to COMPUTE_DTYPE (e.g. bfloat16) only for the forward
pass. Because the cast sits inside the differentiated region (it is applied to the model that
_loss_fn is differentiated through), gradients flow back through it to the float32 master
copy, so the optimizer keeps updating float32 weights. No-op when COMPUTE_DTYPE ==
PARAMS_DTYPE (the default), which avoids an unnecessary copy.
Source code in xlron/train/train_utils.py
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 | |
count_parameters(params)
Counts the number of parameters in a parameter tree.
Source code in xlron/train/train_utils.py
281 282 283 | |
get_sweep_rewarm_fn(env, env_params, config)
Build a jitted re-equilibration function for load sweeps.
A load sweep reuses the compiled experiment across loads, but the network state
(link occupancy, departure times) in the base experiment_input was warmed up at
the original --load. Starting every swept load from that state biases per-load
steady-state metrics: low loads inherit an over-full network (blocking
overestimated), high loads an under-full one (underestimated). The returned
function re-runs the ENV_WARMUP_STEPS warmup at the state's (already updated)
arrival rate, then zeroes the warmup metric counters so each swept load's metrics
exclude the re-equilibration transient. Build it once outside the load loop:
arrival_rate is a dynamic state leaf, so the single compilation is reused
across all loads (preserving the sweep's compile-once behaviour).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Environment (same one the experiment was compiled with) |
required | |
env_params
|
Environment parameters |
required | |
config
|
Config Box (reads ENV_WARMUP_STEPS, NUM_ENVS, NUM_LEARNERS, ...) |
required |
Returns:
| Type | Description |
|---|---|
Callable[[Tuple, PRNGKey], Tuple]
|
Jitted function (experiment_input, warmup_key) -> experiment_input, where |
Callable[[Tuple, PRNGKey], Tuple]
|
experiment_input is (runner_state, env_state, obsv, rng_step, rng_epoch). |
Callable[[Tuple, PRNGKey], Tuple]
|
With NUM_LEARNERS > 1 the function is vmapped over the leading learner axis |
Callable[[Tuple, PRNGKey], Tuple]
|
and warmup_key must be a batch of NUM_LEARNERS keys. |
Source code in xlron/train/train_utils.py
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 | |
get_user_flags(flags)
Extract only explicitly-set (non-default) flags from absl FlagValues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flags
|
absl.flags.FlagValues instance. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict of {flag_name: value} for flags that were set on the command line. |
Source code in xlron/train/train_utils.py
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 | |
get_warmup_fn(warmup_state, env, params, train_state, config)
Warmup period to fill the network before training or eval.
The action selection method is controlled by config.warmup_action_type:
- None : use the default for the current run mode (RL policy or heuristic)
- "heuristic" : always use the heuristic specified by --path_heuristic
- "random" : sample uniformly from valid (masked) actions
Source code in xlron/train/train_utils.py
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 | |
heuristic_eval_obs_placeholder(num_envs=1)
Shape-(1,) placeholder observation for pure-heuristic eval.
Heuristic action selection (select_action_eval with config.EVAL_HEURISTIC) reads only env_state, never the observation, yet the obs rides every scan/fori_loop carry. Building the real flattened observation (request_array + link_slot_array concat, ~4.4k elements on NSFNET 100-FSU) each step is dead work that cannot be eliminated while the obs is threaded through the carry. Substituting this placeholder makes env.step's returned obs unused, so the whole get_obs build is dead-code-eliminated from the compiled step. Not applied for GNN/Transformer policies (their obs is (env_state, params)) nor for EVAL_MODEL or RL training, where the model consumes the observation.
Every site that threads the heuristic-eval obs carry must use this same placeholder (experiment_data_setup, get_warmup_fn's loop body, eval_heuristic's step body) so the carry structure stays consistent across init, warmup, re-warm (load sweeps) and eval.
Source code in xlron/train/train_utils.py
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 | |
load_warmup_cache(path, template)
Restore save_warmup_cache's result into template's structure, shapes and dtypes.
Source code in xlron/train/train_utils.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 | |
log_metrics(config, out, total_run_time, increment_run_time, merge_func, episode_count=0, update_count=0, step_count=0)
Log metrics to wandb and/or save episode end metrics to CSV.
Source code in xlron/train/train_utils.py
2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 | |
make_ent_schedule(config)
Create an entropy coefficient schedule based on the configuration.
Source code in xlron/train/train_utils.py
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 | |
make_lr_schedule(config)
Create a learning rate schedule based on the configuration.
Source code in xlron/train/train_utils.py
1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 | |
make_vf_lr_schedule(config)
Create a learning rate schedule for the value function optimizer.
Source code in xlron/train/train_utils.py
1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 | |
make_vml_schedule(config)
Create a valid mass loss coefficient schedule based on the configuration.
Source code in xlron/train/train_utils.py
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 | |
merge_leading_dims(x, num_dims)
Merge leading dimensions.
Note
This implementation is a generic function for merging leading dimensions extracted from Haiku. For the original implementation, please refer to the following link: (https://github.com/deepmind/dm-haiku/blob/main/haiku/_src/basic.py#L207)
Source code in xlron/train/train_utils.py
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 | |
model_inputs(obs, env_params, config)
Policy call arguments: graph policies read the env params beside the state.
Observations never carry the params (they are pytrees of arrays, which a rollout scan or env vmap would otherwise copy into every transition), so they are appended here at call time.
Source code in xlron/train/train_utils.py
1257 1258 1259 1260 1261 1262 1263 1264 | |
ndim_at_least(x, num_dims)
Check if the number of dimensions of x is at least num_dims.
Source code in xlron/train/train_utils.py
521 522 523 524 525 | |
print_experiment_summary(config, env_params=None)
Print a formatted summary of the experiment configuration.
Source code in xlron/train/train_utils.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
print_metrics(processed_data, config, user_flags=None, timing=None)
Print final metrics as a standardized run summary and optionally write JSONL.
Source code in xlron/train/train_utils.py
2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 | |
process_metrics(config, out, merge_func)
Calculate statistics from training or evaluation run.
Source code in xlron/train/train_utils.py
2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 | |
reset_warmup_metric_counters(env_state)
Zero the metric counters accumulated during warmup.
With continuous_operation the env is never reset, so the cumulative counters (accepted_services, accepted_bitrate, total_bitrate, and the GN-model blocked_spectrum/blocked_snr/blocked_power counters) and the LogWrapper's lengths/cum_returns would otherwise include the near-zero-blocking network-fill transient, biasing every logged blocking probability (ENV_WARMUP_STEPS is documented as 'steps before collecting stats'). These fields are metrics-only; total_requests, which drives episode truncation, is deliberately kept. jnp.zeros_like preserves per-env shapes and dtypes for the jitted learner.
Source code in xlron/train/train_utils.py
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
run_eval_during_training(config, run_eval, eval_input, out, best_eval_metric, step_count, first_save=True)
Run evaluation during training and save model if it improves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Box
|
Training configuration. |
required |
run_eval
|
Callable
|
Compiled eval function. |
required |
eval_input
|
Tuple
|
Initial eval runner state (train_state, env_state, obsv, rng_step, rng_epoch). |
required |
out
|
Dict
|
Output from the current training increment. |
required |
best_eval_metric
|
float
|
Best eval metric seen so far. |
required |
step_count
|
int
|
Current training env step count (for wandb logging). |
required |
first_save
|
bool
|
Whether this is the first save of the training run. |
True
|
Returns:
| Type | Description |
|---|---|
Tuple
|
Tuple of (updated best_eval_metric, updated first_save). |
Source code in xlron/train/train_utils.py
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 | |
save_warmup_cache(path, result)
Save the warmup's (env_state, obs) leaves; written atomically.
Source code in xlron/train/train_utils.py
1203 1204 1205 1206 1207 1208 1209 | |
scale_gradient(g, scale=1)
Scales the gradient of g by scale but keeps the original value unchanged.
Source code in xlron/train/train_utils.py
276 277 278 | |
select_action(select_action_state, env, env_params, train_state, config)
Select an action from the policy. If using VONE, the action is a tuple of (source, path, destination). Otherwise, the action is a single lightpath. Args: select_action_state: Tuple of (rng_key, env_state, last_obs) env: Environment env_params: Environment parameters train_state: TrainState config: Configuration Returns: env_state: Environment state action: Action log_prob: Log probability of action value: Value of state
Source code in xlron/train/train_utils.py
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 | |
steps_per_train_state_unit(config)
Number of train_state.step increments per update loop.
train_state.step increments once per gradient (minibatch) step when STEP_ON_GRADIENT is set, otherwise once per update loop. Any schedule or anneal evaluated at train_state.step (entropy/VML schedules, GAE-lambda and prio-beta anneals) must scale its horizon by this factor so it completes exactly at the end of training. The LR schedules are exempt: they are driven by optax's internal count, which always ticks once per tx.update (i.e. per minibatch).
Source code in xlron/train/train_utils.py
1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 | |
unreplicate_batch_dim(x)
Unreplicated just the update batch dimension. (The dimension that is vmapped over when acting and learning)
In stoix's case it is always the second dimension, after the device dimension. We simply take element 0 as the params are identical across this dimension.
Source code in xlron/train/train_utils.py
555 556 557 558 559 560 561 562 | |
unreplicate_n_dims(x, unreplicate_depth=2)
Unreplicates a pytree by removing the first unreplicate_depth axes.
This function takes a pytree and removes some number of axes, associated with parameter
duplication for running multiple updates across devices and in parallel with vmap.
This is typically one axis for device replication, and one for the update batch size.
Source code in xlron/train/train_utils.py
545 546 547 548 549 550 551 552 | |
warmup_cache_path(config, warmup_state, env_params, runner_state)
File of this warmup's result under --WARMUP_CACHE_DIR, or None if not caching.
The name hashes everything the warmup's result depends on: the environment parameters (static fields included), reset states and warmup keys, the warmup settings, the policy weights when the policy acts, and the xlron source code, so a code change never reuses an older result.
Source code in xlron/train/train_utils.py
1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
write_run_summary(summary, output_file=None, print_to_console=True)
Print and/or write a run summary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
dict
|
The dict returned by build_run_summary(). |
required |
output_file
|
str | None
|
If not None, append as one JSON line to this file. |
None
|
print_to_console
|
bool
|
If True, print a human-readable summary to stdout. |
True
|
Source code in xlron/train/train_utils.py
2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 | |
Models
ActorCriticMLP
Bases: Module
Actor-Critic MLP using Equinox.
Source code in xlron/models/mlp.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
sample_action(seed, dist, log_prob=False, deterministic=False)
Sample an action from the distribution
Source code in xlron/models/mlp.py
262 263 264 265 266 267 268 269 270 271 272 273 | |
LaunchPowerActorCriticMLP
Bases: Module
Actor-Critic MLP for launch power optimization.
Takes an observation of the current request + statistics on each of the K candidate paths. Makes K forward passes, one for each path, and outputs a distribution over power levels for each path.
Source code in xlron/models/mlp.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 | |
num_power_levels
property
Calculate number of power levels dynamically
power_levels
property
Calculate power levels dynamically
get_action_probs(dist)
Get probabilities for discrete case or pdf for continuous case
Source code in xlron/models/mlp.py
493 494 495 496 497 498 499 | |
sample_action(seed, dist, log_prob=False, deterministic=False)
Sample an action and convert to power level
Source code in xlron/models/mlp.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 | |
MLP
Bases: Module
Simple MLP module using Equinox.
Source code in xlron/models/mlp.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
bfloat16_safe_orthogonal(scale=1.0)
Returns an orthogonal initializer that is safe for bfloat16.
Source code in xlron/models/mlp.py
104 105 106 107 108 109 110 | |
constant(value)
Returns a constant initializer.
Source code in xlron/models/mlp.py
113 114 115 116 117 118 119 | |
crelu(x)
Computes the Concatenated ReLU (CReLU) activation function.
Source code in xlron/models/mlp.py
66 67 68 69 | |
make_linear_with_orthogonal_init(in_features, out_features, key, scale=1.0, dtype=None)
Create a Linear layer with orthogonal initialization.
Source code in xlron/models/mlp.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
orthogonal_init(key, shape, scale=1.0, dtype=jnp.float32)
Orthogonal initializer that is safe for bfloat16 and other dtypes. Based on JAX/Flax orthogonal initializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
PRNGKey for initialization |
required |
shape
|
Tuple[int, ...]
|
Shape of the weight matrix |
required |
scale
|
float
|
Scaling factor for the orthogonal matrix |
1.0
|
dtype
|
dtype
|
Target dtype (will init in float32 then cast) |
float32
|
Returns:
| Type | Description |
|---|---|
Array
|
Orthogonally initialized weight matrix |
Source code in xlron/models/mlp.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
relu2(x)
Squared ReLU, max(x, 0)^2 (So et al. 2021, "Primer").
Source code in xlron/models/mlp.py
72 73 74 | |
relu3(x)
Cubed ReLU, max(x, 0)^3.
Source code in xlron/models/mlp.py
77 78 79 80 | |
select_activation(activation)
Selects the activation function based on the provided string.
Source code in xlron/models/mlp.py
94 95 96 97 98 99 100 101 | |
ActorCriticGNN
Bases: Module
Combined Actor-Critic GNN model.
Source code in xlron/models/gnn.py
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 | |
sample_action(seed, dist, log_prob=False, deterministic=False)
Sample an action from the distributions.
Source code in xlron/models/gnn.py
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 | |
sample_action_path(seed, dist, log_prob=False, deterministic=False)
Sample an action from the distribution.
Source code in xlron/models/gnn.py
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 | |
sample_action_path_power(seed, dist, log_prob=False, deterministic=False)
Sample an action from the distributions.
Source code in xlron/models/gnn.py
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 | |
sample_action_power(seed, dist, log_prob=False, deterministic=False)
Sample an action and convert to power level
Source code in xlron/models/gnn.py
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 | |
ActorGNN
Bases: Module
Actor network using GNN for processing graph state.
Source code in xlron/models/gnn.py
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 | |
CriticGNN
Bases: Module
Critic network using GNN for processing graph state.
Source code in xlron/models/gnn.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 | |
GraphNet
Bases: Module
A complete Graph Network model defined with Jraph and Equinox.
Source code in xlron/models/gnn.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
MessagePassingStep
Bases: Module
A single message passing step containing MLPs and optional layer norms.
Source code in xlron/models/gnn.py
421 422 423 424 425 426 427 428 429 430 | |
GAT(attention_query_fn, attention_logit_fn, node_update_fn=None)
Returns a method that applies a Graph Attention Network layer.
Graph Attention message passing as described in https://arxiv.org/abs/1710.10903. This model expects node features as a jnp.array, may use edge features for computing attention weights, and ignore global features. It does not support nests.
NOTE: this implementation assumes that the input graph has self edges. To recover the behavior of the referenced paper, please add self edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attention_query_fn
|
GATAttentionQueryFn
|
function that generates attention queries from sender node features. |
required |
attention_logit_fn
|
GATAttentionLogitFn
|
function that converts attention queries into logits for softmax attention. |
required |
node_update_fn
|
Optional[GATNodeUpdateFn]
|
function that updates the aggregated messages. If None, will apply leaky relu and concatenate (if using multi-head attention). |
None
|
Returns:
| Type | Description |
|---|---|
|
A function that applies a Graph Attention layer. |
Source code in xlron/models/gnn.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
GraphNetGAT(update_edge_fn, update_node_fn, attention_logit_fn, attention_reduce_fn, update_global_fn=None, aggregate_edges_for_nodes_fn=utils.segment_sum, aggregate_nodes_for_globals_fn=utils.segment_sum, aggregate_edges_for_globals_fn=utils.segment_sum)
Returns a method that applies a GraphNet with attention on edge features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_edge_fn
|
GNUpdateEdgeFn
|
function used to update the edges. |
required |
update_node_fn
|
GNUpdateNodeFn
|
function used to update the nodes. |
required |
attention_logit_fn
|
AttentionLogitFn
|
function used to calculate the attention weights. |
required |
attention_reduce_fn
|
AttentionReduceFn
|
function used to apply attention weights to the edge features. |
required |
update_global_fn
|
Optional[GNUpdateGlobalFn]
|
function used to update the globals or None to deactivate globals updates. |
None
|
aggregate_edges_for_nodes_fn
|
AggregateEdgesToNodesFn
|
function used to aggregate attention-weighted messages to each node. |
segment_sum
|
aggregate_nodes_for_globals_fn
|
AggregateNodesToGlobalsFn
|
function used to aggregate the nodes for the globals. |
segment_sum
|
aggregate_edges_for_globals_fn
|
AggregateEdgesToGlobalsFn
|
function used to aggregate attention-weighted edges for the globals. |
segment_sum
|
Returns:
| Type | Description |
|---|---|
|
A function that applies a GraphNet Graph Attention layer. |
Source code in xlron/models/gnn.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
GraphNetwork(update_edge_fn, update_node_fn, update_global_fn=None, aggregate_edges_for_nodes_fn=utils.segment_sum, aggregate_nodes_for_globals_fn=utils.segment_sum, aggregate_edges_for_globals_fn=utils.segment_sum, attention_logit_fn=None, attention_normalize_fn=utils.segment_softmax, attention_reduce_fn=None)
Returns a method that applies a configured GraphNetwork.
This implementation follows Algorithm 1 in https://arxiv.org/abs/1806.01261
There is one difference. For the nodes update the class aggregates over the sender edges and receiver edges separately. This is a bit more general than the algorithm described in the paper. The original behaviour can be recovered by using only the receiver edge aggregations for the update.
In addition this implementation supports softmax attention over incoming edge features.
Example usage::
gn = GraphNetwork(update_edge_function, update_node_function, **kwargs) # Conduct multiple rounds of message passing with the same parameters: for _ in range(num_message_passing_steps): graph = gn(graph)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_edge_fn
|
Optional[GNUpdateEdgeFn]
|
function used to update the edges or None to deactivate edge updates. |
required |
update_node_fn
|
Optional[GNUpdateNodeFn]
|
function used to update the nodes or None to deactivate node updates. |
required |
update_global_fn
|
Optional[GNUpdateGlobalFn]
|
function used to update the globals or None to deactivate globals updates. |
None
|
aggregate_edges_for_nodes_fn
|
AggregateEdgesToNodesFn
|
function used to aggregate messages to each node. |
segment_sum
|
aggregate_nodes_for_globals_fn
|
AggregateNodesToGlobalsFn
|
function used to aggregate the nodes for the globals. |
segment_sum
|
aggregate_edges_for_globals_fn
|
AggregateEdgesToGlobalsFn
|
function used to aggregate the edges for the globals. |
segment_sum
|
attention_logit_fn
|
Optional[AttentionLogitFn]
|
function used to calculate the attention weights or None to deactivate attention mechanism. |
None
|
attention_normalize_fn
|
Optional[AttentionNormalizeFn]
|
function used to normalize raw attention logits or None if attention mechanism is not active. |
segment_softmax
|
attention_reduce_fn
|
Optional[AttentionReduceFn]
|
function used to apply weights to the edge features or None if attention mechanism is not active. |
None
|
Returns:
| Type | Description |
|---|---|
|
A method that applies the configured GraphNetwork. |
Source code in xlron/models/gnn.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
add_graphs_tuples(graphs, other_graphs)
Adds the nodes, edges and global features from other_graphs to graphs.
Source code in xlron/models/gnn.py
380 381 382 383 384 385 386 387 388 | |
add_self_edges_fn(receivers, senders, total_num_nodes)
Adds self edges. Assumes self edges are not in the graph yet.
Source code in xlron/models/gnn.py
84 85 86 87 88 89 90 91 | |
ActorCriticTransformer
Bases: Module
Source code in xlron/models/transformer.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 | |
__call__(state, params, *, enable_dropout=False, key=None)
Forward pass through the actor-critic transformer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
enable_dropout
|
bool
|
Whether to enable dropout |
False
|
key
|
PRNGKey | None
|
PRNG key for dropout |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Categorical, Array]
|
Tuple of (action_distribution, value) |
Source code in xlron/models/transformer.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
sample_action(seed, dist, log_prob=False, deterministic=False)
Sample an action from the distribution
Source code in xlron/models/transformer.py
652 653 654 655 656 657 658 659 660 661 662 663 | |
AttentionBlock
Bases: Module
A single transformer attention block.
Source code in xlron/models/transformer.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
FeedForwardBlock
Bases: Module
A single transformer feed forward block.
Source code in xlron/models/transformer.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
TransformerLayer
Bases: Module
A single transformer layer.
Source code in xlron/models/transformer.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | |
WIRE
Bases: Module
Wavelet-Induced Rotary Encodings for graphs. https://openreview.net/pdf?id=f7BvsdILYx
Projects m-dimensional node features (e.g., RWSE, spectral coords) to rotation angles for RoPE-style positional encoding.
Source code in xlron/models/transformer.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
__call__(queries, keys, positions)
Apply WIRE to queries and keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queries
|
Float[Array, 'num_nodes embedding_size']
|
Query vectors (num_nodes, embedding_size) |
required |
keys
|
Float[Array, 'num_nodes embedding_size']
|
Key vectors (num_nodes, embedding_size) |
required |
positions
|
Float[Array, 'num_nodes num_features']
|
Node position features, e.g., RWSE (num_nodes, num_features) |
required |
Returns:
| Type | Description |
|---|---|
tuple[Float[Array, 'num_nodes embedding_size'], Float[Array, 'num_nodes embedding_size']]
|
Rotated (queries, keys) |
Source code in xlron/models/transformer.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
__init__(num_features, embedding_size, key, freq_scale=0.01)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_features
|
int
|
Dimension of input position features (m) |
required |
embedding_size
|
int
|
Dimension of queries/keys to rotate (must be even) |
required |
key
|
PRNGKeyArray
|
PRNG key |
required |
freq_scale
|
float
|
Scale for frequency initialisation |
0.01
|
Source code in xlron/models/transformer.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
get_angles(positions)
Compute rotation angles from position features.
Source code in xlron/models/transformer.py
99 100 101 102 103 | |
rotate(x, angles)
Apply rotary encoding to queries or keys.
For each 2D block [x_{2i}, x_{2i+1}], rotate by angle theta_i: x_{2i}' = x_{2i} * cos(theta) - x_{2i+1} * sin(theta) x_{2i+1}' = x_{2i} * sin(theta) + x_{2i+1} * cos(theta)
Source code in xlron/models/transformer.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
pooled_actor_projection(mlp, embeddings, paths)
Commute only the final affine projection with a path's weighted sum.
Hidden nonlinearities remain per link. The bias is multiplied by the sum of path weights, including zero for dummy paths. This keeps ordinary JAX AD. Exact because the actor MLP's final layer has an identity activation (the eqx.nn.MLP default), so sum pooling of logits equals projecting summed features.
Source code in xlron/models/transformer.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
Heuristics
arbr_ff(state, params)
Adaptive Routing with Back-to-back Regeneration (ARBR). Only suitable for RSA/RMSA. Ranks the k candidate paths by an adaptive metric combining the static resource cost of serving the request with the current utilisation of the path's links, then allocates first-fit on the best-ranked path with a free block. Reference: Walkowiak, Klinkowski & Lechowicz, "Dynamic routing in spectrally spatially flexible optical networks with back-to-back regeneration", J. Opt. Commun. Netw. 10(5), 2018.
Adaptation to single-fibre RSA/RMSA without regeneration or transceiver limits: each candidate routing configuration is a single transparent path, so the static cost reduces to SL(p, d) = hops x required slots (incl. guardband), the transceiver terms of the original metric vanish (transceivers unconstrained), and the dynamic cost reduces to the maximum link utilisation (MLU) over the path's links, quantised to decile bins {10, 20, ..., 100} as in the paper. The combined metric is c_adaptive = (1 - alpha) * SL + alpha * MLU, where the tuning parameter alpha is set by --arbr_alpha (0 = static cost only, 1 = dynamic utilisation only; 0.8 is the value recommended in the paper).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | |
best_fit(state, params)
Best-Fit Spectrum Allocation. Returns the best fit slot for each path.
Source code in xlron/heuristics/heuristics.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 | |
bf_ksp(state, params)
Get the first available slot from the first k-shortest paths Method: Go through action mask and find the first available slot on all paths
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
capacity_loss(state, params, num_interfering_routes=1)
Slot-continuity capacity loss (the MSCL metric) of every candidate (path, slot) assignment for the current request.
Capacity A future request needing w contiguous slots fits on path p at starting position i iff slots i..i+w-1 are free on every link of p. Writing run_p[i] for the length of the contiguous free run starting at slot i of p's link-aggregated spectrum (0 if slot i is occupied on any link), the number of feasible placements for size w is N_p(w) = #{i : run_p[i] >= w}, and the slot-continuity capacity of p is the total over all demand sizes:
C_p = sum_{w=1..W} N_p(w) = sum_i min(run_p[i], W)
W is the largest possible request in slots (from the max datarate, the
lowest spectral efficiency and the slot size, plus guardband); demand
sizes are weighted uniformly, as in the original formulation.
Loss Serving the current request on route r from slot s occupies slots [s, e) on every link of r (e = s + required slots incl. guardband). That reduces C_q for r itself and for every route q sharing >= 1 link with r; spectrum elsewhere is untouched. The MSCL loss of candidate (r, s) is
loss(r, s) = sum_{q affected} [ C_q before - C_q after ]
and the MSCL heuristics choose the candidate minimising it: a one-step
lookahead that consumes dead-end fragments and spares large aligned voids
on heavily-shared links, rather than packing blindly like first-fit.
Closed form Instead of materialising the updated spectrum for each of the k x S candidates, the per-route loss decomposes exactly into two terms computed from run-length arrays and a single prefix sum:
- inside the block: each free position i in [s, e) drops from
min(run[i], W) to 0; summed as a difference of the prefix sum of
min(run, W) at e and s.
- left of the block: positions i in the free run containing s (run start
a, run end b) are truncated from run length b - i to s - i, losing
min(b - i, W) - min(s - i, W); summing over d = s - i = 1..D with
D = s - a and gap g = b - s gives sum_min(D, g) - sum_min(D, 0), where
sum_min(D, off) = sum_{d=1..D} min(d + off, W) has the closed form
t*off + t(t+1)/2 + (D-t)*W with t = clip(W - off, 0, D).
Positions at or beyond e keep their runs (a free run starting there
cannot reach back across the newly occupied block), and runs not touching
[s, e) are unaffected. If s is already occupied for a route then a = b = s
and both terms vanish for it, which is exactly right. This closed form is
verified against a brute-force before/after recount in
heuristics_test.py::CapacityLossBruteforceTest.
Interfering route set Two routes interfere when they share at least one link. The routes whose capacity loss is accounted are controlled by num_interfering_routes = n: the first n stored paths of every node pair that share a link with the candidate route, plus the candidate route itself - counted once, since a candidate with k-index below n already is one of its own pair's first n stored routes. n = 1 (the default) is the single-route-per-pair set of the original 2013 formulation. n = k_paths is the all-stored-routes set of the multi-route extension of dos Santos (2021): it also prices in the damage a placement does to a pair's alternative routes (which future traffic will actually be offered to under KSP routing), at n times the cost and memory of the single-route set. The ksp_mscl and mscl_ksp heuristics choose n via the --mscl_interfering_k flag (0 = all k_paths).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
num_interfering_routes
|
int
|
Stored routes per node pair in the interfering set (static at trace time; 1 <= n <= k_paths) |
1
|
References R. C. Almeida Jr., A. F. dos Santos, K. D. R. Assis, H. Waldman & J. F. Martins-Filho, "Slot assignment strategy to reduce loss of capacity of contiguous-slot path requests in flexible grid optical networks", Electronics Letters 49(5), pp. 358-360, 2013. doi:10.1049/el.2012.4247 X. Zhang & C. Qiao, "Wavelength assignment for dynamic traffic in multi-fiber WDM networks", ICCCN 1998 - the relative-capacity-loss RWA metric that MSCL generalises to contiguous-spectrum RSA/RMSA. M. L. dos Santos, "Abordagens para atribuicao de espectro em redes opticas elasticas baseadas em perda de capacidade sob multiplas rotas" (Approaches for spectrum assignment in elastic optical networks based on capacity loss under multiple routes), M.Sc. dissertation, Universidade Federal de Pernambuco, Recife, 2021. https://repositorio.ufpe.br/handle/123456789/45594 - multi-route interfering sets; the MSCL Sequencial and MSCL Combinado heuristics.
Returns:
| Name | Type | Description |
|---|---|---|
Tuple |
Array
|
(loss, mask). loss is (k_paths, link_resources) float32 with jnp.inf |
Array
|
at invalid actions; mask is the (k_paths, link_resources) action mask. |
Source code in xlron/heuristics/heuristics.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 | |
exact_fit(state, params)
Exact-Fit Spectrum Allocation. For each path, find free blocks whose size exactly equals the required slots for the request.
Returns:
| Name | Type | Description |
|---|---|---|
Tuple |
Array
|
(first_exact, last_exact, mask). first_exact/last_exact hold the |
Array
|
lowest/highest exactly-fitting block start per path, or link_resources if |
|
Array
|
no exact fit exists on that path. |
Source code in xlron/heuristics/heuristics.py
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | |
ff_ksp(state, params)
Get the first available slot from all paths Method: Go through action mask and find the first available slot on all paths
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
first_fit(state, params)
First-Fit Spectrum Allocation. Returns the first fit slot for each path.
When band_slot_order_ff is set (GN model envs with --band_preference), slots are searched in band preference order rather than raw index order.
Source code in xlron/heuristics/heuristics.py
882 883 884 885 886 887 888 889 | |
flf_ksp(state, params)
First-Last-Fit across K-Shortest Paths. Small requests take the globally first available slot across all paths (ff_ksp); large requests take the globally last available slot across all paths (lf_ksp). See ksp_flf for the partitioning rationale and references.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
get_action_mask_and_slots(state, params)
Return feasible starts and the actual footprint of each (path, start).
GN resolves modulation separately for every start. Its nominal reach-based path efficiency does not describe the physically admitted footprint. Compute the mask and widths together so direct heuristic calls also use fresh formats.
Source code in xlron/heuristics/heuristics.py
953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 | |
get_link_weights(state, params)
Get link weights based on occupancy for use in congestion-aware routing heuristics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Link weights |
Source code in xlron/heuristics/heuristics.py
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 | |
get_path_free_arrays(link_slot_array, path_links)
Aggregate slot occupancy over the links of each path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
link_slot_array
|
Array
|
(num_links, num_slots) array; nonzero = occupied |
required |
path_links
|
Array
|
(num_paths, num_links) binary path-link incidence |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
bool (num_paths, num_slots); True where the slot is free on every link |
Source code in xlron/heuristics/heuristics.py
973 974 975 976 977 978 979 980 981 982 983 984 985 | |
get_request_num_slots(state, params)
Required slots (incl. guardband) for the current request on each of the k paths.
Source code in xlron/heuristics/heuristics.py
939 940 941 942 943 944 945 946 947 948 949 950 | |
get_run_lengths_and_bounds(free)
For each slot position, the length of the free run starting there and the [start, end) bounds of the free run containing it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
free
|
Array
|
bool (..., num_slots) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Tuple |
Array
|
(run_len, run_start, run_end), each (..., num_slots) int32. |
Array
|
For occupied positions run_len = 0 and run_start = run_end = position. |
Source code in xlron/heuristics/heuristics.py
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
is_large_request(state, params)
Classify the current request as large (True) or small (False) by comparing its datarate to the midpoint of the requestable datarate range. Used by the first-last-fit family to segregate request size classes at opposite spectrum ends.
Source code in xlron/heuristics/heuristics.py
930 931 932 933 934 935 936 | |
kca_ff(state, params)
Congestion-aware First Fit. Only suitable for RSA/RMSA. Method:
Source code in xlron/heuristics/heuristics.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
kmc_ff(state, params)
K-Minimum Cut. Only suitable for RSA/RMSA. Method: 1. Go through action mask and find the first available slot on all paths. 2. For each path, allocate the first available slot. 3. Sum number of new consecutive zero regions (cuts) created by assignment (on each link) 4. Choose path that creates the fewest cuts.
Source code in xlron/heuristics/heuristics.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
kme_ff(state, params)
K-Minimum Entropy. Only suitable for RSA/RMSA. Method: 1. Go through action mask and find the first available slot on all paths. 2. For each path, allocate the first available slot. 3. Sum the change in Shannon fragmentation entropy of the path's links caused by the assignment (Wright, Parker & Lord, JOCN 2015). 4. Choose path whose assignment increases entropy the least.
Source code in xlron/heuristics/heuristics.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
kmf_ff(state, params)
K-Minimum Frag-size. Only suitable for RSA/RMSA. Method: 1. Go through action mask and find the first available slot on all paths. 2. For each path, allocate the first available slot. 3. Sum number of new consecutive zero regions (cuts) created by assignment (on each link) 4. Choose path that creates the fewest cuts.
Source code in xlron/heuristics/heuristics.py
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
ksp_bf(state, params)
Get the first available slot from all k-shortest paths Method: Go through action mask and find the first available slot, starting from shortest path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
ksp_ef(state, params)
K-Shortest Path, Exact-Fit. Only suitable for RSA/RMSA. On the shortest available path, allocate the first free block whose size exactly matches the required slots; if no exact-fit block exists, fall back to first-fit. Exact-fit consumes blocks whole, avoiding the creation of small unusable fragments. Reference: Chatterjee, Sarma & Oki, "Routing and spectrum allocation in elastic optical networks: A tutorial", IEEE Comms. Surveys & Tutorials 17(3), 2015.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
ksp_ff(state, params)
Get the first available slot from the shortest available path Method: Go through action mask and find the first available slot, starting from shortest path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
ksp_ff_multiband(state, params)
Get the first available slot from all k-shortest paths in multiband scenario Method: Go through action mask and find the first available slot, starting from shortest path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
MultiBandRSAEnvState
|
Environment state specific to multiband operations |
required |
params
|
MultiBandRSAEnvParams
|
Environment parameters including multiband details |
required |
Returns: Array: Action
Source code in xlron/heuristics/heuristics.py
64 65 66 67 68 69 70 71 72 73 74 | |
ksp_flef(state, params)
K-Shortest Path, First-Last-Exact-Fit. Only suitable for RSA/RMSA. On the shortest available path: small requests take the lowest exactly-fitting free block, falling back to first-fit; large requests take the highest exactly-fitting free block, falling back to last-fit. Combines the size-class segregation of first-last-fit with exact-fit's fragment avoidance. Reference: Chatterjee, Fadini & Oki, "A spectrum allocation scheme based on first-last-exact fit policy for elastic optical networks", JNCA 68, 2016.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
ksp_flf(state, params)
K-Shortest Path, First-Last-Fit. On the shortest available path, allocate small requests first-fit (from the low end of the spectrum) and large requests last-fit (from the high end). Requests are "large" if their datarate exceeds the midpoint of the requestable range. Segregating request sizes to opposite spectrum ends reduces the size-mismatch fragmentation that a single first-fit pointer creates. Reference: Fadini & Oki, "A subcarrier-slot partition scheme for wavelength assignment in elastic optical networks", IEEE ICC 2014; Chatterjee, Sarma & Oki, IEEE Comms. Surveys & Tutorials 17(3), 2015.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
ksp_lf(state, params)
Get the last available slot on the shortest available path Method: Go through action mask and find the last available slot, starting from shortest path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
ksp_mscl(state, params)
K-Shortest Path, Minimum Slot-continuity Capacity Loss (MSCL). Only suitable for RSA/RMSA.
Path selection follows KSP order (first candidate path with any valid slot, exactly as in ksp_ff); the slot on that path is then chosen to minimise the slot-continuity capacity loss. In short: every placement destroys some of the network's remaining ability to host future contiguous-slot requests - on the chosen route and on every route sharing a link with it. MSCL evaluates that destruction exactly, one step ahead, for every candidate slot, and picks the placement that destroys least. See capacity_loss for the metric definition, the closed-form computation, and full references.
The loss is accounted over the first --mscl_interfering_k stored routes of every node pair sharing a link with the candidate path (0 = all k_paths). With the default of 1 this is the single-route interfering set of the original 2013 formulation; with 0 it is the multi-route set of dos Santos (2021), whose MSCL Sequencial is exactly this heuristic (sequential route choice, min-loss slot). Cost scales linearly with the interfering-set size.
References
R. C. Almeida Jr. et al., "Slot assignment strategy to reduce loss of capacity of contiguous-slot path requests in flexible grid optical networks", Electronics Letters 49(5), 2013, doi:10.1049/el.2012.4247. M. L. dos Santos, "Abordagens para atribuicao de espectro em redes opticas elasticas baseadas em perda de capacidade sob multiplas rotas", M.Sc. dissertation, Universidade Federal de Pernambuco, Recife, 2021, sec. 3.1 (MSCL Sequencial). https://repositorio.ufpe.br/handle/123456789/45594
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
ksp_mu(state, params, unique_lightpaths, relative)
Get the most-used slot on the shortest available path. Method: Go through action mask and find the utilisation of available slots on each path. Find the shortest available path and choose the most utilised slot on that path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
unique_lightpaths
|
bool
|
Whether to consider unique lightpaths |
required |
relative
|
bool
|
Whether to return relative utilisation |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
last_fit(state, params)
Last-Fit Spectrum Allocation. Returns the last fit slot for each path.
When band_slot_order_lf is set (GN model envs with --band_preference), slots are searched in band preference order (descending within each band).
Source code in xlron/heuristics/heuristics.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 | |
lf_ksp(state, params)
Get the last available slot from all paths Method: Go through action mask and find the last available slot on all paths
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
most_used(state, params, unique_lightpaths, relative)
Get the amount of utilised bandwidth on each lightpath. If RWA-LR environment, the utilisation of a slot is defined by either the count of unique active lightpahts on the slot (if unique_lightpaths is True) or the count of active lightpaths on the slot (if unique_lightpaths is False). If RSA-type environment, utilisation is the count of active lightpaths on that slot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
unique_lightpaths
|
bool
|
Whether to consider unique lightpaths |
required |
relative
|
bool
|
Whether to return relative utilisation |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Most used slots (array length = link_resources) |
Source code in xlron/heuristics/heuristics.py
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 | |
mscl_ksp(state, params)
Minimum Slot-continuity Capacity Loss (MSCL) across K-Shortest Paths. Only suitable for RSA/RMSA.
Jointly selects the (path, slot) pair minimising the slot-continuity capacity loss over all k candidate paths and all slots - i.e. routing and spectrum assignment are decided together by the same one-step-lookahead metric, rather than fixing the path first as ksp_mscl does. Ties break to the shortest path, then the lowest slot index. See capacity_loss for the metric definition, the closed-form computation, and full references.
The loss is accounted over the first --mscl_interfering_k stored routes of every node pair sharing a link with the candidate path (0 = all k_paths). With the default of 1 this is the single-route interfering set of the original 2013 formulation; with 0 it is the multi-route set of dos Santos (2021), whose MSCL Combinado is exactly this heuristic (joint route-slot choice; the flowchart's strict-improvement scan over routes and slots in order yields the same tie-breaks as the flattened argmin here). Cost scales linearly with the interfering-set size.
References
R. C. Almeida Jr. et al., Electronics Letters 49(5), 2013, doi:10.1049/el.2012.4247 (see ksp_mscl). M. L. dos Santos, M.Sc. dissertation, Universidade Federal de Pernambuco, Recife, 2021, sec. 3.2 (MSCL Combinado). https://repositorio.ufpe.br/handle/123456789/45594
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
mu_ksp(state, params, unique_lightpaths, relative)
Use the most-used available slot on any path. The most-used slot is that which has the most unique lightpaths (if unique_lightpaths=True) or active lightpaths. Method: Go through action mask and find the usage of available slots, choose available slot that is most utilised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
EnvState
|
Environment state |
required |
params
|
EnvParams
|
Environment parameters |
required |
unique_lightpaths
|
bool
|
Whether to consider unique lightpaths |
required |
relative
|
bool
|
Whether to return relative utilisation |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Array |
Array
|
Action |
Source code in xlron/heuristics/heuristics.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |