Spaces:
Runtime error
Runtime error
GitHub Copilot
commited on
Commit
·
594d19b
1
Parent(s):
37e2fa3
Fix: Add Warm-Up Atom (Harmonic Resonance) to Baker to fix black image
Browse files
local_test/test_baker.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
import numpy as np
|
| 5 |
+
import cv2
|
| 6 |
+
|
| 7 |
+
# Add parent directory to path to import logos
|
| 8 |
+
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../')
|
| 9 |
+
|
| 10 |
+
from logos.baker import BreadBaker
|
| 11 |
+
from logos.fractal_engine import LogosFractalEngine, ContextAction
|
| 12 |
+
from logos.logos_core import calculate_heat_code, unpack_atom, pack_atom, META_SIZE
|
| 13 |
+
|
| 14 |
+
def test_bake_cycle():
|
| 15 |
+
print("Initializing Local Test Environment...")
|
| 16 |
+
|
| 17 |
+
# Create a synthetic test image (Gradient)
|
| 18 |
+
img_size = 256
|
| 19 |
+
img = np.zeros((img_size, img_size, 3), dtype=np.uint8)
|
| 20 |
+
for y in range(img_size):
|
| 21 |
+
for x in range(img_size):
|
| 22 |
+
img[y, x] = [x % 255, y % 255, (x+y) % 255]
|
| 23 |
+
|
| 24 |
+
print(f"Created Test Image: {img_size}x{img_size}")
|
| 25 |
+
|
| 26 |
+
# Initialize Baker
|
| 27 |
+
baker = BreadBaker(variance_threshold=10, min_block_size=8)
|
| 28 |
+
|
| 29 |
+
# Bake
|
| 30 |
+
print("Baking...")
|
| 31 |
+
atom_defs = baker.bake(img, prefix_path=[])
|
| 32 |
+
print(f"Generated {len(atom_defs)} atom definitions")
|
| 33 |
+
|
| 34 |
+
# Pack Atoms (Simulating DSPBridge)
|
| 35 |
+
atoms = []
|
| 36 |
+
for i, adef in enumerate(atom_defs):
|
| 37 |
+
path = adef['path_bits']
|
| 38 |
+
payload = adef['payload']
|
| 39 |
+
hc = calculate_heat_code(path)
|
| 40 |
+
# Dummy meta
|
| 41 |
+
full_payload = b'\x00' * META_SIZE + payload
|
| 42 |
+
atom = pack_atom(hc, full_payload, gap_id=i)
|
| 43 |
+
atoms.append(atom)
|
| 44 |
+
|
| 45 |
+
print(f"Packed {len(atoms)} atoms")
|
| 46 |
+
|
| 47 |
+
# Decode (Simulating DSPBridge decode_wave)
|
| 48 |
+
print("Decoding...")
|
| 49 |
+
engine = LogosFractalEngine(min_bucket_size=1)
|
| 50 |
+
|
| 51 |
+
for atom in atoms:
|
| 52 |
+
hc, pl, _, _ = unpack_atom(atom)
|
| 53 |
+
baker_payload = pl[META_SIZE:]
|
| 54 |
+
hex_str = f"{hc:08x}"
|
| 55 |
+
engine.process_atom(hex_str, baker_payload)
|
| 56 |
+
|
| 57 |
+
# Render
|
| 58 |
+
result = engine.draw_viewport((img_size, img_size))
|
| 59 |
+
|
| 60 |
+
# Verify
|
| 61 |
+
mean_input = np.mean(img)
|
| 62 |
+
mean_output = np.mean(result)
|
| 63 |
+
print(f"Input Mean Brightness: {mean_input:.2f}")
|
| 64 |
+
print(f"Output Mean Brightness: {mean_output:.2f}")
|
| 65 |
+
|
| 66 |
+
if mean_output < 1.0:
|
| 67 |
+
print("[FAIL] Output is essentially black.")
|
| 68 |
+
print("Hypothesis: Nodes start at Heat 0. GF4 Multiply by 0 = 0.")
|
| 69 |
+
return False
|
| 70 |
+
else:
|
| 71 |
+
print("[SUCCESS] Output has content.")
|
| 72 |
+
return True
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
test_bake_cycle()
|
logos/__pycache__/dsp_bridge.cpython-314.pyc
CHANGED
|
Binary files a/logos/__pycache__/dsp_bridge.cpython-314.pyc and b/logos/__pycache__/dsp_bridge.cpython-314.pyc differ
|
|
|
logos/__pycache__/network.cpython-314.pyc
ADDED
|
Binary file (4.67 kB). View file
|
|
|
logos/baker.py
CHANGED
|
@@ -52,6 +52,21 @@ class BreadBaker:
|
|
| 52 |
r, g, b = int(rgb_mean[0]), int(rgb_mean[1]), int(rgb_mean[2])
|
| 53 |
matrix_key = (b << 16) | (g << 8) | r
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Pack payload compatible with LogoFractalEngine vector decoder
|
| 56 |
# We pack matrix_key (RGB) into the vector slots
|
| 57 |
action = ContextAction.CHANGE_1
|
|
|
|
| 52 |
r, g, b = int(rgb_mean[0]), int(rgb_mean[1]), int(rgb_mean[2])
|
| 53 |
matrix_key = (b << 16) | (g << 8) | r
|
| 54 |
|
| 55 |
+
# --- ATOM 1: WARM UP (Harmonic Resonance) ---
|
| 56 |
+
# We must raise heat_state from 0 to 1 so that GF4 multiplication (Dissolution)
|
| 57 |
+
# has a non-zero scalar. 0 * Input = 0 (No Change).
|
| 58 |
+
# ContextAction.PERSIST (00) increments heat.
|
| 59 |
+
|
| 60 |
+
warm_action = ContextAction.PERSIST
|
| 61 |
+
warm_ctrl = (warm_action.value << 6) & 0xC0
|
| 62 |
+
warm_payload = bytes([warm_ctrl])
|
| 63 |
+
|
| 64 |
+
self.atoms.append({
|
| 65 |
+
"path_bits": path_bits,
|
| 66 |
+
"payload": warm_payload
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
# --- ATOM 2: STRUCTURE (Matrix Key) ---
|
| 70 |
# Pack payload compatible with LogoFractalEngine vector decoder
|
| 71 |
# We pack matrix_key (RGB) into the vector slots
|
| 72 |
action = ContextAction.CHANGE_1
|