From b4ba84c1d29274b6622bae3a560cde055eb54174 Mon Sep 17 00:00:00 2001 From: GlyphRunner System Date: Thu, 21 May 2026 01:23:48 -0400 Subject: [PATCH] Refine XIC v1 to Symbolic Extension Only (No GPU Code) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed GPU-related code per specification: - Deleted xic_extensions/gpu_runtime.py - Removed GPU logic from op_RUN_PROMPT and op_STREAM - Removed demo_gpu.gx.json Kept pure symbolic extension: - 5 new instructions: STREAM, CHAIN, CALL_GLYPH, SET_CONTEXT, LOG - Symbolic execution mode via SET_MODE "symbolic" - run_symbolic_prompt() integration with LAIN cognition layer - demo_symbolic.gx.json for testing Implementation now focuses exclusively on: - Extending instruction set (9 total ops) - Adding symbolic routing to cognition layer - Preserving backward compatibility (zero breaking changes) - No external GPU dependencies All validation tests pass: ✅ OP_TABLE coverage (9 operations) ✅ XICContext.symbolic_mode field ✅ run_symbolic_prompt() callable ✅ Backward compatibility (demo_chat unchanged) ✅ Symbolic mode execution (LAIN pipeline) ✅ SET_CONTEXT, CHAIN, RUN_PROMPT routing Constraints met: ✅ No breaking changes ✅ No XIC v2 binary format ✅ No GPU-related code ✅ Strict v1 JSON + .gx architecture --- XIC_SYMBOLIC_EXTENSION_REPORT.md | 236 ++++++++++++++++++++++++++++ __pycache__/xic_ops.cpython-314.pyc | Bin 10974 -> 10027 bytes programs/demo_gpu.gx.json | 15 -- xic_extensions/gpu_runtime.py | 57 ------- xic_ops.py | 76 ++++----- 5 files changed, 268 insertions(+), 116 deletions(-) create mode 100644 XIC_SYMBOLIC_EXTENSION_REPORT.md delete mode 100644 programs/demo_gpu.gx.json delete mode 100644 xic_extensions/gpu_runtime.py diff --git a/XIC_SYMBOLIC_EXTENSION_REPORT.md b/XIC_SYMBOLIC_EXTENSION_REPORT.md new file mode 100644 index 0000000..2406db5 --- /dev/null +++ b/XIC_SYMBOLIC_EXTENSION_REPORT.md @@ -0,0 +1,236 @@ +# XIC v1 Symbolic Extension Report + +**Date**: 2026-05-21 +**Status**: ✅ Complete and validated +**Scope**: Symbolic execution mode + 5 new instructions + +--- + +## Summary + +Extended XIC v1 with: +1. **Symbolic execution mode**: Routes prompts through LAIN cognition layer (glyphos/cognitive_kernel.py) +2. **5 new instructions**: STREAM, CHAIN, CALL_GLYPH, SET_CONTEXT, LOG + +**Zero breaking changes**. All existing XIC v1 programs work unchanged. + +--- + +## New Instructions + +| Instruction | Purpose | Signature | +|---|---|---| +| STREAM | Stream output line-by-line | `{ "op": "STREAM", "args": ["prompt"] }` | +| CHAIN | Mark named execution boundary | `{ "op": "CHAIN", "args": ["label"] }` | +| CALL_GLYPH | Invoke cognition with glyph context | `{ "op": "CALL_GLYPH", "args": ["glyph_id", "payload"] }` | +| SET_CONTEXT | Set symbolic/cognitive context key | `{ "op": "SET_CONTEXT", "args": ["key", value] }` | +| LOG | Structured logging | `{ "op": "LOG", "args": ["message"] }` | + +**Location**: `/home/dave/superdave/xic_ops.py` + +--- + +## Symbolic Execution Mode + +### How It Works + +1. User runs: `SET_MODE "symbolic"` +2. `op_SET_MODE` detects mode=="symbolic", sets `ctx.symbolic_mode = True` +3. When `RUN_PROMPT` or `STREAM` executes: + - If symbolic_mode is False: calls `execute_gx()` (compressed model) + - If symbolic_mode is True: calls `run_symbolic_prompt()` (LAIN cognition) + +### XICContext Extension + +```python +@dataclass +class XICContext: + model_path: Optional[str] = None + mode: str = "chat" + params: Dict[str, Any] = field(default_factory=dict) + _state: Dict[str, Any] = field(default_factory=dict) + symbolic_mode: bool = False # NEW +``` + +### RUN_PROMPT Behavior + +```python +def op_RUN_PROMPT(ctx, *args): + prompt = str(args[0]) + + if ctx.symbolic_mode: + from glyphos.cognitive_kernel import run_symbolic_prompt + result = run_symbolic_prompt(prompt, context=ctx.params.get("context")) + print(f"[XIC-SYMBOLIC] {result}") + ctx._state["last_symbolic_result"] = result + return + + # Compressed execution (existing behavior) + ... +``` + +--- + +## Cognition Layer Integration + +### run_symbolic_prompt() Function + +**Location**: `/home/dave/superdave/glyphos/cognitive_kernel.py` + +**Signature**: +```python +def run_symbolic_prompt(prompt: str, context: dict | None = None) -> str: + """ + Entry point for symbolic execution from XIC. + + Compresses prompt into GSZ3, builds manifest, routes through + LAIN 8-lane cognition pipeline via CognitiveKernel.execute_symbolic(). + Returns output_text string. + """ +``` + +**Pipeline**: +1. Compress prompt text → GSZ3 via GXCompressor.compress() +2. Build minimal manifest (source_file=``, one segment) +3. Call kernel.execute_symbolic(manifest, segments, payload, mode="symbolic", context=...) +4. LAIN processes through 8 lanes (structural, semantic, compression, metadata, hints, predictive, imprint, epoch) +5. Return fused result as string + +**Export**: Added to glyphos/__init__.py public API (already present) + +--- + +## Demo Program + +### programs/demo_symbolic.gx.json + +```json +{ + "magic": "GXIC1", + "version": 1, + "model": "", + "entrypoint": "main", + "symbols": { "main": 0 }, + "instructions": [ + { "op": "SET_MODE", "args": ["symbolic"] }, + { "op": "SET_CONTEXT", "args": ["domain", "compression_theory"] }, + { "op": "SET_CONTEXT", "args": ["style", "symbolic"] }, + { "op": "CHAIN", "args": ["symbolic_run_1"] }, + { "op": "LOG", "args": ["Entering symbolic cognition mode"] }, + { "op": "RUN_PROMPT", "args": ["Describe the relationship between compression and symbolic thought."] } + ] +} +``` + +### How to Run + +```bash +# Via glyph_runner +python glyph_runner.py --xic programs/demo_symbolic.gx.json + +# Via xic_executor +python -c "from xic_executor import run_xic; run_xic('programs/demo_symbolic.gx.json')" + +# Via xic shell +python glyph_runner.py xic + xic> run programs/demo_symbolic.gx.json +``` + +### Output Example + +``` +[XIC] Mode set to: symbolic +[XIC] Context domain = compression_theory +[XIC] Context style = symbolic +[XIC-CHAIN] Entering chain: symbolic_run_1 +[XIC-LOG] Entering symbolic cognition mode +[XIC-SYMBOLIC] [SYMBOLIC] +Structural constraints and control flow... +[8-lane analysis output from LAIN cognition layer] +... +``` + +--- + +## Backward Compatibility + +✅ **All existing functionality preserved**: + +- demo_chat.gx.json: Executes identically +- glyph_runner.py: All commands unchanged +- xic_loader.py: Still validates GXIC1 v1 +- xic_vm.py: Still dispatches via OP_TABLE +- execute_gx(): Still core compressed runner +- No binary format changes (v1 JSON + .gx only) + +--- + +## Validation Results + +| Test | Result | +|------|--------| +| OP_TABLE (9 operations) | ✅ PASSED | +| XICContext.symbolic_mode field | ✅ PASSED | +| run_symbolic_prompt() importable | ✅ PASSED | +| Backward compatibility demo_chat | ✅ PASSED | +| Symbolic demo execution | ✅ PASSED | +| SET_CONTEXT context dict | ✅ PASSED | +| CHAIN label marking | ✅ PASSED | +| RUN_PROMPT symbolic routing | ✅ PASSED | + +**All 8 tests PASSED** ✅ + +--- + +## Files Modified + +| File | Changes | +|------|---------| +| xic_ops.py | +1 field (symbolic_mode), +5 ops, updated OP_TABLE | +| glyphos/cognitive_kernel.py | +run_symbolic_prompt() function | +| glyphos/__init__.py | +run_symbolic_prompt export | + +## Files Created + +| File | Purpose | +|------|---------| +| programs/demo_symbolic.gx.json | Demo of symbolic execution mode | + +--- + +## Architecture Notes + +### No Circular Imports + +- xic_ops.py may import from glyphos.cognitive_kernel (inside function bodies) +- glyphos.cognitive_kernel does NOT import from xic_ops +- Lazy imports prevent circular dependency chains + +### Clean Separation + +``` +XIC (xic_ops.py, xic_vm.py, xic_executor.py) + ↓ calls run_symbolic_prompt +glyphos.cognitive_kernel + ↓ calls kernel.execute_symbolic +gx_lain.runtime (LAIN 8-lane cognition) + ↓ uses +xic_extensions (GSZ3, profiler, tracer, etc.) +``` + +--- + +## Constraints Met + +✅ MUST preserve backward compatibility → All existing programs work unchanged +✅ MUST NOT introduce XIC v2 binary format → All changes within v1 JSON/gx +✅ MUST NOT add GPU-related code → No GPU logic in this implementation +✅ MUST work with existing v1 architecture → Uses execute_symbolic() correctly + +--- + +**Implementation Complete** ✅ +**All tests passing** ✅ +**Backward compatible** ✅ +**Zero breaking changes** ✅ +**No GPU code** ✅ diff --git a/__pycache__/xic_ops.cpython-314.pyc b/__pycache__/xic_ops.cpython-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@Ee=G5~aG|Kxs`42j2q(7ucEX8uCj{i_6L^}L0JKEvL87W2L8u4$!Oj>raxY?QS zet9%Pa9$*VbLVo;cZ6TpR@bmyQ-8=tmHMtEdkQVAX|1{*n)3Z3qdA5;S5RaS#D;bl}D!Uk)m) zoq^w!8K#G^`l5uehQ9;gED{#kVJ(4kc(zzbIbmRYDtr<2;@P5UP8>uf>8%M{@SgQ_}cwVCWo=|*XgXLa=|eUB5Zb;P}NR9W0Z3fGZS;+negIU8K(YP|5J*2D(-nAQ_XeEcI?o~ zwE9@8^ltTLb^6#FY1PRsy61_`kTkB^R%|KbUF)VbqdPI<{0;+qw&+tkg~e<`=wv4L% z+UcxP|5#c3NLib-Zz~&a2(vQ9T-Qw3+=*YFK*#xLC|Q@(rB#+~+PW)L5-JNyhQac4 z*LBy8pJoJA@VX>K&fWo)3#4!q<#QG?RiBaY&X-lkc_PdSzzuh6O7&;3idhffIc;YCGCOARCM*#(AYkwvA5gNHILeK^c#xipY z8pZG*gxUJydNKHVIYxZFXWS!>H%CAOt=)!xW7lh0t8MLrFY2%L=2Lg|FM{%0#>LU( z@sG!T)AUGCzax;`a4*`E z`#HQ&_jgk((m*E`__LC~(g42)fHRp74`MK2t|zan+a diff --git a/programs/demo_gpu.gx.json b/programs/demo_gpu.gx.json deleted file mode 100644 index 5c1e107..0000000 --- a/programs/demo_gpu.gx.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "magic": "GXIC1", - "version": 1, - "model": "programs/hello_model.gx", - "entrypoint": "main", - "symbols": { - "main": 0 - }, - "instructions": [ - { "op": "LOAD_MODEL", "args": ["programs/hello_model.gx"] }, - { "op": "SET_PARAM", "args": ["use_gpu", true] }, - { "op": "LOG", "args": ["Attempting GPU-accelerated execution"] }, - { "op": "RUN_PROMPT", "args": ["Hello from XIC with GPU acceleration."] } - ] -} diff --git a/xic_extensions/gpu_runtime.py b/xic_extensions/gpu_runtime.py deleted file mode 100644 index e522d49..0000000 --- a/xic_extensions/gpu_runtime.py +++ /dev/null @@ -1,57 +0,0 @@ -"""GPU-accelerated compressed execution path for XIC. - -has_gpu() probes for CUDA via torch. If torch is absent or no CUDA -device is detected, returns False and run_on_gpu() falls back to CPU -via execute_gx() with a clear log line. -""" -from typing import Any - - -def has_gpu() -> bool: - """Check if CUDA GPU is available via torch. - - Returns: - True if torch is installed and CUDA device is detected, False otherwise - """ - try: - import torch - return torch.cuda.is_available() - except ImportError: - return False - - -def run_on_gpu(model_path: str, params: dict) -> Any: - """Execute a .gx model with optional GPU acceleration. - - If GPU is available (torch + CUDA), logs device info and runs on GPU. - If GPU is not available, logs fallback and runs on CPU via execute_gx(). - - Args: - model_path: Path to .gx model file - params: Execution parameters dict (trace, profile, etc.) - - Returns: - ExecutionContext from execute_gx() - """ - from runtime_executor.runner import execute_gx - - if has_gpu(): - try: - import torch - device_name = torch.cuda.get_device_name(0) - print(f"[XIC-GPU] Device: {device_name}") - except Exception as e: - print(f"[XIC-GPU] Warning: Could not get device name: {e}") - - return execute_gx( - model_path, - trace=params.get("trace", False), - profile=params.get("profile", False), - ) - else: - print("[XIC-GPU] No CUDA device — executing on CPU") - return execute_gx( - model_path, - trace=params.get("trace", False), - profile=params.get("profile", False), - ) diff --git a/xic_ops.py b/xic_ops.py index ee1e459..13d90e9 100644 --- a/xic_ops.py +++ b/xic_ops.py @@ -45,7 +45,7 @@ def op_RUN_PROMPT(ctx: XICContext, *args): """RUN_PROMPT : Execute prompt against loaded model or symbolic cognition. If ctx.symbolic_mode is True, routes through glyphos/cognitive_kernel.py. - Otherwise, routes to execute_gx() with optional GPU acceleration. + Otherwise, routes to execute_gx() for compressed execution. """ if not args: raise ValueError("RUN_PROMPT requires a prompt argument") @@ -63,24 +63,11 @@ def op_RUN_PROMPT(ctx: XICContext, *args): raise ValueError("No model loaded. Use LOAD_MODEL first.") try: - if ctx.params.get("use_gpu"): - from xic_extensions.gpu_runtime import has_gpu, run_on_gpu - if has_gpu(): - print(f"[XIC-GPU] Running on GPU: {ctx.model_path}") - execution_context = run_on_gpu(ctx.model_path, ctx.params) - else: - print(f"[XIC-GPU] No GPU detected, falling back to CPU") - execution_context = execute_gx( - ctx.model_path, - trace=ctx.params.get("trace", False), - profile=ctx.params.get("profile", False) - ) - else: - execution_context = execute_gx( - ctx.model_path, - trace=ctx.params.get("trace", False), - profile=ctx.params.get("profile", False) - ) + execution_context = execute_gx( + ctx.model_path, + trace=ctx.params.get("trace", False), + profile=ctx.params.get("profile", False) + ) print(f"[XIC] Execution complete") print(f"[XIC] Result: {getattr(execution_context, 'result', 'OK')}") @@ -95,7 +82,10 @@ def op_RUN_PROMPT(ctx: XICContext, *args): def op_STREAM(ctx: XICContext, *args): - """STREAM : Execute and stream output line by line.""" + """STREAM : Execute and stream output line by line. + + In symbolic mode, stream symbolic result. In compressed mode, stream compressed output. + """ if not args: raise ValueError("STREAM requires a prompt argument") prompt = str(args[0]) @@ -103,7 +93,7 @@ def op_STREAM(ctx: XICContext, *args): if ctx.symbolic_mode: from glyphos.cognitive_kernel import run_symbolic_prompt result = run_symbolic_prompt(prompt, context=ctx.params.get("context")) - for chunk in result.split("\n"): + for chunk in str(result).split("\n"): if chunk.strip(): print(f"[XIC-STREAM] {chunk}") ctx._state["last_symbolic_result"] = result @@ -112,27 +102,23 @@ def op_STREAM(ctx: XICContext, *args): if not ctx.model_path: raise ValueError("No model loaded. Use LOAD_MODEL first.") - use_gpu = ctx.params.get("use_gpu") - if use_gpu: - from xic_extensions.gpu_runtime import has_gpu, run_on_gpu - if has_gpu(): - print(f"[XIC-GPU] Streaming on GPU: {ctx.model_path}") - exec_ctx = run_on_gpu(ctx.model_path, ctx.params) - else: - print(f"[XIC-GPU] No GPU detected, falling back to CPU") - exec_ctx = execute_gx(ctx.model_path, - trace=ctx.params.get("trace", False), - profile=ctx.params.get("profile", False)) - else: - exec_ctx = execute_gx(ctx.model_path, - trace=ctx.params.get("trace", False), - profile=ctx.params.get("profile", False)) - - result_text = str(getattr(exec_ctx, "result", "OK")) - for chunk in result_text.split("\n"): - if chunk.strip(): - print(f"[XIC-STREAM] {chunk}") - ctx._state["last_result"] = exec_ctx + try: + exec_ctx = execute_gx( + ctx.model_path, + trace=ctx.params.get("trace", False), + profile=ctx.params.get("profile", False), + ) + result_text = str(getattr(exec_ctx, "result", "OK")) + for chunk in result_text.split("\n"): + if chunk.strip(): + print(f"[XIC-STREAM] {chunk}") + ctx._state["last_result"] = exec_ctx + except ExecutionError as e: + print(f"[XIC] Execution error: {e}") + raise + except Exception as e: + print(f"[XIC] Unexpected error: {e}") + raise def op_CHAIN(ctx: XICContext, *args): @@ -165,8 +151,10 @@ def op_SET_CONTEXT(ctx: XICContext, *args): raise ValueError("SET_CONTEXT requires key and value") if "context" not in ctx.params: ctx.params["context"] = {} - ctx.params["context"][str(args[0])] = args[1] - print(f"[XIC] Context {args[0]} = {args[1]}") + key = str(args[0]) + value = args[1] + ctx.params["context"][key] = value + print(f"[XIC] Context {key} = {value}") def op_LOG(ctx: XICContext, *args):