Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/hardware/virtual_hpc/cray_lux_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,4 +563,8 @@ def get_node(self, node_id: int) -> ComputeNode:
raise ValueError(f"Node {node_id} not found")

def get_total_performance(self) -> float:
"""Get total theo
"""Get total theoretical performance across all compute nodes."""
total_flops = 0.0
for node in self.compute_nodes:
total_flops += node.performance_gflops
return total_flops
7 changes: 6 additions & 1 deletion src/virtual_bio/dna_origami_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,4 +466,9 @@ def _generate_spherical_shell_layer(self, center: np.ndarray, radius: float, num
distances, indices = kdtree.query(point, k=4) # Self + 3 neighbors
for j in indices[1:]: # Skip self
if i < j: # Avoid duplicate connections
strand_id = f"shell_{int(r
strand_id = f"shell_{int(i)}_{int(j)}_dist_{distances[j]:.2f}"
self.strands.append({
'id': strand_id,
'points': [points_array[i], points_array[j]],
'length': distances[j]
})
41 changes: 22 additions & 19 deletions tests/integration/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

import pytest
import numpy as np
from src.core.microtubule_simulator import MicrotubuleSimulator
from src.core.microtubule_simulator import MicrotubuleSimulator, MicrotubuleConfig
from src.core.quantum_orch_or import QuantumOrchOR
from src.virtual_bio.ion_channel_dynamics import IonChannel
from src.virtual_bio.ion_channel_dynamics import IonChannel, IonChannelConfig, IonChannelType
from src.virtual_bio.synaptic_plasticity import SynapticPlasticity
from src.evaluation.consciousness_assessment import ConsciousnessAssessment
from src.evaluation.consciousness_assessment import ConsciousnessAssessor


class TestEndToEnd:
Expand All @@ -17,9 +17,9 @@ class TestEndToEnd:
def test_microtubule_to_consciousness_pipeline(self):
"""Test complete pipeline from microtubule simulation to consciousness assessment"""
# Initialize components
simulator = MicrotubuleSimulator(num_tubulins=100, length=1000.0)
orch_or = QuantumOrchOR(num_qubits=8, reduction_time=1e-3)
assessment = ConsciousnessAssessment()
simulator = MicrotubuleSimulator(config=MicrotubuleConfig(num_tubulins_per_filament=100, microtubule_length_nm=1000.0))
orch_or = QuantumOrchOR(num_tubulins=1000, coherence_time=1e-3, quantum_superposition_levels=8)
assessment = ConsciousnessAssessor()

# Simulate microtubule dynamics
simulator.initialize_quantum_state()
Expand Down Expand Up @@ -48,8 +48,9 @@ def test_microtubule_to_consciousness_pipeline(self):

def test_neural_plasticity_integration(self):
"""Test integration between ion channels and synaptic plasticity"""
ion_channel = IonChannelDynamics(num_channels=100, dt=0.01)
plasticity = SynapticPlasticity(num_neurons=100)
ion_channel = IonChannel(channel_type=IonChannelType.SODIUM, config=IonChannelConfig(time_step_ms=0.01, membrane_area_um2=1000.0), channel_density=100.0)
plasticity = SynapticPlasticity()
plasticity.initialize(n_neurons=100)

# Simulate action potentials
result = ion_channel.simulate_action_potential()
Expand All @@ -69,12 +70,13 @@ def test_neural_plasticity_integration(self):
def test_multiscale_simulation(self):
"""Test multiscale simulation across quantum and biological levels"""
# Quantum level
simulator = MicrotubuleSimulator(num_tubulins=100, length=1000.0)
orch_or = QuantumOrchOR(num_qubits=8, reduction_time=1e-3)
simulator = MicrotubuleSimulator(config=MicrotubuleConfig(num_tubulins_per_filament=100, microtubule_length_nm=1000.0))
orch_or = QuantumOrchOR(num_tubulins=1000, coherence_time=1e-3, quantum_superposition_levels=8)

# Biological level
ion_channel = IonChannelDynamics(num_channels=100, dt=0.01)
plasticity = SynapticPlasticity(num_neurons=100)
ion_channel = IonChannel(channel_type=IonChannelType.SODIUM, config=IonChannelConfig(time_step_ms=0.01, membrane_area_um2=1000.0), channel_density=100.0)
plasticity = SynapticPlasticity()
plasticity.initialize(n_neurons=100)

# Simulate quantum dynamics
simulator.initialize_quantum_state()
Expand All @@ -98,11 +100,12 @@ def test_multiscale_simulation(self):
def test_consciousness_assessment_pipeline(self):
"""Test complete consciousness assessment pipeline"""
# Setup components
simulator = MicrotubuleSimulator(num_tubulins=100, length=1000.0)
orch_or = QuantumOrchOR(num_qubits=8, reduction_time=1e-3)
ion_channel = IonChannelDynamics(num_channels=100, dt=0.01)
plasticity = SynapticPlasticity(num_neurons=100)
assessment = ConsciousnessAssessment()
simulator = MicrotubuleSimulator(config=MicrotubuleConfig(num_tubulins_per_filament=100, microtubule_length_nm=1000.0))
orch_or = QuantumOrchOR(num_tubulins=1000, coherence_time=1e-3, quantum_superposition_levels=8)
ion_channel = IonChannel(channel_type=IonChannelType.SODIUM, config=IonChannelConfig(time_step_ms=0.01, membrane_area_um2=1000.0), channel_density=100.0)
plasticity = SynapticPlasticity()
plasticity.initialize(n_neurons=100)
assessment = ConsciousnessAssessor()

# Run simulations
simulator.initialize_quantum_state()
Expand Down Expand Up @@ -138,7 +141,7 @@ def test_consciousness_assessment_pipeline(self):
def test_state_persistence_and_retrieval(self, temp_dir):
"""Test saving and loading complete system state"""
# Initialize and run simulation
simulator = MicrotubuleSimulator(num_tubulins=100, length=1000.0)
simulator = MicrotubuleSimulator(config=MicrotubuleConfig(num_tubulins_per_filament=100, microtubule_length_nm=1000.0))
simulator.initialize_quantum_state()
simulator.simulate_quantum_dynamics(dt=0.1, steps=10)

Expand All @@ -147,7 +150,7 @@ def test_state_persistence_and_retrieval(self, temp_dir):
simulator.save_state(str(state_file))

# Load state
new_simulator = MicrotubuleSimulator(num_tubulins=100, length=1000.0)
new_simulator = MicrotubuleSimulator(config=MicrotubuleConfig(num_tubulins_per_filament=100, microtubule_length_nm=1000.0))
new_simulator.load_state(str(state_file))

# Verify state preservation
Expand Down
16 changes: 10 additions & 6 deletions tests/unit/core/test_microtubule_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
import numpy as np
from src.core.microtubule_simulator import MicrotubuleSimulator
from src.core.microtubule_simulator import MicrotubuleSimulator, MicrotubuleConfig


class TestMicrotubuleSimulator:
Expand All @@ -13,14 +13,18 @@ class TestMicrotubuleSimulator:
@pytest.fixture
def simulator(self):
"""Create a MicrotubuleSimulator instance"""
return MicrotubuleSimulator(num_tubulins=100, length=1000.0)
config = MicrotubuleConfig(
num_tubulins_per_filament=100,
microtubule_length_nm=1000.0
)
return MicrotubuleSimulator(config)

def test_initialization(self, simulator):
"""Test simulator initialization"""
assert simulator.num_tubulins == 100
assert simulator.length == 1000.0
assert hasattr(simulator, "positions")
assert hasattr(simulator, "quantum_states")
assert simulator.config.num_tubulins_per_filament == 100
assert simulator.config.microtubule_length_nm == 1000.0
assert hasattr(simulator, "lattice")
assert hasattr(simulator, "coherence_sim")

def test_simulate_quantum_dynamics(self, simulator):
"""Test quantum dynamics simulation"""
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/core/test_penrose_gravitational_collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
import numpy as np
from src.core.penrose_gravitational_collapse import GravitationalCollapseCalculator
from src.core.penrose_gravitational_collapse import GravitationalCollapseCalculator, PenroseParameters


class TestPenroseGravitationalCollapse:
Expand All @@ -13,13 +13,15 @@ class TestPenroseGravitationalCollapse:
@pytest.fixture
def collapse(self):
"""Create a PenroseGravitationalCollapse instance"""
return GravitationalCollapseCalculator(mass=1e-26, energy=1e-10)
params = PenroseParameters(
tubulin_mass=1e-26
)
return GravitationalCollapseCalculator(params)

def test_initialization(self, collapse):
"""Test collapse model initialization"""
assert collapse.mass == 1e-26
assert collapse.energy == 1e-10
assert hasattr(collapse, "reduction_time")
assert collapse.params.tubulin_mass == 1e-26
assert hasattr(collapse, "calculate_collapse_time")

def test_compute_reduction_time(self, collapse):
"""Test reduction time computation"""
Expand Down
12 changes: 8 additions & 4 deletions tests/unit/core/test_quantum_orch_or.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ class TestQuantumOrchOR:
@pytest.fixture
def orch_or(self):
"""Create a QuantumOrchOR instance"""
return QuantumOrchOR(num_qubits=8, reduction_time=1e-3)
return QuantumOrchOR(
num_tubulins=1000,
coherence_time=1e-3,
quantum_superposition_levels=8
)

def test_initialization(self, orch_or):
"""Test OrchOR initialization"""
assert orch_or.num_qubits == 8
assert orch_or.reduction_time == 1e-3
assert hasattr(orch_or, "quantum_state")
assert orch_or.num_tubulins == 1000
assert orch_or.coherence_time == 1e-3
assert orch_or.quantum_superposition_levels == 8

def test_initialize_superposition(self, orch_or):
"""Test quantum superposition initialization"""
Expand Down
18 changes: 13 additions & 5 deletions tests/unit/virtual_bio/test_ion_channel_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
import numpy as np
from src.virtual_bio.ion_channel_dynamics import IonChannel
from src.virtual_bio.ion_channel_dynamics import IonChannel, IonChannelConfig, IonChannelType


class TestIonChannelDynamics:
Expand All @@ -13,13 +13,21 @@ class TestIonChannelDynamics:
@pytest.fixture
def ion_channel(self):
"""Create an IonChannelDynamics instance"""
return IonChannel(num_channels=100, voltage_range=(-80, 40), dt=0.01)
config = IonChannelConfig(
time_step_ms=0.01,
membrane_area_um2=1000.0
)
return IonChannel(
channel_type=IonChannelType.SODIUM,
config=config,
channel_density=100.0
)

def test_initialization(self, ion_channel):
"""Test ion channel initialization"""
assert ion_channel.num_channels == 100
assert ion_channel.voltage_range == (-80, 40)
assert ion_channel.dt == 0.01
assert ion_channel.channel_density == 100.0
assert ion_channel.config.time_step_ms == 0.01
assert ion_channel.config.membrane_area_um2 == 1000.0

def test_simulate_voltage_step(self, ion_channel):
"""Test voltage step simulation"""
Expand Down
51 changes: 31 additions & 20 deletions tests/unit/virtual_bio/test_synaptic_plasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,87 @@ class TestSynapticPlasticity:
@pytest.fixture
def plasticity(self):
"""Create a SynapticPlasticity instance"""
return SynapticPlasticity(num_neurons=100, initial_weight=0.5, learning_rate=0.01)
config = {
"stdp_learning_rate": 0.01,
"stdp_tau_plus": 20.0,
"stdp_tau_minus": 20.0,
"stdp_a_plus": 0.1,
"stdp_a_minus": 0.1,
"homeostatic_target": 1.0,
"homeostatic_rate": 0.001,
}
plasticity = SynapticPlasticity(config)
plasticity.initialize(n_neurons=100)
return plasticity

def test_initialization(self, plasticity):
"""Test synaptic plasticity initialization"""
assert plasticity.num_neurons == 100
assert plasticity.learning_rate == 0.01
assert plasticity.weights is not None
assert plasticity.weights.shape == (100, 100)
assert plasticity.n_neurons == 100
assert plasticity.config["stdp_learning_rate"] == 0.01
assert plasticity.synaptic_weights is not None
assert plasticity.synaptic_weights.shape == (100, 100)

def test_apply_hebbian_learning(self, plasticity):
"""Test Hebbian learning application"""
pre_synaptic = np.random.rand(100)
post_synaptic = np.random.rand(100)

initial_weights = plasticity.weights.copy()
initial_weights = plasticity.synaptic_weights.copy()
plasticity.apply_hebbian_learning(pre_synaptic, post_synaptic)

assert not np.array_equal(plasticity.weights, initial_weights)
assert not np.array_equal(plasticity.synaptic_weights, initial_weights)

def test_apply_stdp(self, plasticity):
"""Test Spike-Timing-Dependent Plasticity"""
pre_times = np.sort(np.random.rand(100) * 100)
post_times = np.sort(np.random.rand(100) * 100)

initial_weights = plasticity.weights.copy()
initial_weights = plasticity.synaptic_weights.copy()
plasticity.apply_stdp(pre_times, post_times)

assert not np.array_equal(plasticity.weights, initial_weights)
assert not np.array_equal(plasticity.synaptic_weights, initial_weights)

def test_apply_anti_hebbian(self, plasticity):
"""Test anti-Hebbian learning"""
pre_synaptic = np.random.rand(100)
post_synaptic = np.random.rand(100)

initial_weights = plasticity.weights.copy()
initial_weights = plasticity.synaptic_weights.copy()
plasticity.apply_anti_hebbian(pre_synaptic, post_synaptic)

assert not np.array_equal(plasticity.weights, initial_weights)
assert not np.array_equal(plasticity.synaptic_weights, initial_weights)

def test_normalize_weights(self, plasticity):
"""Test weight normalization"""
plasticity.weights = np.random.rand(100, 100) * 10
plasticity.synaptic_weights = np.random.rand(100, 100) * 10
plasticity.normalize_weights()

max_weight = np.max(plasticity.weights)
max_weight = np.max(plasticity.synaptic_weights)
assert max_weight <= 1.0

def test_simulate_long_term_potentiation(self, plasticity):
"""Test LTP simulation"""
stimulus_strength = 0.8
duration = 100

initial_weights = plasticity.weights.copy()
initial_weights = plasticity.synaptic_weights.copy()
plasticity.simulate_long_term_potentiation(stimulus_strength, duration)

assert not np.array_equal(plasticity.weights, initial_weights)
assert not np.array_equal(plasticity.synaptic_weights, initial_weights)
# LTP should strengthen weights
assert np.mean(plasticity.weights) > np.mean(initial_weights)
assert np.mean(plasticity.synaptic_weights) > np.mean(initial_weights)

def test_simulate_long_term_depression(self, plasticity):
"""Test LTD simulation"""
stimulus_strength = 0.8
duration = 100

initial_weights = plasticity.weights.copy()
initial_weights = plasticity.synaptic_weights.copy()
plasticity.simulate_long_term_depression(stimulus_strength, duration)

assert not np.array_equal(plasticity.weights, initial_weights)
assert not np.array_equal(plasticity.synaptic_weights, initial_weights)
# LTD should weaken weights
assert np.mean(plasticity.weights) < np.mean(initial_weights)
assert np.mean(plasticity.synaptic_weights) < np.mean(initial_weights)

def test_save_weights(self, plasticity, temp_dir):
"""Test saving weights"""
Expand All @@ -99,4 +110,4 @@ def test_load_weights(self, plasticity, temp_dir):
new_plasticity = SynapticPlasticity(num_neurons=100)
new_plasticity.load_weights(str(filepath))

np.testing.assert_array_equal(plasticity.weights, new_plasticity.weights)
np.testing.assert_array_equal(plasticity.synaptic_weights, new_plasticity.synaptic_weights)
Loading