API Reference
microfuel
¤
AircraftType
module-attribute
¤
AircraftType: TypeAlias = Literal[
"A20N",
"A320",
"A359",
"B788",
"B738",
"A332",
"A21N",
"A321",
"B789",
"B77W",
"A333",
"B772",
"B744",
"B737",
"B739",
"B38M",
"A319",
"A306",
"A388",
"B752",
"B748",
"B77L",
"B763",
"MD11",
"B39M",
"A318",
]
AIRCRAFT_TYPES
module-attribute
¤
AIRCRAFT_TYPES: tuple[AircraftType, ...] = get_args(
AircraftType
)
Partition
module-attribute
¤
Coordinate2D
¤
Bases: NamedTuple, Generic[_T]
Source code in src/microfuel/__init__.py
60 61 62 | |
dataloader
¤
SequenceInfo
module-attribute
¤
SequenceInfo = namedtuple(
"SequenceInfo",
[
"flight_indices",
"segment_indices_relative",
"target",
"segment_id",
"aircraft_type_idx",
"duration_s",
"flight_id",
],
)
Sequence
module-attribute
¤
Sequence = namedtuple(
"Sequence",
[
"features_flight",
"features_segment",
"target",
"segment_id",
"aircraft_type_idx",
"duration_s",
"flight_id",
],
)
VarlenBatch
module-attribute
¤
VarlenBatch = namedtuple(
"VarlenBatch",
[
"x_flight",
"cu_seqlens_flight",
"x_segment",
"cu_seqlens_segment",
"y",
"segment_ids",
"aircraft_type_idx",
"durations",
],
)
VarlenDataset
¤
Bases: Dataset
Source code in src/microfuel/dataloader.py
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 | |
ac_type_vocab
instance-attribute
¤
ac_type_vocab = {
ac_type: i
for i, ac_type in (enumerate(AIRCRAFT_TYPES))
}
class_counts
instance-attribute
¤
__init__
¤
Source code in src/microfuel/dataloader.py
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 | |
__len__
¤
__len__() -> int
Source code in src/microfuel/dataloader.py
212 213 | |
__getitem__
¤
Source code in src/microfuel/dataloader.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |
collate_fn
¤
collate_fn(batch_sequences: list[Sequence]) -> VarlenBatch
Source code in src/microfuel/dataloader.py
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 | |
datasets
¤
preprocessed
¤
MODEL_INPUT_FEATURES
module-attribute
¤
MODEL_INPUT_FEATURES: list[str] = [
*FLIGHT_FEATURES,
*STATE_FEATURES,
]
SmoothResult
module-attribute
¤
SmoothResult = namedtuple(
"SmoothResult", ["val", "val_d", "var_val", "var_val_d"]
)
Stat
¤
IteratorData
¤
Bases: NamedTuple
Source code in src/microfuel/datasets/preprocessed.py
1095 1096 1097 | |
TrajectoryInfo
¤
Bases: TypedDict
Source code in src/microfuel/datasets/preprocessed.py
1140 1141 1142 1143 1144 1145 1146 1147 1148 | |
Trajectory
¤
Bases: NamedTuple
Source code in src/microfuel/datasets/preprocessed.py
1151 1152 1153 | |
TrajectoryIterator
¤
Yields the entire flight trajectory for each segment as polars DataFrames.
Source code in src/microfuel/datasets/preprocessed.py
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 | |
segment_infos
instance-attribute
¤
segment_infos: list[TrajectoryInfo] = (
it_data.segments_df.to_dicts()
)
segments_by_flight
instance-attribute
¤
segments_by_flight: dict[
FlightId, list[TrajectoryInfo]
] = {}
flight_ids_to_iterate
instance-attribute
¤
flight_ids_to_iterate = list(self.segments_by_flight.keys())
__init__
¤
__init__(
partition: Partition,
*,
segment_ids: Collection[SegmentId] | None = None,
shuffle_seed: int | None = None,
stats: Stats | None = None,
start_to_end_only: bool = False,
path_base: Path = PATH_PREPROCESSED,
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_to_end_only
|
bool
|
if False, yields the entire materialised flight trajectory. Note that collecting this iterator will use a lot of memory due to duplicates! Prefer using the torch iterator instead. |
False
|
Source code in src/microfuel/datasets/preprocessed.py
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 | |
__len__
¤
__len__() -> int
Source code in src/microfuel/datasets/preprocessed.py
1189 1190 | |
__iter__
¤
__iter__() -> Iterator[Trajectory]
Source code in src/microfuel/datasets/preprocessed.py
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 | |
make_splits
¤
make_splits(
partition: Partition,
train_split: float = 0.8,
seed: int = 13,
*,
path_base: Path = PATH_PREPROCESSED,
max_bins: int = 30,
min_samples_for_binning: int = 2,
)
Source code in src/microfuel/datasets/preprocessed.py
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 | |
find_segment_indices
¤
find_segment_indices(
timestamps, start_time, end_time, *, xp=np
)
Source code in src/microfuel/datasets/preprocessed.py
206 207 208 209 | |
smooth_time_series
¤
smooth_time_series(
values,
dts_s,
process_noise_variances: tuple[float, float],
observation_noise_variance: float,
gap_threshold: float = 30.0,
) -> SmoothResult
Applies a Kalman filter and RTS smoother to a 1D time series, handling large gaps.
Assumes the time series follow a Constant Velocity (CV) system: \(x_k = F x_{k-1} + w_k\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_noise_variances
|
tuple[float, float]
|
(pos, vel) variances for the model's state transition noise (Q). |
required |
observation_noise_variance
|
float
|
variance for the measurement noise (R). |
required |
gap_threshold
|
float
|
time gap (in seconds) above which to split the time series into chunks. |
30.0
|
Source code in src/microfuel/datasets/preprocessed.py
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 | |
make_trajectories
¤
make_trajectories(
partition: Partition,
seed: int = 13,
*,
path_base: Path = PATH_PREPROCESSED,
altitude_max: Annotated[
float, isqx.aerospace.PRESSURE_ALTITUDE(isqx.M)
] = ft2m(50000),
speed_max: Annotated[
float, isqx.SPEED(isqx.M_PERS)
] = knot2mps(800),
vertical_speed_max: Annotated[
float, isqx.aerospace.VS(isqx.M_PERS)
] = fpm2mps(8000),
track_rate_max: Annotated[float, isqx.RAD_PERS] = 0.003,
plot_every_n_flights: int | None = None,
)
Creates train/validation split of preprocessed trajectories.
Handles the alignment of asynchronous data sources:
- Flight List: [takeoff, landing] constraints.
- Fuel Data: segment boundaries.
- ADS-B + ACARS: raw state observations.
It produces the standard state vector \(x_t\) required by
microfuel.model.FuelBurnPredictor.
Everything related to segments (e.g. whether a particular state vector is within [start, end]) should be handled elsewhere. This function processes the entire trajectory.
Source code in src/microfuel/datasets/preprocessed.py
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 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 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | |
altitude_to_pressure_std
¤
altitude_to_pressure_std(altitude_m)
Source code in src/microfuel/datasets/preprocessed.py
763 764 765 | |
make_era5
¤
make_era5(
partition: Partition,
*,
path_base: Path = PATH_PREPROCESSED,
path_raw_weather: Path = PATH_DATA_RAW / "era5",
)
Source code in src/microfuel/datasets/preprocessed.py
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 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 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 | |
make_derived_features
¤
make_derived_features(
partition: Partition,
*,
path_base: Path = PATH_PREPROCESSED,
)
Warning
This function is unused. Integration of weather features is planned for the future
Source code in src/microfuel/datasets/preprocessed.py
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 | |
make_standardisation_stats
¤
make_standardisation_stats(
partition: Partition,
*,
path_base: Path = PATH_PREPROCESSED,
)
Source code in src/microfuel/datasets/preprocessed.py
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 1072 1073 | |
load_splits
¤
load_splits(
partition: Partition,
*,
path_base: Path = PATH_PREPROCESSED,
) -> dict[Split, list[SegmentId]]
Source code in src/microfuel/datasets/preprocessed.py
1081 1082 1083 1084 1085 | |
load_standardisation_stats
¤
load_standardisation_stats(
partition: Partition,
*,
path_base: Path = PATH_PREPROCESSED,
) -> Stats
Source code in src/microfuel/datasets/preprocessed.py
1088 1089 1090 1091 1092 | |
prepare_iterator_data
¤
prepare_iterator_data(
partition: Partition,
segment_ids: Collection[SegmentId] | None = None,
stats: Stats | None = None,
path_base: Path = PATH_PREPROCESSED,
) -> IteratorData
Prepares data required by the dataloader.
Source code in src/microfuel/datasets/preprocessed.py
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 | |
raw
¤
Config
¤
Bases: TypedDict
Source code in src/microfuel/datasets/raw.py
19 20 21 22 23 | |
FuelRecord
¤
Bases: TypedDict
Fuel consumption data for a given flight interval. Path: fuel_{partition}.parquet.
Source code in src/microfuel/datasets/raw.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
flight_id
instance-attribute
¤
Links to the flight list and trajectory.
start
instance-attribute
¤
The start timestamp of the interval (usually an ACARS report).
end
instance-attribute
¤
The end timestamp of the interval.
fuel_kg
instance-attribute
¤
The target variable.
Warning
Note that this variable has quantisation artifacts: data is not a simple continuous distribution but a composite from at least two distinct sources: imperial (pounds) and metric (kilograms) units with a 2sf rounding step.
FlightListRecord
¤
Bases: TypedDict
Metadata for each flight in the dataset. Path: flight_list_{partition}.parquet.
Source code in src/microfuel/datasets/raw.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
flight_id
instance-attribute
¤
A unique identifier for the flight.
takeoff
instance-attribute
¤
The timestamp of takeoff.
landed
instance-attribute
¤
The timestamp of landing.
origin_icao
instance-attribute
¤
origin_icao: Annotated[AirportIcao, pl.Utf8]
ICAO code for the departure airport.
destination_icao
instance-attribute
¤
destination_icao: Annotated[AirportIcao, pl.Utf8]
ICAO code for the destination airport.
AirportRecord
¤
Bases: TypedDict
Airport metadata. Path: apt.parquet.
Source code in src/microfuel/datasets/raw.py
128 129 130 131 132 133 134 | |
TrajectoryRecord
¤
Bases: TypedDict
Flight trajectory data points. Path: flights_{partition}/{flight_id}.parquet.
Source code in src/microfuel/datasets/raw.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 197 198 199 200 201 202 203 204 205 206 | |
timestamp
instance-attribute
¤
latitude
instance-attribute
¤
Latitude, encoded via Compact Positional Reporting (CPR, tc=9-18, 20-22) We do not have access to uncertainty/quantisation, can be anywhere from:
- navigational integrity category: nic=11 (rc < 7.5m)..nic=8 (rc < 185m)
- navigational accuracy category: nacp=10 (epu < 10m)..nacp=8 (epu < 93m)
longitude
instance-attribute
¤
altitude
instance-attribute
¤
Barometric altitude (tc=9-18, 12-bit field). Not to be confused with GNSS altitude (tc=20-22)
Quantisation: 'q' bit (bit 8 of the field): - q=1: 25-foot increments. altitude = (decimal value of 11 bits) * 25 - 1000 ft. - q=0: 100-foot increments, using gray code for altitudes > 50,175 ft.
Uncertainty: depends on barometric altitude quality (baq).
groundspeed
instance-attribute
¤
Ground speed (GNSS or inertial reference system, tc=19, subtypes1-2).
Not transmitted directly, encoded as two signed velocity components (east-west velocity, north-south velocity):
- groundspeed = sqrt(vew^2 + vns^2)
- track angle = atan2(vew, vns)
Quantisation: 1 kt (subsonic), 4 kt (supersonic). Uncertainty: nacv=4 (< 0.3m/s), nacv=3 (< 1.0m/s), nacv=2 (< 3.0m/s), nacv=1 (< 10.0m/s)
vertical_rate
instance-attribute
¤
vertical_rate: (
Annotated[
float,
pl.Float64,
isqx.aerospace.VS(isqx.usc.FT * isqx.MIN**-1),
]
| None
)
Vertical rate (vrsrc specifies origin: GNSS or barometric, tc=19).
a sign bit indicates climb or descent. a 9-bit value (vr) encodes the magnitude. vertical speed (ft/min) = 64 * (vr - 1).
Uncertainty: linked to vertical component of nacv.
mach
instance-attribute
¤
mach: Annotated[float, pl.Float64, isqx.MACH_NUMBER] | None
Mach number (Mode S, BDS 6,0, 10 bits, mb 25-34).
Quantisation: 0.004.
TAS
instance-attribute
¤
True airspeed.
- ADS-B (tc=19, subtype 3/4) - Quantisation: 1 kt (subtype 3), 4 kt (subtype 4).
- Mode S (BDS 5,0 track and turn report, 10 bits, mb 47-56) - Quantisation: 2 kt
CAS
instance-attribute
¤
Calibrated airspeed. Not broadcast, but likely derived from indicated airspeed (BDS 6,0).
Quantisation: 1 kt.
source
instance-attribute
¤
Data source.
Data from adsb and acars have different characteristics.
acars data, for instance, may include mach, TAS, and CAS,
which are not present in standard ADS-B reports.
artificial data points are inserted from microfuel.datasets.raw.FlightListRecord to aid
interpolation.
SubmissionRecord
¤
Bases: TypedDict
Source code in src/microfuel/datasets/raw.py
227 228 229 230 231 | |
load_config
¤
Source code in src/microfuel/datasets/raw.py
26 27 28 29 30 31 32 | |
setup_mc_alias
¤
setup_mc_alias(
bucket_access_key: str,
bucket_access_secret: str,
endpoint_url: str = "https://s3.opensky-network.org:443",
alias_name: str = "prc25",
) -> int
Source code in src/microfuel/datasets/raw.py
35 36 37 38 39 40 41 42 | |
download_from_s3
¤
download_from_s3(
bucket_access_key: str,
bucket_access_secret: str,
*,
path_out: Path = PATH_DATA_RAW,
bucket_name: str = "prc-2025-datasets",
endpoint_url: str = "https://s3.opensky-network.org:443",
alias_name: str = "prc2025",
) -> int
Download data from S3 using MinIO client. Not using boto3 because it is extremely slow.
Source code in src/microfuel/datasets/raw.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
scan_fuel
¤
scan_fuel(
partition: Partition = "phase1",
*,
path_base: Path = PATH_DATA_RAW,
) -> Annotated[pl.LazyFrame, FuelRecord]
Source code in src/microfuel/datasets/raw.py
90 91 92 93 94 95 96 97 | |
scan_flight_list
¤
scan_flight_list(
partition: Partition = "phase1",
*,
path_base: Path = PATH_DATA_RAW,
) -> Annotated[pl.LazyFrame, FlightListRecord]
Source code in src/microfuel/datasets/raw.py
118 119 120 121 122 123 124 125 | |
scan_airports
¤
scan_airports(
*, path_base: Path = PATH_DATA_RAW
) -> Annotated[pl.LazyFrame, AirportRecord]
Source code in src/microfuel/datasets/raw.py
137 138 139 | |
scan_all_trajectories
¤
scan_all_trajectories(
partition: Partition = "phase1",
*,
path_base: Path = PATH_DATA_RAW,
) -> Annotated[pl.LazyFrame, TrajectoryRecord]
Source code in src/microfuel/datasets/raw.py
209 210 211 212 213 214 215 | |
scan_trajectory
¤
scan_trajectory(
flight_id: str,
partition: Partition = "phase1",
*,
path_base: Path = PATH_DATA_RAW,
) -> Annotated[pl.LazyFrame, TrajectoryRecord]
Source code in src/microfuel/datasets/raw.py
218 219 220 221 222 223 224 | |
hacks
¤
Vendored and patched versions of flash-linear-attention.
To avoid recompilation during variable-length training, we make the following changes:
-
Causal Conv1D (https://github.com/fla-org/flash-linear-attention/blob/main/fla/modules/convolution.py)
-
NBremoved from autotune key NBremoved from constexpr list in signature (kept as scalar)-
BTfixed to 64 in wrappers -
L2Norm (https://github.com/fla-org/flash-linear-attention/blob/main/fla/modules/l2norm.py)
-
NBremoved from autotune key NBremoved from constexpr in signature-
Tremoved from constexpr in signature -
GatedNorm (https://github.com/fla-org/flash-linear-attention/blob/main/fla/modules/fused_norm_gate.py)
-
NBremoved from autotune key NBremoved from constexpr in signature
NUM_WARPS_AUTOTUNE
module-attribute
¤
NUM_WARPS_AUTOTUNE = (
[2, 4, 8, 16] if is_amd else [4, 8, 16, 32]
)
causal_conv1d_fwd_kernel
¤
causal_conv1d_fwd_kernel(
x,
y,
weight,
bias,
residual,
cu_seqlens,
initial_state,
chunk_indices,
B,
T,
D: tl.constexpr,
W: tl.constexpr,
BT: tl.constexpr,
BW: tl.constexpr,
BD: tl.constexpr,
NB,
ACTIVATION: tl.constexpr,
HAS_WEIGHT: tl.constexpr,
HAS_BIAS: tl.constexpr,
HAS_RESIDUAL: tl.constexpr,
USE_INITIAL_STATE: tl.constexpr,
IS_VARLEN: tl.constexpr,
)
Source code in src/microfuel/hacks.py
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 | |
causal_conv1d_bwd_kernel
¤
causal_conv1d_bwd_kernel(
x,
y,
weight,
initial_state,
dh0,
dht,
dy,
dx,
dw,
db,
cu_seqlens,
chunk_indices,
B,
T,
D: tl.constexpr,
W: tl.constexpr,
BT: tl.constexpr,
BW: tl.constexpr,
BD: tl.constexpr,
NB,
ACTIVATION: tl.constexpr,
HAS_WEIGHT: tl.constexpr,
HAS_BIAS: tl.constexpr,
USE_INITIAL_STATE: tl.constexpr,
USE_FINAL_STATE: tl.constexpr,
IS_VARLEN: tl.constexpr,
)
Source code in src/microfuel/hacks.py
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 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 | |
causal_conv1d_fwd
¤
causal_conv1d_fwd(
x: torch.Tensor,
weight: torch.Tensor,
bias: torch.Tensor,
residual: torch.Tensor,
initial_state: torch.Tensor | None = None,
output_final_state: bool = False,
activation: str | None = None,
cu_seqlens: torch.Tensor | None = None,
) -> torch.Tensor
Source code in src/microfuel/hacks.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 | |
causal_conv1d_bwd
¤
causal_conv1d_bwd(
x: torch.Tensor,
dy: torch.Tensor,
dht: torch.Tensor,
weight: torch.Tensor | None = None,
bias: torch.Tensor | None = None,
residual: torch.Tensor | None = None,
initial_state: torch.Tensor | None = None,
activation: str | None = None,
cu_seqlens: torch.Tensor | None = None,
)
Source code in src/microfuel/hacks.py
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 | |
l2norm_fwd_kernel
¤
l2norm_fwd_kernel(
x,
y,
rstd,
eps,
T,
D: tl.constexpr,
BD: tl.constexpr,
NB,
BT: tl.constexpr,
)
Source code in src/microfuel/hacks.py
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 | |
l2norm_bwd_kernel
¤
l2norm_bwd_kernel(
y,
rstd,
dy,
dx,
eps,
T,
D: tl.constexpr,
BD: tl.constexpr,
NB,
BT: tl.constexpr,
)
Source code in src/microfuel/hacks.py
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 | |
l2norm_fwd
¤
l2norm_fwd(
x: torch.Tensor,
eps: float = 1e-06,
output_dtype: torch.dtype | None = None,
)
Source code in src/microfuel/hacks.py
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 | |
l2norm_bwd
¤
l2norm_bwd(
y: torch.Tensor,
rstd: torch.Tensor,
dy: torch.Tensor,
eps: float = 1e-06,
)
Source code in src/microfuel/hacks.py
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 | |
layer_norm_gated_fwd_kernel
¤
layer_norm_gated_fwd_kernel(
x,
g,
y,
w,
b,
residual,
residual_out,
mean,
rstd,
eps,
T,
D: tl.constexpr,
BT: tl.constexpr,
BD: tl.constexpr,
NB,
ACTIVATION: tl.constexpr,
IS_RMS_NORM: tl.constexpr,
STORE_RESIDUAL_OUT: tl.constexpr,
HAS_RESIDUAL: tl.constexpr,
HAS_WEIGHT: tl.constexpr,
HAS_BIAS: tl.constexpr,
)
Source code in src/microfuel/hacks.py
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 | |
layer_norm_gated_bwd_kernel
¤
layer_norm_gated_bwd_kernel(
x,
g,
w,
b,
y,
dy,
dx,
dg,
dw,
db,
dresidual,
dresidual_in,
mean,
rstd,
T,
BS,
D: tl.constexpr,
BT: tl.constexpr,
BD: tl.constexpr,
NB,
ACTIVATION: tl.constexpr,
IS_RMS_NORM: tl.constexpr,
STORE_DRESIDUAL: tl.constexpr,
HAS_DRESIDUAL: tl.constexpr,
HAS_WEIGHT: tl.constexpr,
HAS_BIAS: tl.constexpr,
RECOMPUTE_OUTPUT: tl.constexpr,
)
Source code in src/microfuel/hacks.py
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 | |
layer_norm_gated_fwd
¤
layer_norm_gated_fwd(
x: torch.Tensor,
g: torch.Tensor,
weight: torch.Tensor,
bias: torch.Tensor,
activation: str = "swish",
eps: float = 1e-05,
residual: torch.Tensor = None,
out_dtype: torch.dtype = None,
residual_dtype: torch.dtype = None,
is_rms_norm: bool = False,
)
Source code in src/microfuel/hacks.py
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 | |
layer_norm_gated_bwd
¤
layer_norm_gated_bwd(
dy: torch.Tensor,
x: torch.Tensor,
g: torch.Tensor,
weight: torch.Tensor,
bias: torch.Tensor,
activation: str = "swish",
eps: float = 1e-05,
mean: torch.Tensor = None,
rstd: torch.Tensor = None,
dresidual: torch.Tensor = None,
has_residual: bool = False,
is_rms_norm: bool = False,
x_dtype: torch.dtype = None,
recompute_output: bool = False,
)
Source code in src/microfuel/hacks.py
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 | |
install_optimized_kernels_
¤
install_optimized_kernels_()
Patches FLA modules with optimized versions to reduce JIT recompilation.
Source code in src/microfuel/hacks.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 | |
model
¤
ZeroCentredRMSNorm
¤
Bases: nn.Module
Avoids abnormal amplification of some weights in the original QK-norm.
During regularisation and weight decay, weight will be pushed near 0.
See: https://ceramic.ai/blog/zerocentered
Source code in src/microfuel/model.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
__init__
¤
Source code in src/microfuel/model.py
20 21 22 23 | |
forward
¤
forward(hidden_states: torch.Tensor) -> torch.Tensor
Source code in src/microfuel/model.py
25 26 27 28 29 30 | |
Pooler
¤
Bases: nn.Module
Source code in src/microfuel/model.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
__init__
¤
__init__(mode: Literal['mean', 'last'] = 'last')
Source code in src/microfuel/model.py
34 35 36 | |
forward
¤
forward(
x: torch.Tensor, cu_seqlens: torch.Tensor
) -> torch.Tensor
Source code in src/microfuel/model.py
38 39 40 41 42 43 44 45 46 47 | |
LinearAttentionBlock
¤
Bases: nn.Module
Source code in src/microfuel/model.py
50 51 52 53 54 55 56 57 58 59 60 61 62 | |
gdn
instance-attribute
¤
gdn = GatedDeltaNet(
hidden_size=hidden_size,
num_heads=num_heads,
head_dim=head_dim,
)
__init__
¤
Source code in src/microfuel/model.py
51 52 53 54 | |
forward
¤
forward(
x: torch.Tensor, cu_seqlens: torch.Tensor
) -> torch.Tensor
Source code in src/microfuel/model.py
56 57 58 59 60 61 62 | |
StaticHyperNet
¤
Bases: nn.Module
Creates a specialised feature extractor for each aircraft type, improving over feature conditioning (concatenating embeddings to input).
See: https://arxiv.org/pdf/1609.09106#page=3 (Section 3.1).
Source code in src/microfuel/model.py
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 | |
mlp
instance-attribute
¤
mlp = nn.Sequential(
nn.Linear(embedding_dim, 64),
nn.GELU(),
nn.Linear(64, input_dim * output_dim + output_dim),
)
__init__
¤
Source code in src/microfuel/model.py
71 72 73 74 75 76 77 78 79 80 81 82 | |
forward
¤
forward(
aircraft_type_idx: torch.Tensor,
) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Source code in src/microfuel/model.py
84 85 86 87 88 89 90 91 92 | |
FuelBurnPredictorConfig
dataclass
¤
Source code in src/microfuel/model.py
95 96 97 98 99 100 101 102 103 | |
FuelBurnPredictor
¤
Bases: nn.Module
Gated Delta Network for fuel burn estimation.
It processes data at two resolutions to solve the mass identifiability problem:
- Processes the high-fidelity kinematics \(x_{t:t+\Delta}\) for the specific query interval.
- Processes the entire trajectory \(x_{0:T}\) (takeoff to landing).
Hypothesis:
The pooled_flight vector acts as a compressed context containing
implicit estimates of the aircraft's takeoff mass and degradation factors,
which are globally observable over the full flight but locally unobservable.
NOTE: Instead of padding, sequences are tightly packed together in a long tensor, and
FLA is informed of boundaries via the cu_seqlens tensor.
Source code in src/microfuel/model.py
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 | |
hypernetwork_segment
instance-attribute
¤
hypernetwork_segment = StaticHyperNet(
num_aircraft_types=cfg.num_aircraft_types,
embedding_dim=cfg.aircraft_embedding_dim,
input_dim=cfg.input_dim,
output_dim=cfg.hidden_size,
)
layers_segment
instance-attribute
¤
layers_segment = nn.ModuleList(
[
(
LinearAttentionBlock(
cfg.hidden_size, cfg.num_heads, head_dim
)
)
for _ in (range(cfg.num_layers))
]
)
hypernetwork_flight
instance-attribute
¤
hypernetwork_flight = StaticHyperNet(
num_aircraft_types=cfg.num_aircraft_types,
embedding_dim=cfg.aircraft_embedding_dim,
input_dim=cfg.input_dim,
output_dim=cfg.hidden_size,
)
layers_flight
instance-attribute
¤
layers_flight = nn.ModuleList(
[
(
LinearAttentionBlock(
cfg.hidden_size, cfg.num_heads, head_dim
)
)
for _ in (range(cfg.num_layers))
]
)
regression_head
instance-attribute
¤
regression_head = nn.Linear(
cfg.hidden_size
+ cfg.hidden_size
+ cfg.aircraft_embedding_dim,
1,
)
__init__
¤
__init__(cfg: FuelBurnPredictorConfig)
Source code in src/microfuel/model.py
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 | |
forward
¤
forward(
x_flight: torch.Tensor,
cu_seqlens_flight: torch.Tensor,
x_segment: torch.Tensor,
cu_seqlens_segment: torch.Tensor,
aircraft_type_idx: torch.Tensor,
) -> torch.Tensor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_flight
|
torch.Tensor
|
packed tensor of full flight trajectories |
required |
cu_seqlens_flight
|
torch.Tensor
|
cumulative sequence lengths for flight tensor |
required |
x_segment
|
torch.Tensor
|
packed tensor of trajectory segments for prediction |
required |
cu_seqlens_segment
|
torch.Tensor
|
cumulative sequence lengths for segment tensor |
required |
aircraft_type_idx
|
torch.Tensor
|
(B,) tensor of aircraft type indices |
required |
Source code in src/microfuel/model.py
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 | |
plot
¤
default_fig
¤
default_fig(*args, **kwargs) -> Figure
Source code in src/microfuel/plot.py
20 21 22 23 24 25 26 | |