-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_physics_prototyping.py
More file actions
152 lines (118 loc) · 5.48 KB
/
test_physics_prototyping.py
File metadata and controls
152 lines (118 loc) · 5.48 KB
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
"""
Test script for the new Physics Prototyping System integration with Mad Scientist.
"""
import pytest
import pytest_asyncio
import asyncio
import sys
import os
# Add the project root directory to the Python path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__))))
from modules.physics_prototyping_system import PhysicsPrototypingSystem
from modules.physics_analysis_system import PhysicsDomain
from modules.mad_scientist_system import MadScientistSystem
class MockBlogScheduler:
async def register_learning_event(self, **kwargs):
print(f"Blog event registered: {kwargs.get('topic', 'Unknown topic')}")
return True
@pytest_asyncio.fixture
async def mock_blog_scheduler():
"""Create a mock blog scheduler for testing."""
return MockBlogScheduler()
@pytest_asyncio.fixture
async def physics_prototyper(mock_blog_scheduler):
"""Create a physics prototyper instance with mock dependencies."""
prototyper = PhysicsPrototypingSystem(None, mock_blog_scheduler)
# Set up a mock AGI system
prototyper.agi_system = type('MockAGISystem', (), {
'memory_service': type('MockMemoryService', (), {
'retrieve_relevant_memories': lambda query, top_k=5: []
})(),
'knowledge_service': type('MockKnowledgeService', (), {
'add_knowledge': lambda content, source, category: None
})()
})()
return prototyper
@pytest.mark.asyncio
async def test_basic_physics_simulation(physics_prototyper):
"""Test the basic physics simulation functionality."""
result = await physics_prototyper.prototype_physics_experiment(
"Test hypothesis: How does a ball fall under gravity?",
PhysicsDomain.MECHANICS
)
assert result.success is True
assert len(result.data) > 0
assert result.simulation_type is not None
assert result.analysis is not None
@pytest.mark.asyncio
async def test_quantum_mechanics_simulation(physics_prototyper):
"""Test quantum mechanics simulation."""
from modules.physics_prototyping_system import SimulationType
result = await physics_prototyper.prototype_physics_experiment(
"Quantum tunneling through a potential barrier",
PhysicsDomain.QUANTUM_MECHANICS
)
assert result.success is True
assert len(result.data) > 0
# Quantum mechanics experiments often default to theoretical physics
assert result.simulation_type in [SimulationType.QUANTUM_SIMULATION,
SimulationType.THEORETICAL_PHYSICS]
@pytest.mark.asyncio
async def test_impossible_physics_simulation(physics_prototyper):
"""Test simulation of impossible physics concepts."""
result = await physics_prototyper.prototype_physics_experiment(
"Perpetual motion machine that violates conservation of energy",
PhysicsDomain.THERMODYNAMICS
)
assert result.success is True
# Impossible physics experiments should typically be refuted or inconclusive
assert result.analysis.get('support') in ['refute', 'inconclusive', 'impossible']
@pytest.mark.asyncio
async def test_prototyping_metrics(physics_prototyper):
"""Test that metrics are properly calculated."""
# First run a simulation to generate data
await physics_prototyper.prototype_physics_experiment(
"Test hypothesis: How does a ball fall under gravity?",
PhysicsDomain.MECHANICS
)
metrics = await physics_prototyper.get_prototyping_metrics()
assert 'total_simulations' in metrics
assert 'success_rate' in metrics
assert metrics['total_simulations'] >= 1
assert 0.0 <= metrics['success_rate'] <= 1.0
@pytest.mark.asyncio
async def test_mad_scientist_integration(mock_blog_scheduler):
"""Test the integration with the mad scientist system."""
# Create the physics prototyping system that would be part of the AGI system
physics_prototyper = PhysicsPrototypingSystem(None, mock_blog_scheduler)
# Set up a mock AGI system with the prototyper
agi_system = type('MockAGISystem', (), {
'blog_scheduler': mock_blog_scheduler,
'memory_service': type('MockMemoryService', (), {
'retrieve_relevant_memories': lambda query, top_k=5: []
})(),
'knowledge_service': type('MockKnowledgeService', (), {
'add_knowledge': lambda content, source, category: None
})(),
# Add the physics prototyping system that we'll test integration with
'physics_prototyping_system': physics_prototyper
})()
# Set the agi_system reference in the physics prototyper
physics_prototyper.agi_system = agi_system
# Initialize the mad scientist system
mad_scientist = MadScientistSystem(agi_system, mock_blog_scheduler)
# Verify the mad scientist system has a reference to the physics prototyper
assert hasattr(mad_scientist, 'physics_prototyper')
# Verify it's the same instance as the AGI system
assert mad_scientist.physics_prototyper is physics_prototyper
# Test that it can call the physics prototyping system
result = await mad_scientist.physics_prototyper.prototype_physics_experiment(
"Simple test: object falling under gravity",
PhysicsDomain.MECHANICS
)
assert result.success is True
assert result.simulation_type is not None
# Test metrics integration
metrics = await mad_scientist.get_mad_scientist_metrics()
assert 'physics_prototyping_metrics' in metrics
assert metrics['physics_prototyping_metrics'] is not None