Skip to content

Commit d584ac5

Browse files
TarrySinghclaude
andcommitted
Make the three C lessons compile on Linux, and mask every machine measurement
The first Linux CI run failed three compiled lessons that pass on macOS: F15-L06, P02-L10 and P04-L06 call clock_gettime(CLOCK_MONOTONIC) under -std=c11, and glibc hides POSIX from a strict ISO C build unless it is asked for before the first header. macOS shows it regardless. Each now defines _DEFAULT_SOURCE, as P04-L09 already did; stub and solution scores unchanged. The reproducibility check also relied on luck for 13 lines: timings it only masked when two runs happened to differ. F15-L06 prints "us/tick" and F15-L07 "rollouts/s", now recognised as measurements; T03-L02 printed seconds and nanoseconds as bare numbers in table cells, which gate 13 forbids, and now prints them with their units. brand/social-preview.png: the 1280 x 640 card for sharing the repository, drawn by tools/brand_lockups.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent eab1883 commit d584ac5

12 files changed

Lines changed: 105 additions & 21 deletions

File tree

‎brand/social-preview.png‎

69.5 KB
Loading

‎flagships/humanoid-lab/lessons/F15-L06-control-loop-in-c/lesson.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// watch the TODOs turn into PASSes. Everything below the three exercises is the harness; it
99
// is given, and it is worth reading, because it is the shape every control loop has.
1010

11+
/* clock_gettime and CLOCK_MONOTONIC are POSIX, not ISO C. Under -std=c11, glibc (Linux)
12+
hides them unless asked before the first header; macOS shows them regardless. */
13+
#define _DEFAULT_SOURCE
1114
#include <mujoco/mujoco.h>
1215

1316
#include <math.h>

‎flagships/humanoid-lab/lessons/F15-L06-control-loop-in-c/solutions/lesson.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//
66
// make SRC=solutions/lesson.c BIN=solutions/lesson_bin test
77

8+
/* clock_gettime and CLOCK_MONOTONIC are POSIX, not ISO C. Under -std=c11, glibc (Linux)
9+
hides them unless asked before the first header; macOS shows them regardless. */
10+
#define _DEFAULT_SOURCE
811
#include <mujoco/mujoco.h>
912

1013
#include <math.h>

‎lessons/T03-L02-bpe-merge-loop-in-cpp/lesson.ipynb‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@
375375
{
376376
"cell_type": "code",
377377
"execution_count": null,
378-
"id": "dab1775e0dda",
378+
"id": "293502b9957b",
379379
"metadata": {},
380380
"outputs": [],
381381
"source": [
@@ -396,10 +396,10 @@
396396
"\n",
397397
"\n",
398398
"if __name__ == \"__main__\":\n",
399-
" print(f\"{'bytes':>8} {'symbols':>9} {'seconds':>8} {'ns/symbol/merge':>16}\")\n",
399+
" print(f\"{'bytes':>8} {'symbols':>9} {'time':>9} {'per symbol, per merge':>22}\")\n",
400400
" for _row in python_scaling():\n",
401-
" print(f\"{_row['bytes']:8d} {_row['symbols']:9d} {_row['seconds']:8.3f}\"\n",
402-
" f\" {_row['ns_per_symbol_per_merge']:16.1f}\")\n",
401+
" print(f\"{_row['bytes']:8d} {_row['symbols']:9d} {_row['seconds']:7.3f} s\"\n",
402+
" f\" {_row['ns_per_symbol_per_merge']:19.1f} ns\")\n",
403403
" print(\"\\nSeconds roughly double when the corpus doubles. The last column is flat, and it\")\n",
404404
" print(\"is the constant you are about to attack: the cost of one symbol, one time, here.\")"
405405
]
@@ -921,7 +921,7 @@
921921
{
922922
"cell_type": "code",
923923
"execution_count": null,
924-
"id": "f978bb688e2c",
924+
"id": "d058e7643bb7",
925925
"metadata": {
926926
"lines_to_next_cell": 1
927927
},
@@ -945,10 +945,10 @@
945945
" cpp_rows = cpp_scaling()\n",
946946
" py_rows = python_scaling()\n",
947947
" print(\"per symbol, per merge — the only column that can tell a constant from a curve\")\n",
948-
" print(f\"{'symbols':>9} {'python ns':>11} {'c++ ns':>9} {'ratio':>9}\")\n",
948+
" print(f\"{'symbols':>9} {'python':>11} {'c++':>11} {'ratio':>9}\")\n",
949949
" for p, c in zip(py_rows, cpp_rows):\n",
950-
" print(f\"{c['symbols']:9d} {p['ns_per_symbol_per_merge']:11.1f}\"\n",
951-
" f\" {c['ns_per_symbol_per_merge']:9.1f}\"\n",
950+
" print(f\"{c['symbols']:9d} {p['ns_per_symbol_per_merge']:8.1f} ns\"\n",
951+
" f\" {c['ns_per_symbol_per_merge']:8.1f} ns\"\n",
952952
" f\" {p['ns_per_symbol_per_merge'] / c['ns_per_symbol_per_merge']:8.1f}x\")\n",
953953
" print(\"\\nRead the two middle columns DOWN, not across. Each is roughly flat as the corpus\")\n",
954954
" print(\"grows, and that flatness is the straight line — the same line in both languages.\")\n",

‎lessons/T03-L02-bpe-merge-loop-in-cpp/lesson.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,10 @@ def python_scaling(fractions=(0.25, 0.5, 1.0), merges: int = 30) -> list:
337337

338338

339339
if __name__ == "__main__":
340-
print(f"{'bytes':>8} {'symbols':>9} {'seconds':>8} {'ns/symbol/merge':>16}")
340+
print(f"{'bytes':>8} {'symbols':>9} {'time':>9} {'per symbol, per merge':>22}")
341341
for _row in python_scaling():
342-
print(f"{_row['bytes']:8d} {_row['symbols']:9d} {_row['seconds']:8.3f}"
343-
f" {_row['ns_per_symbol_per_merge']:16.1f}")
342+
print(f"{_row['bytes']:8d} {_row['symbols']:9d} {_row['seconds']:7.3f} s"
343+
f" {_row['ns_per_symbol_per_merge']:19.1f} ns")
344344
print("\nSeconds roughly double when the corpus doubles. The last column is flat, and it")
345345
print("is the constant you are about to attack: the cost of one symbol, one time, here.")
346346

@@ -788,10 +788,10 @@ def _show_scaling() -> None:
788788
cpp_rows = cpp_scaling()
789789
py_rows = python_scaling()
790790
print("per symbol, per merge — the only column that can tell a constant from a curve")
791-
print(f"{'symbols':>9} {'python ns':>11} {'c++ ns':>9} {'ratio':>9}")
791+
print(f"{'symbols':>9} {'python':>11} {'c++':>11} {'ratio':>9}")
792792
for p, c in zip(py_rows, cpp_rows):
793-
print(f"{c['symbols']:9d} {p['ns_per_symbol_per_merge']:11.1f}"
794-
f" {c['ns_per_symbol_per_merge']:9.1f}"
793+
print(f"{c['symbols']:9d} {p['ns_per_symbol_per_merge']:8.1f} ns"
794+
f" {c['ns_per_symbol_per_merge']:8.1f} ns"
795795
f" {p['ns_per_symbol_per_merge'] / c['ns_per_symbol_per_merge']:8.1f}x")
796796
print("\nRead the two middle columns DOWN, not across. Each is roughly flat as the corpus")
797797
print("grows, and that flatness is the straight line — the same line in both languages.")

‎lessons/T03-L02-bpe-merge-loop-in-cpp/solutions/lesson_solution.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ def python_scaling(fractions=(0.25, 0.5, 1.0), merges: int = 30) -> list:
252252

253253

254254
if __name__ == "__main__":
255-
print(f"{'bytes':>8} {'symbols':>9} {'seconds':>8} {'ns/symbol/merge':>16}")
255+
print(f"{'bytes':>8} {'symbols':>9} {'time':>9} {'per symbol, per merge':>22}")
256256
for _row in python_scaling():
257-
print(f"{_row['bytes']:8d} {_row['symbols']:9d} {_row['seconds']:8.3f}"
258-
f" {_row['ns_per_symbol_per_merge']:16.1f}")
257+
print(f"{_row['bytes']:8d} {_row['symbols']:9d} {_row['seconds']:7.3f} s"
258+
f" {_row['ns_per_symbol_per_merge']:19.1f} ns")
259259
print("\nSeconds roughly double when the corpus doubles. The last column is flat, and it")
260260
print("is the constant you are about to attack: the cost of one symbol, one time, here.")
261261

@@ -631,10 +631,10 @@ def _show_scaling() -> None:
631631
cpp_rows = cpp_scaling()
632632
py_rows = python_scaling()
633633
print("per symbol, per merge — the only column that can tell a constant from a curve")
634-
print(f"{'symbols':>9} {'python ns':>11} {'c++ ns':>9} {'ratio':>9}")
634+
print(f"{'symbols':>9} {'python':>11} {'c++':>11} {'ratio':>9}")
635635
for p, c in zip(py_rows, cpp_rows):
636-
print(f"{c['symbols']:9d} {p['ns_per_symbol_per_merge']:11.1f}"
637-
f" {c['ns_per_symbol_per_merge']:9.1f}"
636+
print(f"{c['symbols']:9d} {p['ns_per_symbol_per_merge']:8.1f} ns"
637+
f" {c['ns_per_symbol_per_merge']:8.1f} ns"
638638
f" {p['ns_per_symbol_per_merge'] / c['ns_per_symbol_per_merge']:8.1f}x")
639639
print("\nRead the two middle columns DOWN, not across. Each is roughly flat as the corpus")
640640
print("grows, and that flatness is the straight line — the same line in both languages.")

‎programmes/document-intelligence/lessons/P02-L10-streaming-scanner-in-c/lesson.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
* of the notebook measure both on your machine, and those measured numbers are the only ones
1717
* you should ever quote.
1818
*/
19+
/* clock_gettime and CLOCK_MONOTONIC are POSIX, not ISO C. Under -std=c11, glibc (Linux)
20+
hides them unless asked before the first header; macOS shows them regardless. */
21+
#define _DEFAULT_SOURCE
1922
#include <stdbool.h>
2023
#include <stdint.h>
2124
#include <stdio.h>

‎programmes/document-intelligence/lessons/P02-L10-streaming-scanner-in-c/solutions/lesson.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
* of the notebook measure both on your machine, and those measured numbers are the only ones
1717
* you should ever quote.
1818
*/
19+
/* clock_gettime and CLOCK_MONOTONIC are POSIX, not ISO C. Under -std=c11, glibc (Linux)
20+
hides them unless asked before the first header; macOS shows them regardless. */
21+
#define _DEFAULT_SOURCE
1922
#include <stdbool.h>
2023
#include <stdint.h>
2124
#include <stdio.h>

‎programmes/model-risk/lessons/P04-L06-reproduce-the-number-in-c/lesson.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
// Moved or copied this checkout? Run `make clean` first. See the common-mistakes section of
1313
// the notebook for why.
1414

15+
/* clock_gettime and CLOCK_MONOTONIC are POSIX, not ISO C. Under -std=c11, glibc (Linux)
16+
hides them unless asked before the first header; macOS shows them regardless. */
17+
#define _DEFAULT_SOURCE
1518
#include <float.h>
1619
#include <math.h>
1720
#include <setjmp.h>

‎programmes/model-risk/lessons/P04-L06-reproduce-the-number-in-c/solutions/lesson.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//
66
// make SRC=solutions/lesson.c BIN=solutions/lesson_bin test
77

8+
/* clock_gettime and CLOCK_MONOTONIC are POSIX, not ISO C. Under -std=c11, glibc (Linux)
9+
hides them unless asked before the first header; macOS shows them regardless. */
10+
#define _DEFAULT_SOURCE
811
#include <float.h>
912
#include <math.h>
1013
#include <setjmp.h>

0 commit comments

Comments
 (0)