ravimohan19 commited on
Commit
4e35872
·
verified ·
1 Parent(s): afd4256

Upload examples/minimal_example.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. examples/minimal_example.py +44 -0
examples/minimal_example.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Minimal example: Physics-Informed Bayesian Optimization in ~30 lines.
3
+
4
+ Demonstrates the core workflow:
5
+ 1. Define a physics model
6
+ 2. Define the parameter space
7
+ 3. Create a designer and suggest experiments
8
+ """
9
+
10
+ import torch
11
+ from physics_informed_bo.experiment.parameter_space import ParameterSpace
12
+ from physics_informed_bo.experiment.designer import ExperimentDesigner
13
+
14
+
15
+ # Physics model: simple Arrhenius-like kinetics
16
+ def physics_model(X):
17
+ temp, conc = X[:, 0], X[:, 1]
18
+ return torch.exp(-5000 / temp) * conc**0.5
19
+
20
+
21
+ # Parameter space
22
+ space = ParameterSpace()
23
+ space.add_continuous("temperature", 300, 600, units="K")
24
+ space.add_continuous("concentration", 0.1, 10.0, units="mol/L")
25
+
26
+ # Some initial observations
27
+ X_init = torch.tensor([[350.0, 1.0], [450.0, 5.0], [500.0, 3.0]])
28
+ y_init = torch.tensor([0.1, 0.8, 0.6])
29
+
30
+ # Create designer with physics + data
31
+ designer = ExperimentDesigner(
32
+ parameter_space=space,
33
+ physics_fn=physics_model,
34
+ initial_data=(X_init, y_init),
35
+ )
36
+
37
+ # Suggest next experiments
38
+ next_experiments = designer.suggest(n=3)
39
+ print("Suggested experiments:")
40
+ for exp in space.to_dict(next_experiments):
41
+ print(f" Temperature={exp['temperature']:.1f} K, Concentration={exp['concentration']:.2f} mol/L")
42
+
43
+ # After running experiments, update the designer
44
+ # designer.update(X_new, y_new)