|
|
"""
|
|
|
Deep Dive: Export Capabilities
|
|
|
|
|
|
Testing the capsule agent's self-export capabilities:
|
|
|
1. export_pt() - PyTorch format
|
|
|
2. export_onnx() - ONNX for deployment
|
|
|
3. export_capsule() - Self-replicating quine!
|
|
|
|
|
|
The quine capability is special - the model can export itself
|
|
|
as a complete, self-contained Python module!
|
|
|
"""
|
|
|
|
|
|
import os
|
|
|
import champion_gen42 as ch
|
|
|
|
|
|
print("=" * 60)
|
|
|
print("📦 Capsule Export Capabilities")
|
|
|
print("=" * 60)
|
|
|
|
|
|
|
|
|
agent = ch.CapsuleAgent()
|
|
|
|
|
|
|
|
|
print(f"\n=== Current Quine Info ===")
|
|
|
print(f"Quine hash: {ch.get_quine_hash()}")
|
|
|
print(f"Integrity: {ch.verify_quine_integrity()}")
|
|
|
|
|
|
|
|
|
export_dir = "exports"
|
|
|
os.makedirs(export_dir, exist_ok=True)
|
|
|
|
|
|
|
|
|
print(f"\n=== Testing export_capsule() ===")
|
|
|
print("This creates a self-contained Python module...")
|
|
|
|
|
|
capsule_path = agent.export_capsule(os.path.join(export_dir, "child_capsule.py"))
|
|
|
print(f"Exported to: {capsule_path}")
|
|
|
|
|
|
|
|
|
if capsule_path and os.path.exists(capsule_path):
|
|
|
size = os.path.getsize(capsule_path)
|
|
|
print(f"File size: {size / 1024 / 1024:.2f} MB")
|
|
|
|
|
|
|
|
|
with open(capsule_path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
|
lines = f.readlines()[:30]
|
|
|
|
|
|
print("\n=== First 30 lines of exported capsule ===")
|
|
|
for i, line in enumerate(lines, 1):
|
|
|
print(f"{i:3d}: {line.rstrip()[:80]}")
|
|
|
|
|
|
print(f"\n... ({len(lines)} of total lines shown)")
|
|
|
|
|
|
|
|
|
print("\n=== Verifying exported capsule ===")
|
|
|
try:
|
|
|
import importlib.util
|
|
|
spec = importlib.util.spec_from_file_location("child", capsule_path)
|
|
|
child = importlib.util.module_from_spec(spec)
|
|
|
spec.loader.exec_module(child)
|
|
|
|
|
|
if hasattr(child, 'get_quine_hash'):
|
|
|
child_hash = child.get_quine_hash()
|
|
|
print(f"Child quine hash: {child_hash}")
|
|
|
print(f"Parent quine hash: {ch.get_quine_hash()}")
|
|
|
print(f"Hashes match: {child_hash == ch.get_quine_hash()}")
|
|
|
|
|
|
if hasattr(child, 'verify_quine_integrity'):
|
|
|
print(f"Child integrity: {child.verify_quine_integrity()}")
|
|
|
|
|
|
except Exception as e:
|
|
|
print(f"Could not verify child: {e}")
|
|
|
else:
|
|
|
print("Export may not have created a file")
|
|
|
|
|
|
|
|
|
print("\n=== Testing replicate_quine() ===")
|
|
|
replica_path = ch.replicate_quine(os.path.join(export_dir, "replica.py"))
|
|
|
print(f"Replicated to: {replica_path}")
|
|
|
|
|
|
if replica_path and os.path.exists(replica_path):
|
|
|
replica_size = os.path.getsize(replica_path)
|
|
|
original_size = os.path.getsize("champion_gen42.py")
|
|
|
print(f"Original size: {original_size / 1024 / 1024:.2f} MB")
|
|
|
print(f"Replica size: {replica_size / 1024 / 1024:.2f} MB")
|
|
|
print(f"Size match: {abs(replica_size - original_size) < 1000}")
|
|
|
|