-
Notifications
You must be signed in to change notification settings - Fork 1
ATOM-FEATURE-20260122-002-quasicrystal-phason-scheduler #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ATOM-FEATURE-20260122-002-quasicrystal-phason-scheduler - Pure first-principles implementation with golden Penrose coordinates - Phason flips with Fibonacci-strided propagation - VLIW bundle packing simulation - Configurable v=c guard (default 62 iterations) - Comparison benchmarks vs uniform random baseline Co-authored-by: toolate28 <105518313+toolate28@users.noreply.github.com>
- Rename max_iterations to vc_guard_override for clarity - Extract magic numbers to named constants (DEFAULT_VC_GUARD_LIMIT, COORD_SEED_*) - Add comments explaining warmup calls in tests Co-authored-by: toolate28 <105518313+toolate28@users.noreply.github.com>
|
@copilot needing matching rule sets agent instructions corpus docs refresh protocol updates apply the innate philosohpy everywhere in every substrate and plane that we are a node of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a standalone quasicrystal phason scheduler prototype for VLIW bundle packing optimization. The implementation addresses the hardcoded v=c guard limit by making it configurable while maintaining the default 62-iteration safety boundary.
Changes:
- New scheduler implementation with 5D→2D Penrose projection, golden angle phason flips, and Fibonacci-strided propagation
- VLIW bundle packing simulation with 12 ALU, 6 VALU, and 2 load/store slots
- Comprehensive test suite with 13 tests covering constants, projections, guards, reproducibility, and density comparisons
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 11 comments.
| File | Description |
|---|---|
| experiments/quasicrystal_phason_scheduler.py | Main implementation with configurable v=c guard, VLIW bundle class, scheduling functions, and integration proposal for performance optimization |
| experiments/test_quasicrystal_phason_scheduler.py | Test suite validating constants, Penrose projection, v=c guard behavior, reproducibility, density metrics, and VLIW packing logic |
| vc_limit = vc_guard_override if vc_guard_override is not None else DEFAULT_VC_GUARD_LIMIT | ||
|
|
||
| for it in range(iterations): | ||
| if it > vc_limit: |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The v=c guard logic checks if it > vc_limit, which means when iterations=62 and vc_limit=62, the loop will execute iterations 0-62 (63 total iterations) before raising the error. This is off-by-one from the documented behavior. The check should be if it >= vc_limit to ensure exactly vc_limit iterations are allowed. This inconsistency exists in the original quasicrystal_optimization.py file as well, but it should be corrected here.
| if it > vc_limit: | |
| if it >= vc_limit: |
| PHI = (1 + math.sqrt(5)) / 2 # Golden ratio ≈ 1.618 | ||
| GOLDEN_ANGLE = 2 * math.pi / PHI**2 # ≈137.5° in radians | ||
| EPSILON = 0.00055 # Coherence seed | ||
| DEFAULT_VC_GUARD_LIMIT = 62 # Default v=c boundary guard limit | ||
| COORD_SEED_SCALE = 1000 # Scale factor for coordinate-to-seed conversion | ||
| COORD_SEED_OFFSET = 100 # Offset factor for coordinate-to-seed conversion | ||
| COORD_SEED_MOD = 2**31 # Modulus for seed (32-bit positive int) | ||
|
|
||
|
|
||
| def penrose_project(n_points: int) -> np.ndarray: | ||
| """5D → 2D Penrose coordinates via cut-and-project. | ||
|
|
||
| Generates aperiodic 2D coordinates using quasicrystal projection. | ||
|
|
||
| Args: | ||
| n_points: Controls grid density (actual points = n_points^2) | ||
|
|
||
| Returns: | ||
| Array of 2D coordinates with shape (N, 2) | ||
| """ | ||
| theta = np.arange(5) * 2 * math.pi / 5 | ||
| u = np.cos(theta) | ||
| v = np.sin(theta) | ||
| points = [] | ||
| for i in range(-n_points // 2, n_points // 2 + 1): | ||
| for j in range(-n_points // 2, n_points // 2 + 1): | ||
| coord = i * u + j * v | ||
| points.append(coord[:2]) | ||
| return np.array(points) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is significant code duplication between this file and experiments/quasicrystal_optimization.py (ATOM-FEATURE-20260122-001), including the constants PHI, GOLDEN_ANGLE, and the penrose_project function. While the PR description mentions this is a "pure first-principles implementation" to avoid "taint from main kernel", having duplicate implementations of the same mathematical functions creates maintenance burden and potential for divergence. Consider extracting these shared utilities into a common module (e.g., experiments/quasicrystal_common.py) that both files can import, especially since both are in the same experiments directory.
| print(f"\n{'='*60}") | ||
| print(f"VLIW Bundle Packing Simulation") | ||
| print(f"Operations: {n_ops} ({op_types.count('ALU')} ALU, {op_types.count('VALU')} VALU, {op_types.count('LS')} LS)") |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The operations distribution is hardcoded as ["ALU"] * 30 + ["VALU"] * 15 + ["LS"] * 5 (50 ops), but then random.choice(op_types) is used with n_ops iterations. When n_ops != 50, the actual distribution will not match the comment on line 378, which reports counts based on the 50-element list. For example, if n_ops=100, the counts displayed will still show "30 ALU, 15 VALU, 5 LS" but the actual operations will have a roughly 3:1.5:0.5 ratio for 100 ops. Consider generating the operations list dynamically based on n_ops with the desired ratio, or document that the displayed counts are for the distribution pool, not the actual operations.
| print(f"\n{'='*60}") | |
| print(f"VLIW Bundle Packing Simulation") | |
| print(f"Operations: {n_ops} ({op_types.count('ALU')} ALU, {op_types.count('VALU')} VALU, {op_types.count('LS')} LS)") | |
| # Compute realized operation-type counts | |
| alu_count = sum(1 for op, _ in ops if op == "ALU") | |
| valu_count = sum(1 for op, _ in ops if op == "VALU") | |
| ls_count = sum(1 for op, _ in ops if op == "LS") | |
| print(f"\n{'='*60}") | |
| print(f"VLIW Bundle Packing Simulation") | |
| print(f"Operations: {n_ops} ({alu_count} ALU, {valu_count} VALU, {ls_count} LS)") |
| Generates aperiodic 2D coordinates using quasicrystal projection. | ||
|
|
||
| Args: | ||
| n_points: Controls grid density (actual points = n_points^2) |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring states the function "Controls grid density (actual points = n_points^2)", but the actual behavior produces (n_points + 1)^2 points due to the inclusive range range(-n_points // 2, n_points // 2 + 1). The test correctly expects this behavior (line 112 of the test file), but the docstring is misleading. Update the docstring to accurately reflect that actual points = (n_points + 1)^2 or that the grid spans from -n_points//2 to n_points//2 inclusive.
| n_points: Controls grid density (actual points = n_points^2) | |
| n_points: Controls grid density (actual points = (n_points + 1)^2; | |
| grid spans from -n_points//2 to n_points//2 inclusive in both axes) |
| # Map coordinate to priority using golden ratio projection | ||
| priorities = [(coord[0] * PHI + coord[1]) for _ in range(len(ops))] |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the integration proposal example, the get_schedule_priority function creates a priorities list where every element has the same value: coord[0] * PHI + coord[1]. This appears to be a logic error - the list comprehension [(coord[0] * PHI + coord[1]) for _ in range(len(ops))] creates len(ops) copies of the same scalar value, which would make the subsequent sorting meaningless (all priorities would be identical). The intended logic is unclear, but this should either: (1) use different coordinates for each operation, (2) use the index in the calculation, or (3) be removed if this was example pseudocode that shouldn't be taken literally.
| # Map coordinate to priority using golden ratio projection | |
| priorities = [(coord[0] * PHI + coord[1]) for _ in range(len(ops))] | |
| # Map coordinate to priority using golden ratio projection, | |
| # with a small EPSILON-strided offset per op to ensure distinct priorities | |
| priorities = [ | |
| (coord[0] * PHI + coord[1]) + EPSILON * i | |
| for i in range(len(ops)) | |
| ] |
| best_val = float('inf') | ||
| best_coord = None | ||
|
|
||
| # v=c guard limit (can be overridden with vc_guard_override) | ||
| vc_limit = vc_guard_override if vc_guard_override is not None else DEFAULT_VC_GUARD_LIMIT | ||
|
|
||
| for it in range(iterations): | ||
| if it > vc_limit: | ||
| raise RuntimeError("v=c boundary guarded — coherence collapse prevented") | ||
|
|
||
| phason_flip(coords, values, it) | ||
|
|
||
| current_best = values.min() | ||
| if current_best < best_val: | ||
| best_val = current_best | ||
| best_idx = np.argmin(values) | ||
| best_coord = coords[best_idx].copy() | ||
|
|
||
| if verbose and it % 50 == 0: | ||
| print(f"Iter {it}/{iterations} | Best density: {-best_val:.4f}") | ||
|
|
||
| return best_coord, -best_val # Return best coord + positive density |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't handle the edge case where best_coord is None (which occurs if no iterations run or no improvement is found). While unlikely in practice (the loop runs at least once for iterations > 0), returning None for the coordinate could cause errors in calling code that expects a numpy array. Consider initializing best_coord to coords[0].copy() before the loop or adding validation that best_coord is not None before returning.
| for i in range(-n_points // 2, n_points // 2 + 1): | ||
| for j in range(-n_points // 2, n_points // 2 + 1): |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The penrose_project function has a subtle difference from the one in quasicrystal_optimization.py. This implementation uses range(-n_points // 2, n_points // 2 + 1) (inclusive of endpoint), while the existing implementation uses range(-n_points // 2, n_points // 2) (exclusive of endpoint). This produces different grid sizes: (n_points + 1)^2 vs n_points^2. While not necessarily wrong, this inconsistency between the two files could lead to confusion and unexpected behavior. Consider documenting why this difference exists or standardizing the approach.
| for i in range(-n_points // 2, n_points // 2 + 1): | |
| for j in range(-n_points // 2, n_points // 2 + 1): | |
| for i in range(-n_points // 2, n_points // 2): | |
| for j in range(-n_points // 2, n_points // 2): |
| np.random.seed(coord_seed) | ||
|
|
||
| bundles = [] | ||
| current_bundle = VLIWBundle() | ||
|
|
||
| for op_type, op_id in ops: | ||
| if not current_bundle.pack(op_type, op_id): | ||
| bundles.append(current_bundle) | ||
| current_bundle = VLIWBundle() | ||
| current_bundle.pack(op_type, op_id) | ||
|
|
||
| if current_bundle.packed_ops: | ||
| bundles.append(current_bundle) | ||
|
|
||
| # Calculate average utilization | ||
| avg_util = sum(b.utilization() for b in bundles) / len(bundles) if bundles else 0 | ||
| return -avg_util # Negative for minimization | ||
|
|
||
|
|
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vliw_packing_objective function modifies global numpy random state by calling np.random.seed(coord_seed) but doesn't restore the original state afterward. This side effect is not documented in the docstring and could cause non-deterministic behavior when this function is called multiple times in a test or benchmark context, as it will affect subsequent numpy random operations. Consider either: (1) documenting this side effect clearly in the docstring, (2) using a local np.random.Generator instance instead of the global state, or (3) saving and restoring the random state.
| np.random.seed(coord_seed) | |
| bundles = [] | |
| current_bundle = VLIWBundle() | |
| for op_type, op_id in ops: | |
| if not current_bundle.pack(op_type, op_id): | |
| bundles.append(current_bundle) | |
| current_bundle = VLIWBundle() | |
| current_bundle.pack(op_type, op_id) | |
| if current_bundle.packed_ops: | |
| bundles.append(current_bundle) | |
| # Calculate average utilization | |
| avg_util = sum(b.utilization() for b in bundles) / len(bundles) if bundles else 0 | |
| return -avg_util # Negative for minimization | |
| rng_state = np.random.get_state() | |
| try: | |
| np.random.seed(coord_seed) | |
| bundles = [] | |
| current_bundle = VLIWBundle() | |
| for op_type, op_id in ops: | |
| if not current_bundle.pack(op_type, op_id): | |
| bundles.append(current_bundle) | |
| current_bundle = VLIWBundle() | |
| current_bundle.pack(op_type, op_id) | |
| if current_bundle.packed_ops: | |
| bundles.append(current_bundle) | |
| # Calculate average utilization | |
| avg_util = sum(b.utilization() for b in bundles) / len(bundles) if bundles else 0 | |
| return -avg_util # Negative for minimization | |
| finally: | |
| np.random.set_state(rng_state) |
|
|
||
| import math | ||
| import sys | ||
| import time |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'time' is not used.
| import time |
| PHI, GOLDEN_ANGLE, EPSILON, DEFAULT_VC_GUARD_LIMIT, | ||
| penrose_project, phason_flip, bundle_density_objective, |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'phason_flip' is not used.
Import of 'DEFAULT_VC_GUARD_LIMIT' is not used.
| PHI, GOLDEN_ANGLE, EPSILON, DEFAULT_VC_GUARD_LIMIT, | |
| penrose_project, phason_flip, bundle_density_objective, | |
| PHI, GOLDEN_ANGLE, EPSILON, | |
| penrose_project, bundle_density_objective, |
|
@copilot please make the required changes |
Summary
Standalone quasicrystal scheduler with golden Penrose coordinates, phason flips, and VLIW bundle packing simulation. Fixes the v=c guard by making iteration limit configurable.
ATOM Tag
ATOM:
ATOM-FEATURE-20260122-002-quasicrystal-phason-schedulerWhy
Enable experimentation with quasicrystal-based scheduling optimization separate from main kernel. The original code had a hardcoded
if it > 62: raise RuntimeErrorthat blocked any run exceeding 62 iterations.What changed
experiments/quasicrystal_phason_scheduler.py— Pure first-principles implementation:VLIWBundleclass (12 ALU, 6 VALU, 2 LS slots)vc_guard_overrideparameterexperiments/test_quasicrystal_phason_scheduler.py— 13 tests covering constants, projection, v=c guard, reproducibility, density comparison, VLIW packingKey API:
Verification / Testing
scripts/validate-bump.shpasses locally (if bump.md changed)scripts/validate-branch-name.shtested on example branches (if applicable)bash scripts/verify-environment.shprintsENV OKscripts/test-scripts.shpasses (if scripts changed)Claude Interaction
You can interact with Claude in this PR by:
claude:review,claude:help,claude:analyzeExample commands:
@claude please review this PR for ATOM compliance@claude explain the changes in scripts/atom-track.sh@claude check for security issues@claude suggest improvementsNotes
Checklist
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.