The nlp2cmd.generation.thermodynamic module integrates Whitelam’s generative thermodynamic computing framework for solving complex optimization problems that traditional DSL generation cannot handle.
Natural Language → HybridThermodynamicGenerator → Solution
│
├─ Rule/LLM → DSL Commands (simple queries)
└─ Langevin → Optimization Solutions (complex problems)
Generates solutions using Langevin dynamics sampling:
from nlp2cmd.generation import create_thermodynamic_generator
# Create generator
thermo = create_thermodynamic_generator(
n_samples=5, # Multiple solutions
n_steps=500, # Langevin steps
)
# Generate solution
result = await thermo.generate("Zaplanuj 5 zadań w 10 slotach")
print(result.decoded_output)
# → Schedule:
# Slot 0: task_0
# Slot 2: task_1
# Slot 4: task_2
Domain-specific energy functions for constraint satisfaction:
Routes between DSL generation and thermodynamic optimization:
from nlp2cmd.generation import HybridThermodynamicGenerator
generator = HybridThermodynamicGenerator()
# Simple query → DSL generation
result = await generator.generate("PokaĹĽ uĹĽytkownikĂłw")
# → {'source': 'dsl', 'result': HybridResult(...)}
# Optimization → Thermodynamic sampling
result = await generator.generate("Zoptymalizuj przydzielanie zasobĂłw")
# → {'source': 'thermodynamic', 'result': ThermodynamicResult(...)}
Input: "Zaplanuj 5 zadań w 10 slotach, zadanie 3 musi być przed slotem 5"
Output:
# Schedule:
Slot 0: task_0
Slot 2: task_1
Slot 4: task_2
Slot 6: task_3
Slot 8: task_4
Input: "Przydziel 3 zasoby do 4 konsumentów, nie przekraczaj pojemności"
Output:
# Allocation:
Consumer 0: R0=0.25, R1=0.50, R2=0.25
Consumer 1: R0=0.33, R1=0.33, R2=0.33
Consumer 2: R0=0.20, R1=0.40, R2=0.40
Consumer 3: R0=0.50, R1=0.25, R2=0.25
| Metric | DSL Generation | Thermodynamic |
|---|---|---|
| Latency | ~2ms | ~150-500ms |
| Cost | $0 | ~$0.01 |
| Accuracy | High for simple queries | Optimal for constraints |
| Energy | Minimal | ~10-50mJ |
The thermodynamic approach provides significant energy savings:
result = await thermo.generate("Complex scheduling problem")
print(result.energy_estimate)
# → {
# 'savings_digital_percent': 65.2,
# 'savings_analog_percent': 98.7,
# 'breakdown': {
# 'llm_formalization': 0.003,
# 'langevin_digital': 0.15,
# 'langevin_analog': 0.005
# }
# }
from nlp2cmd.generation import (
create_hybrid_generator,
create_thermodynamic_generator,
)
# Hybrid for mixed workloads
hybrid = create_hybrid_generator()
result = await hybrid.generate("PokaĹĽ dane z tabeli users")
# → Uses rules (2ms, $0)
result = await hybrid.generate("Zaplanuj zadania z ograniczeniami")
# → Uses thermodynamic (~200ms, ~$0.01)
from nlp2cmd.generation.thermodynamic import (
ThermodynamicGenerator,
ConstraintEnergy,
LangevinConfig,
)
# Custom constraint energy
energy = ConstraintEnergy()
energy.add_penalty(
"custom_constraint",
lambda z, c: violation_function(z, c),
lambda z, c: gradient_function(z, c),
weight=10.0
)
generator = ThermodynamicGenerator(
energy_model=energy,
langevin_config=LangevinConfig(n_steps=1000)
)
problems = [
"Zaplanuj 3 zadania",
"Przydziel 2 zasoby",
"Zoptymalizuj trasÄ™",
]
results = await thermo.generate_batch(problems)
for result in results:
print(f"Problem: {result.problem.problem_type}")
print(f"Energy: {result.energy:.2f}")
print(f"Solution: {result.decoded_output}\n")
from nlp2cmd.thermodynamic import LangevinConfig
config = LangevinConfig(
mu=1.0, # Mobility coefficient
kT=0.5, # Thermal energy
dt=0.01, # Time step
n_steps=1000, # Integration steps
dim=64, # Latent dimension
record_trajectory=True,
)
thermo = create_thermodynamic_generator(
langevin_config=config,
n_samples=10,
voting_strategy="energy",
)
The thermodynamic generator integrates seamlessly with existing DSL adapters:
# Standard DSL generation
from nlp2cmd.generation import create_hybrid_generator
hybrid = create_hybrid_generator()
# Mixed workload
queries = [
"SELECT * FROM users", # → SQL (rules)
"docker ps -a", # → Docker (rules)
"Zaplanuj zadania z terminami", # → Scheduling (thermo)
"kubectl get pods", # → K8s (rules)
]
for query in queries:
result = await hybrid.generate(query)
print(f"{query} → {result['source']}")
Run the full test suite:
PYTHONPATH=/home/tom/github/wronai/nlp2cmd/src python3 -m pytest \
tests/iterative/test_iter_10_thermodynamic.py -v
Whitelam, S. (2025) “Generative thermodynamic computing” Physical Review E 111, 044114. arXiv:2506.15121 - Foundational paper introducing the thermodynamic computing framework with Langevin dynamics for generative modeling.
Whitelam, S. & Casert, C. (2024) “Thermodynamic neural networks” - Previous work on nonlinear thermodynamic hardware implementations.
Zhang, M., Jiang, N., Li, L., & Xue, Y. (2021) “COLD Decoding: Energy-based Constrained Text Generation with Langevin Dynamics” ICML - Application of Langevin dynamics to constrained text generation.
Welling, M. & Teh, Y. W. (2011) “Bayesian learning via stochastic gradient Langevin dynamics” ICML 2011 - Foundational work on SGLD for sampling.
Aifer, C. et al. (2024) “Thermodynamic hardware for linear algebra operations” - Hardware implementations for thermodynamic computing.
The thermodynamic module implements the core concepts from Whitelam (2025) with practical adaptations for NLP-to-command generation: