File size: 1,362 Bytes
4e35872 | 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 | """
Minimal example: Physics-Informed Bayesian Optimization in ~30 lines.
Demonstrates the core workflow:
1. Define a physics model
2. Define the parameter space
3. Create a designer and suggest experiments
"""
import torch
from physics_informed_bo.experiment.parameter_space import ParameterSpace
from physics_informed_bo.experiment.designer import ExperimentDesigner
# Physics model: simple Arrhenius-like kinetics
def physics_model(X):
temp, conc = X[:, 0], X[:, 1]
return torch.exp(-5000 / temp) * conc**0.5
# Parameter space
space = ParameterSpace()
space.add_continuous("temperature", 300, 600, units="K")
space.add_continuous("concentration", 0.1, 10.0, units="mol/L")
# Some initial observations
X_init = torch.tensor([[350.0, 1.0], [450.0, 5.0], [500.0, 3.0]])
y_init = torch.tensor([0.1, 0.8, 0.6])
# Create designer with physics + data
designer = ExperimentDesigner(
parameter_space=space,
physics_fn=physics_model,
initial_data=(X_init, y_init),
)
# Suggest next experiments
next_experiments = designer.suggest(n=3)
print("Suggested experiments:")
for exp in space.to_dict(next_experiments):
print(f" Temperature={exp['temperature']:.1f} K, Concentration={exp['concentration']:.2f} mol/L")
# After running experiments, update the designer
# designer.update(X_new, y_new)
|