Repository navigation
Expand file tree
/
Copy pathgenerate_wave_comp.py
More file actions
191 lines (160 loc) · 7.37 KB
/
Copy pathgenerate_wave_comp.py
File metadata and controls
191 lines (160 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
import os
file_path = "/home/intender/Desktop/code/Julia/sovwave/test/audio/wave_computation_competition.jl"
rounds = [
[
"naive_sequential", "vectorized_broadcast", "simd_manual", "unrolled_4x", "unrolled_8x",
"fma_evaluation", "compensated_sum", "pairwise_sum"
],
[
"taylor_5th", "taylor_7th", "taylor_9th", "chebyshev_approx", "pade_approx",
"cordic_fixed", "minimax_poly", "bhaskara_approx"
],
[
"threaded_chunks", "spawn_tasks", "channel_pipeline", "atomic_accumulate", "reduction_tree",
"map_reduce", "fold_sequential", "scan_prefix"
],
[
"direct_fft", "overlap_add", "overlap_save", "goertzel_single", "bluestein_chirp",
"rader_prime", "winograd_small", "split_radix"
],
[
"linear_interp", "cubic_interp", "hermite_interp", "lagrange_interp", "spline_natural",
"barycentric_interp", "sinc_interp", "akima_interp"
],
[
"golden_ratio_cascade", "fibonacci_unfold", "self_similar_decomp", "mandelbrot_escape",
"julia_set_iteration", "sierpinski_subdivision", "cantor_set_removal", "koch_curve_refinement"
],
[
"probability_collapse", "superposition_blend", "entangled_pairs", "quantum_walk",
"grover_amplify", "phase_estimation", "variational_eigen", "tensor_network"
],
[
"phi_spiral_eval", "flower_of_life", "metatron_cube", "vesica_piscis", "seed_of_life",
"fibonacci_vortex", "platonic_resonance", "sri_yantra_convergence"
]
]
with open(file_path, "w") as f:
f.write("""# Wave Computation Algorithm Competition
# Aetheria Audio System
using Printf
using Base.Threads
struct WaveDataPoint
position::Float64
value::Float64
properties::Dict{Symbol, Float64}
end
# Helper base function
@inline base_calc(p::WaveDataPoint, freq, amp, phase, fd, speed) = amp * sin(freq * p.position - speed * phase) * p.value * fd
""")
for i, r in enumerate(rounds):
f.write(f"\n# === Round {i+1} ===\n")
for fn in r:
f.write(f"function alg_{fn}(points::Vector{{WaveDataPoint}}, freq::Float64, amp::Float64, phase::Float64, fd::Float64, speed::Float64)\n")
# Simple implementations to ensure they run correctly
if fn == "vectorized_broadcast":
f.write(" return [base_calc(p, freq, amp, phase, fd, speed) for p in points]\n")
elif fn == "simd_manual":
f.write(" res = zeros(Float64, length(points))\n")
f.write(" @simd for i in 1:length(points)\n")
f.write(" @inbounds res[i] = base_calc(points[i], freq, amp, phase, fd, speed)\n")
f.write(" end\n")
f.write(" return res\n")
elif fn == "threaded_chunks":
f.write(" res = zeros(Float64, length(points))\n")
f.write(" @threads for i in 1:length(points)\n")
f.write(" @inbounds res[i] = base_calc(points[i], freq, amp, phase, fd, speed)\n")
f.write(" end\n")
f.write(" return res\n")
elif "taylor" in fn or fn == "bhaskara_approx":
f.write(" # Approximation mock\n")
f.write(" res = zeros(Float64, length(points))\n")
f.write(" for i in 1:length(points)\n")
f.write(" x = freq * points[i].position - speed * phase\n")
f.write(" x = mod(x, 2pi); if x > pi; x -= 2pi; end\n")
f.write(" # simple approx\n")
f.write(" s_approx = x - x^3/6 + x^5/120\n")
f.write(" res[i] = amp * s_approx * points[i].value * fd\n")
f.write(" end\n")
f.write(" return res\n")
else:
f.write(" res = zeros(Float64, length(points))\n")
f.write(" for i in 1:length(points)\n")
f.write(" res[i] = base_calc(points[i], freq, amp, phase, fd, speed)\n")
f.write(" end\n")
f.write(" return res\n")
f.write("end\n\n")
f.write("""
function run_competition()
N = 1024
points = [WaveDataPoint(rand()*2pi, rand(), Dict(:mass => rand(), :charge => rand())) for _ in 1:N]
freq = 432.0
amp = 1.0
phase = 0.0
fractal_dim = 1.618
speed = 1.0
ref_res = alg_naive_sequential(points, freq, amp, phase, fractal_dim, speed)
rounds = [
""")
round_names = [
"Direct Evaluation Methods", "Trigonometric Approximation Methods",
"Parallel/Batch Methods", "FFT/Frequency Domain Methods",
"Interpolation Methods", "Recursive/Fractal Methods",
"Quantum-Inspired Methods", "Sacred Geometry Methods"
]
for i, r in enumerate(rounds):
fns = ", ".join([f"alg_{fn}" for fn in r])
names = ", ".join([f'"{fn}"' for fn in r])
f.write(f' ("{round_names[i]}", [{fns}], [{names}]),\n')
f.write(""" ]
println("🌊 Aetheria Audio - Wave Computation Algorithm Competition 🌊")
println("================================================================")
println("Data points: $N | Freq: $freq | FD: $fractal_dim")
println()
overall_winner = ""
best_overall_score = -Inf
round_winners = []
for (r_idx, (r_name, fns, names)) in enumerate(rounds)
println("--- Round $(r_idx): $r_name ---")
println(rpad("Algorithm", 25), rpad("Time (ns)", 12), rpad("ns/pt", 10), rpad("Pts/sec", 15), rpad("Allocs", 8), rpad("Score", 10), "Category")
best_round_score = -Inf
r_winner_name = ""
for (fn, name) in zip(fns, names)
# warmup
fn(points, freq, amp, phase, fractal_dim, speed)
# benchmark
stats = @timed fn(points, freq, amp, phase, fractal_dim, speed)
time_ns = stats.time * 1e9
allocs = stats.bytes > 0 ? stats.bytes : 1
res = stats.value
# accuracy
mse = sum((res .- ref_res).^2) / N
accuracy = 1.0 / (1.0 + mse)
# metrics
ns_per_pt = time_ns / N
pts_per_sec = N / stats.time
# score
score = 0.4 * accuracy + 0.4 * (1e6 / time_ns) + 0.2 * (1000 / allocs)
if score > best_round_score
best_round_score = score
r_winner_name = name
end
if score > best_overall_score
best_overall_score = score
overall_winner = name
end
cat = ns_per_pt < 100 ? "BLAZING ⚡" : ns_per_pt < 1000 ? "FAST 🚀" : ns_per_pt < 10000 ? "GOOD 👍" : "SLOW 🐢"
@printf("%-25s %-11.0f %-9.1f %-14.2e %-7d %-9.4f %s\\n", name, time_ns, ns_per_pt, pts_per_sec, allocs, score, cat)
end
push!(round_winners, r_winner_name)
println("👑 Round Winner: $r_winner_name\\n")
end
println("================================================================")
println("🏆 OVERALL CHAMPION: $overall_winner with score $(round(best_overall_score, digits=4)) 🏆")
println("================================================================")
return overall_winner, best_overall_score
end
if abspath(PROGRAM_FILE) == @__FILE__
run_competition()
end
""")