Skip to content

Commit fac7166

Browse files
author
Antigravity Agent
committed
style(benchmark): fix string literal newline in LaTeX output (#415)
- Fixed invalid newline character in benchmark_suite.zig string literal - Reformatted affected files for Zig 0.15 compliance - Build passes, tests pass
1 parent c41af89 commit fac7166

10 files changed

Lines changed: 62 additions & 118 deletions

File tree

.ralph/state/wake_count

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
31
1+
34

.trinity/mu/heartbeat.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"agent":"mu","wake":938,"timestamp":1774536510,"errors_scanned":0,"fixes_applied":0,"build_ok":true,"test_ok":true}
1+
{"agent":"mu","wake":954,"timestamp":1774542018,"errors_scanned":0,"fixes_applied":0,"build_ok":true,"test_ok":true}

.trinity/mu/state/wake_count

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
938
1+
954

.trinity/scholar/heartbeat.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"agent":"scholar","wake":776,"timestamp":1774536460,"fails_found":0,"researched":0,"fed_mu":0}
1+
{"agent":"scholar","wake":785,"timestamp":1774541904,"fails_found":0,"researched":0,"fed_mu":0}

.trinity/scholar/state/wake_count

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
776
1+
785

src/benchmark/runner.zig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,7 @@ pub const BenchmarkRunner = struct {
140140
const writer = file.writer();
141141

142142
// Header
143-
try writer.print(
144-
"model,n_seeds,ppl_mean,ppl_std,ppl_ci_low,ppl_ci_high,tok_mean,tok_std,lat_mean,lat_std,mem_mean,flops,improvement\n",
145-
.{}
146-
);
143+
try writer.print("model,n_seeds,ppl_mean,ppl_std,ppl_ci_low,ppl_ci_high,tok_mean,tok_std,lat_mean,lat_std,mem_mean,flops,improvement\n", .{});
147144

148145
// Data rows
149146
for (results) |r| {
@@ -174,7 +171,7 @@ pub fn countFLOPs(config: FLOPsConfig) u64 {
174171

175172
pub fn estimateTrainingFLOPs(params_m: u32, n_tokens: u32) f64 {
176173
const training_flops = @as(f64, @floatFromInt(params_m)) *
177-
@as(f64, @floatFromInt(n_tokens)) * 6.0;
174+
@as(f64, @floatFromInt(n_tokens)) * 6.0;
178175
return training_flops;
179176
}
180177

src/benchmark_suite.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,9 @@ pub const AggregatedResult = struct {
235235
const model_name = try self.baseline_model.format(allocator);
236236
defer allocator.free(model_name);
237237

238-
// Format: Model & PPL & tok/s & Latency (ms) & Params (M) \\
238+
// Format: Model & PPL & tok/s & Latency (ms) & Params (M) \\ (LaTeX line break)
239239
return std.fmt.allocPrint(allocator,
240-
"{s} & {d:.2} $\\pm$ {d:.2} & {d:.1} $\\pm$ {d:.1} & {d:.2} $\\pm$ {d:.2} & {d} \\\\
241-
, .{
240+
"{s} & {d:.2} $\\pm$ {d:.2} & {d:.1} $\\pm$ {d:.1} & {d:.2} $\\pm$ {d:.2} & {d} \\\\", .{
242241
model_name,
243242
self.perplexity_mean,
244243
self.perplexity_std,

src/energy.zig

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ pub const EnergyEngine = struct {
128128
}
129129

130130
/// Measure energy consumption for a function
131-
pub fn measure(
132-
self: *const EnergyEngine,
133-
name: []const u8,
134-
n_tokens: u32
135-
) !EnergyResult {
131+
pub fn measure(self: *const EnergyEngine, name: []const u8, n_tokens: u32) !EnergyResult {
136132
_ = name;
137133

138134
const sample_interval_s = @as(f64, @floatFromInt(self.config.sample_interval_ms)) / 1000.0;
@@ -168,12 +164,7 @@ pub const EnergyEngine = struct {
168164
}
169165

170166
/// Measure across multiple seeds
171-
pub fn measureSeeds(
172-
self: *const EnergyEngine,
173-
name: []const u8,
174-
seeds: []const u32,
175-
n_tokens_per_seed: u32
176-
) !EnergySummary {
167+
pub fn measureSeeds(self: *const EnergyEngine, name: []const u8, seeds: []const u32, n_tokens_per_seed: u32) !EnergySummary {
177168
const start_time = std.time.nanoTimestamp();
178169

179170
std.debug.print("\n╔══════════════════════════════════════════════╗\n", .{});
@@ -246,10 +237,7 @@ pub const EnergyEngine = struct {
246237
const writer = file.writer();
247238

248239
// Header
249-
try writer.print(
250-
"metric,value,unit\n",
251-
.{}
252-
);
240+
try writer.print("metric,value,unit\n", .{});
253241

254242
// Aggregate results
255243
try writer.print("mean_power_watts,{d:.6},W\n", .{summary.results.mean_power_watts});
@@ -289,20 +277,18 @@ pub const EnergyEngine = struct {
289277
\\## Efficiency Metrics
290278
\\- FLOPs per joule: {d:.0}
291279
\\- Power state: mostly active
292-
,
293-
.{
294-
summary.n_samples,
295-
summary.results.duration_secs,
296-
summary.results.mean_power_watts,
297-
summary.results.peak_power_watts,
298-
summary.results.total_energy_joules,
299-
summary.results.total_energy_joules / 3.6e6,
300-
summary.results.energy_per_token_joules,
301-
summary.results.carbon_g_co2e,
302-
summary.results.carbon_g_co2e / 120.0, // 120 g CO2e per km
303-
summary.results.flops_per_joule,
304-
}
305-
);
280+
, .{
281+
summary.n_samples,
282+
summary.results.duration_secs,
283+
summary.results.mean_power_watts,
284+
summary.results.peak_power_watts,
285+
summary.results.total_energy_joules,
286+
summary.results.total_energy_joules / 3.6e6,
287+
summary.results.energy_per_token_joules,
288+
summary.results.carbon_g_co2e,
289+
summary.results.carbon_g_co2e / 120.0, // 120 g CO2e per km
290+
summary.results.flops_per_joule,
291+
});
306292

307293
return buffer.toOwnedSlice();
308294
}

src/hyperparameter_analysis.zig

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,19 @@ pub const AnalysisEngine = struct {
113113
}
114114

115115
/// Run sensitivity analysis for single hyperparameter
116-
pub fn analyzeParam(
117-
self: *const AnalysisEngine,
118-
config: SensitivityConfig,
119-
param_range: HyperparamRange
120-
) !SensitivityResult {
116+
pub fn analyzeParam(self: *const AnalysisEngine, config: SensitivityConfig, param_range: HyperparamRange) !SensitivityResult {
121117
// Allocate response surface array (owned by result, not freed here)
122118
const response = try self.allocator.alloc(f64, param_range.n_steps);
123119

124120
// Generate values from min to max
125121
for (0..param_range.n_steps) |i| {
126122
const t = @as(f64, @floatFromInt(i)) /
127-
@as(f64, @floatFromInt(param_range.n_steps - 1));
123+
@as(f64, @floatFromInt(param_range.n_steps - 1));
128124

129125
const value = switch (param_range.scale) {
130126
.linear => param_range.min_value +
131-
t * (param_range.max_value - param_range.min_value),
132-
.logarithmic => param_range.min_value * std.math.pow(f64,
133-
param_range.max_value / param_range.min_value,
134-
t
135-
),
127+
t * (param_range.max_value - param_range.min_value),
128+
.logarithmic => param_range.min_value * std.math.pow(f64, param_range.max_value / param_range.min_value, t),
136129
};
137130

138131
response[i] = value;
@@ -189,10 +182,7 @@ pub const AnalysisEngine = struct {
189182
}
190183

191184
/// Run full sensitivity analysis across all hyperparameters
192-
pub fn analyzeAll(
193-
self: *const AnalysisEngine,
194-
config: SensitivityConfig
195-
) !SensitivitySummary {
185+
pub fn analyzeAll(self: *const AnalysisEngine, config: SensitivityConfig) !SensitivitySummary {
196186
// Allocate results array
197187
const results = try self.allocator.alloc(SensitivityResult, config.base_config.len);
198188
defer self.allocator.free(results);
@@ -230,10 +220,7 @@ pub const AnalysisEngine = struct {
230220
}
231221

232222
/// Generate recommendations based on sensitivity results
233-
fn generateRecommendations(
234-
self: *const AnalysisEngine,
235-
results: []const SensitivityResult
236-
) ![]const Recommendation {
223+
fn generateRecommendations(self: *const AnalysisEngine, results: []const SensitivityResult) ![]const Recommendation {
237224
const recs = try self.allocator.alloc(Recommendation, results.len);
238225
errdefer self.allocator.free(recs);
239226

@@ -264,22 +251,15 @@ pub const AnalysisEngine = struct {
264251
}
265252

266253
/// Export results to CSV
267-
pub fn exportCsv(
268-
self: *const AnalysisEngine,
269-
results: []const SensitivityResult,
270-
path: []const u8
271-
) !void {
254+
pub fn exportCsv(self: *const AnalysisEngine, results: []const SensitivityResult, path: []const u8) !void {
272255
_ = self;
273256
const file = try std.fs.cwd().createFile(path, .{});
274257
defer file.close();
275258

276259
const writer = file.writer();
277260

278261
// Header
279-
try writer.print(
280-
"param,min_value,max_value,best_value,sensitivity_score\n",
281-
.{}
282-
);
262+
try writer.print("param,min_value,max_value,best_value,sensitivity_score\n", .{});
283263

284264
// Data rows
285265
for (results) |r| {
@@ -294,10 +274,7 @@ pub const AnalysisEngine = struct {
294274
}
295275

296276
/// Generate sensitivity report (human-readable)
297-
pub fn generateReport(
298-
self: *const AnalysisEngine,
299-
summary: SensitivitySummary
300-
) ![]const u8 {
277+
pub fn generateReport(self: *const AnalysisEngine, summary: SensitivitySummary) ![]const u8 {
301278
var buffer = std.ArrayList(u8).init(self.allocator);
302279
defer buffer.deinit();
303280

@@ -310,13 +287,11 @@ pub const AnalysisEngine = struct {
310287
\\- Least sensitive: {s}
311288
\\
312289
\\## Recommendations
313-
,
314-
.{
315-
summary.n_params_analyzed,
316-
@tagName(summary.most_sensitive),
317-
@tagName(summary.least_sensitive),
318-
}
319-
);
290+
, .{
291+
summary.n_params_analyzed,
292+
@tagName(summary.most_sensitive),
293+
@tagName(summary.least_sensitive),
294+
});
320295

321296
for (summary.recommendations) |rec| {
322297
try buffer.writer().print(
@@ -325,14 +300,12 @@ pub const AnalysisEngine = struct {
325300
\\- Confidence: {d:.0%}
326301
\\- Reason: {s}
327302
\\
328-
,
329-
.{
330-
@tagName(rec.param),
331-
rec.suggested_value,
332-
rec.confidence * 100.0,
333-
rec.reason,
334-
}
335-
);
303+
, .{
304+
@tagName(rec.param),
305+
rec.suggested_value,
306+
rec.confidence * 100.0,
307+
rec.reason,
308+
});
336309
}
337310

338311
return buffer.toOwnedSlice();
@@ -368,7 +341,7 @@ test "HyperparameterAnalysis - linear parameter range" {
368341
const config = SensitivityConfig{
369342
.name = "test",
370343
.base_config = &[_]HyperparamRange{range},
371-
.seeds = &[_]u32{ 42 },
344+
.seeds = &[_]u32{42},
372345
.dataset = .tinystories,
373346
.epochs = 10,
374347
.output_path = "/tmp/test.csv",
@@ -397,7 +370,7 @@ test "HyperparameterAnalysis - logarithmic parameter range" {
397370
const config = SensitivityConfig{
398371
.name = "test",
399372
.base_config = &[_]HyperparamRange{range},
400-
.seeds = &[_]u32{ 42 },
373+
.seeds = &[_]u32{42},
401374
.dataset = .tinystories,
402375
.epochs = 10,
403376
.output_path = "/tmp/test.csv",

src/profiling.zig

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,7 @@ pub const ProfilingEngine = struct {
7777
std.debug.print(" Arch: {s}\n", .{@tagName(builtin.cpu.arch)});
7878
}
7979

80-
pub fn profileSeeds(
81-
self: *const ProfilingEngine,
82-
name: []const u8,
83-
seeds: []const u32
84-
) !ProfileSummary {
80+
pub fn profileSeeds(self: *const ProfilingEngine, name: []const u8, seeds: []const u32) !ProfileSummary {
8581
const start_time = std.time.nanoTimestamp();
8682

8783
std.debug.print("\n╔════════════════════════════════════════════╗\n", .{});
@@ -126,10 +122,7 @@ pub const ProfilingEngine = struct {
126122
const writer = file.writer();
127123

128124
// Header
129-
try writer.print(
130-
"metric,mean,std_dev,min,max,ci_95_low,ci_95_high,unit\n",
131-
.{}
132-
);
125+
try writer.print("metric,mean,std_dev,min,max,ci_95_low,ci_95_high,unit\n", .{});
133126

134127
// Data rows
135128
for (summary.results) |r| {
@@ -162,12 +155,10 @@ pub const ProfilingEngine = struct {
162155
\\- Total time: {d:.2}s
163156
\\
164157
\\## Results by Metric
165-
,
166-
.{
167-
summary.n_metrics,
168-
summary.total_time_secs,
169-
}
170-
);
158+
, .{
159+
summary.n_metrics,
160+
summary.total_time_secs,
161+
});
171162

172163
for (summary.results) |r| {
173164
try writer.print(
@@ -177,18 +168,16 @@ pub const ProfilingEngine = struct {
177168
\\- Range: {d:.2} - {d:.2} {s}
178169
\\- 95% CI: [{d:.2}, {d:.2}]
179170
\\
180-
,
181-
.{
182-
@tagName(r.metric),
183-
r.mean,
184-
r.std_dev,
185-
r.min,
186-
r.max,
187-
r.ci_95.low,
188-
r.ci_95.high,
189-
r.unit,
190-
}
191-
);
171+
, .{
172+
@tagName(r.metric),
173+
r.mean,
174+
r.std_dev,
175+
r.min,
176+
r.max,
177+
r.ci_95.low,
178+
r.ci_95.high,
179+
r.unit,
180+
});
192181
}
193182

194183
return buffer.toOwnedSlice();

0 commit comments

Comments
 (0)