Download examples/minimal_example.py from ravimohan19/physics-informed-bayesian-optimization: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/ravimohan19/physics-informed-bayesian-optimization/resolve/main/examples/minimal_example.py
- Command line
-
hf download hf://spaces/ravimohan19/physics-informed-bayesian-optimization/examples/minimal_example.py
-
curl -L -o minimal_example.py https://huggingface.co/spaces/ravimohan19/physics-informed-bayesian-optimization/resolve/main/examples/minimal_example.py
1.36 kB
| """ | |
| 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) | |