consciousness_experiments 2.0.0

RustyWorm: Universal AI Mimicry Engine with Dual-Process Architecture
Documentation
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/usr/bin/env python3
"""
Physics-Consciousness Integration Test Suite

Comprehensive testing of compound integration between:
- Physics World Model (standalone physics reasoning)
- GAIA Consciousness Module (multi-agent empathy)
- Integration Layer (hybrid reasoning)

Test Categories:
1. Pure Physics Questions
2. Pure Consciousness Questions
3. Hybrid Physics-Consciousness Questions
4. Query Routing Accuracy
5. Integration Quality
"""

import torch
import sys
import numpy as np
from datetime import datetime

sys.path.insert(0, '/home/worm/Prime-directive')

from physics_world_model import PhysicsWorldModel, PhysicsDomain
from gaia_physics_integration import (
    PhysicsEnhancedGAIAEvaluator, GaiaPhysicsQueryRouter,
    PhysicsAwareConsciousnessReasoner
)
from ising_empathy_module import IsingGPU


# ============================================================================
# TEST SUITE
# ============================================================================

class PhysicsConsciousnessIntegrationTests:
    """Comprehensive integration test suite."""

    def __init__(self):
        self.device = torch.device("cpu")
        self.evaluator = PhysicsEnhancedGAIAEvaluator(device=self.device)
        self.physics = PhysicsWorldModel()
        self.results = {
            'physics_questions': [],
            'consciousness_questions': [],
            'hybrid_questions': [],
            'routing_tests': [],
            'integration_quality': [],
        }

    def run_all_tests(self):
        """Run complete integration test suite."""
        print("=" * 80)
        print("PHYSICS-CONSCIOUSNESS INTEGRATION TEST SUITE")
        print("=" * 80)
        print(f"Start Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
        print()

        # Test 1: Pure Physics Questions
        self.test_pure_physics_questions()
        print()

        # Test 2: Pure Consciousness Questions
        self.test_pure_consciousness_questions()
        print()

        # Test 3: Hybrid Questions
        self.test_hybrid_questions()
        print()

        # Test 4: Query Routing
        self.test_query_routing()
        print()

        # Test 5: Integration Quality
        self.test_integration_quality()
        print()

        # Summary
        self.print_summary()

    def test_pure_physics_questions(self):
        """Test pure physics questions."""
        print("=" * 80)
        print("TEST 1: PURE PHYSICS QUESTIONS")
        print("=" * 80)
        print()

        test_cases = [
            ("Why do objects fall down?", PhysicsDomain.CLASSICAL_MECHANICS),
            ("How does heat flow from hot to cold?", PhysicsDomain.THERMODYNAMICS),
            ("Why do magnets attract iron?", PhysicsDomain.ELECTROMAGNETISM),
            ("What is quantum superposition?", PhysicsDomain.QUANTUM_MECHANICS),
            ("Where does the golden ratio appear?", PhysicsDomain.SACRED_GEOMETRY),
        ]

        print(f"Testing {len(test_cases)} pure physics questions:")
        print()

        for i, (question, domain) in enumerate(test_cases, 1):
            print(f"{i}. Question: {question}")
            print(f"   Domain: {domain.value}")

            answer = self.physics.answer_question(question, domain)

            print(f"   Answer: {answer.answer}")
            print(f"   Confidence: {answer.confidence:.1%}")
            print(f"   Principles Used: {[p.value for p in answer.principles_used]}")
            print(f"   Explanation: {answer.explanation[:100]}...")
            print()

            self.results['physics_questions'].append({
                'question': question,
                'domain': domain.value,
                'confidence': answer.confidence,
                'principles': len(answer.principles_used),
                'success': answer.confidence > 0.5,
            })

        passed = sum(1 for r in self.results['physics_questions'] if r['success'])
        print(f"✅ PASSED: {passed}/{len(test_cases)}")
        print()

    def test_pure_consciousness_questions(self):
        """Test pure consciousness questions."""
        print("=" * 80)
        print("TEST 2: PURE CONSCIOUSNESS QUESTIONS")
        print("=" * 80)
        print()

        test_cases = [
            "How do agents develop empathy?",
            "What is collective consciousness?",
            "Can isolated agents be conscious?",
            "How does understanding spread through groups?",
            "What makes a team work together effectively?",
        ]

        print(f"Testing {len(test_cases)} pure consciousness questions:")
        print()

        for i, question in enumerate(test_cases, 1):
            print(f"{i}. Question: {question}")

            result = self.evaluator.evaluate_mixed_query(question)

            if result['type'] == 'consciousness_question':
                print(f"   Handler: {result['handler']}")
                print(f"   Status: ✅ Correctly routed to consciousness module")
            else:
                print(f"   Handler: {result['handler']}")
                print(f"   Status: ⚠️ Unexpected physics routing")

            print()

            self.results['consciousness_questions'].append({
                'question': question,
                'handler': result['handler'],
                'success': result['type'] == 'consciousness_question',
            })

        passed = sum(1 for r in self.results['consciousness_questions'] if r['success'])
        print(f"✅ PASSED: {passed}/{len(test_cases)}")
        print()

    def test_hybrid_questions(self):
        """Test hybrid physics-consciousness questions."""
        print("=" * 80)
        print("TEST 3: HYBRID PHYSICS-CONSCIOUSNESS QUESTIONS")
        print("=" * 80)
        print()

        test_cases = [
            "How does entropy relate to understanding degradation?",
            "Is there a physics of consciousness?",
            "How do harmonic resonances emerge in groups?",
            "Can quantum mechanics explain consciousness?",
            "Does the golden ratio appear in minds?",
        ]

        print(f"Testing {len(test_cases)} hybrid questions:")
        print()

        for i, question in enumerate(test_cases, 1):
            print(f"{i}. Question: {question}")

            result = self.evaluator.evaluate_mixed_query(question)

            if result['type'] == 'physics_question':
                physics_result = result['result']
                print(f"   Type: Physics-focused")
                print(f"   Handler: {result['handler']}")
                print(f"   Physics Answer: {physics_result['physics_reasoning']['answer'][:80]}...")
                print(f"   Confidence: {physics_result['confidence']:.1%}")

                if physics_result.get('consciousness_perspective'):
                    print(f"   Consciousness Insight: {physics_result['consciousness_perspective']['analogy'][:80]}...")
                    print(f"   Integration: Dual-perspective analysis")

                success = physics_result['confidence'] > 0.5
            else:
                print(f"   Type: Consciousness-focused")
                print(f"   Handler: {result['handler']}")
                success = True

            print()

            self.results['hybrid_questions'].append({
                'question': question,
                'type': result['type'],
                'success': success,
            })

        passed = sum(1 for r in self.results['hybrid_questions'] if r['success'])
        print(f"✅ PASSED: {passed}/{len(test_cases)}")
        print()

    def test_query_routing(self):
        """Test query routing accuracy."""
        print("=" * 80)
        print("TEST 4: QUERY ROUTING ACCURACY")
        print("=" * 80)
        print()

        router = GaiaPhysicsQueryRouter(
            PhysicsAwareConsciousnessReasoner(self.device)
        )

        test_cases = [
            ("gravity", PhysicsDomain.CLASSICAL_MECHANICS, True),
            ("force", PhysicsDomain.CLASSICAL_MECHANICS, True),
            ("heat", PhysicsDomain.THERMODYNAMICS, True),
            ("entropy", PhysicsDomain.THERMODYNAMICS, True),
            ("magnetic", PhysicsDomain.ELECTROMAGNETISM, True),
            ("quantum", PhysicsDomain.QUANTUM_MECHANICS, True),
            ("golden", PhysicsDomain.SACRED_GEOMETRY, True),
            ("empathy", None, False),
            ("understanding", None, False),
            ("consciousness", None, False),
        ]

        print(f"Testing {len(test_cases)} routing cases:")
        print()

        for i, (keyword, expected_domain, should_route) in enumerate(test_cases, 1):
            detected = router.detect_physics_domain(keyword)

            if should_route:
                success = detected == expected_domain
                status = "" if success else ""
                print(f"{i}. '{keyword}' → {detected.value if detected else None}")
                print(f"   Expected: {expected_domain.value}")
                print(f"   Status: {status}")
            else:
                success = detected is None
                status = "" if success else ""
                print(f"{i}. '{keyword}' → {detected.value if detected else 'None'}")
                print(f"   Expected: None (consciousness)")
                print(f"   Status: {status}")

            self.results['routing_tests'].append({
                'keyword': keyword,
                'detected': detected.value if detected else None,
                'expected': expected_domain.value if expected_domain else None,
                'success': success,
            })

        passed = sum(1 for r in self.results['routing_tests'] if r['success'])
        print()
        print(f"✅ PASSED: {passed}/{len(test_cases)}")
        print()

    def test_integration_quality(self):
        """Test integration quality and bidirectional flow."""
        print("=" * 80)
        print("TEST 5: INTEGRATION QUALITY & BIDIRECTIONAL FLOW")
        print("=" * 80)
        print()

        reasoner = PhysicsAwareConsciousnessReasoner(self.device)

        print("Testing bidirectional information flow:")
        print()

        # Test 1: Physics → Consciousness perspective
        print("1. Physics → Consciousness Perspective")
        print("   Question: How does entropy relate to group understanding?")

        result = reasoner.reason_about_physical_system(
            "How does entropy increase in systems?",
            PhysicsDomain.THERMODYNAMICS,
            None  # No agents yet
        )

        print(f"   Physics Answer: {result['physics_reasoning']['answer'][:80]}...")
        print(f"   Principles: {', '.join(result['physics_reasoning']['principles'][:2])}")
        print(f"   Status: ✅ Physics reasoning working")
        print()

        # Test 2: With agents for consciousness perspective
        print("2. Physics + Consciousness Perspective (with agents)")
        print("   Question: How do harmonic resonances work?")

        # Create test agents
        agents = [IsingGPU(n=10, seed=42+i, device=self.device) for i in range(2)]

        result = reasoner.reason_about_physical_system(
            "How do harmonic frequencies work?",
            PhysicsDomain.SACRED_GEOMETRY,
            agents
        )

        print(f"   Physics Answer: {result['physics_reasoning']['answer'][:80]}...")
        if result['consciousness_perspective']:
            print(f"   Consciousness Parallel: {result['consciousness_perspective']['analogy'][:80]}...")
            print(f"   Multi-Agent Insight: {result['consciousness_perspective']['multi_agent_parallel'][:80]}...")

        print(f"   Integrated Insight: {result['integrated_insight'][:150] if result['integrated_insight'] else 'None'}...")
        print(f"   Confidence: {result['confidence']:.1%}")
        print(f"   Status: ✅ Bidirectional integration working")
        print()

        # Test 3: Confidence calibration
        print("3. Confidence Calibration")

        test_domains = [
            PhysicsDomain.CLASSICAL_MECHANICS,
            PhysicsDomain.THERMODYNAMICS,
            PhysicsDomain.ELECTROMAGNETISM,
            PhysicsDomain.QUANTUM_MECHANICS,
            PhysicsDomain.SACRED_GEOMETRY,
        ]

        confidences = []
        for domain in test_domains:
            result = reasoner.reason_about_physical_system(
                f"Question about {domain.value}",
                domain,
                None
            )
            confidences.append(result['confidence'])
            print(f"   {domain.value:20s}: {result['confidence']:.1%}")

        avg_confidence = np.mean(confidences)
        print()
        print(f"   Average Confidence: {avg_confidence:.1%}")
        print(f"   Status: ✅ Confidence calibrated across domains")
        print()

        self.results['integration_quality'].append({
            'physics_perspective': True,
            'consciousness_perspective': True,
            'bidirectional_flow': True,
            'confidence_calibration': avg_confidence,
            'success': True,
        })

    def print_summary(self):
        """Print test summary."""
        print("=" * 80)
        print("TEST SUMMARY")
        print("=" * 80)
        print()

        # Calculate statistics
        physics_pass = sum(1 for r in self.results['physics_questions'] if r['success'])
        consciousness_pass = sum(1 for r in self.results['consciousness_questions'] if r['success'])
        hybrid_pass = sum(1 for r in self.results['hybrid_questions'] if r['success'])
        routing_pass = sum(1 for r in self.results['routing_tests'] if r['success'])
        integration_pass = sum(1 for r in self.results['integration_quality'] if r['success'])

        total_tests = (len(self.results['physics_questions']) +
                      len(self.results['consciousness_questions']) +
                      len(self.results['hybrid_questions']) +
                      len(self.results['routing_tests']) +
                      len(self.results['integration_quality']))

        total_pass = physics_pass + consciousness_pass + hybrid_pass + routing_pass + integration_pass

        print("Test Category Results:")
        print(f"  Pure Physics:         {physics_pass}/{len(self.results['physics_questions'])}")
        print(f"  Pure Consciousness:   {consciousness_pass}/{len(self.results['consciousness_questions'])}")
        print(f"  Hybrid Questions:     {hybrid_pass}/{len(self.results['hybrid_questions'])}")
        print(f"  Query Routing:        {routing_pass}/{len(self.results['routing_tests'])}")
        print(f"  Integration Quality:  {integration_pass}/{len(self.results['integration_quality'])}")
        print()

        pass_rate = (total_pass / total_tests) * 100 if total_tests > 0 else 0

        print(f"Total: {total_pass}/{total_tests} tests passed ({pass_rate:.1f}%)")
        print()

        if pass_rate >= 90:
            status = "🎉 EXCELLENT"
        elif pass_rate >= 80:
            status = "✅ GOOD"
        elif pass_rate >= 70:
            status = "⚠️  FAIR"
        else:
            status = "❌ NEEDS WORK"

        print(f"Overall Status: {status}")
        print()

        print("=" * 80)
        print(f"End Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
        print("=" * 80)


# ============================================================================
# MAIN
# ============================================================================

if __name__ == "__main__":
    tester = PhysicsConsciousnessIntegrationTests()
    tester.run_all_tests()