Skip to content
VLASIFY™
TutorialScientific AI & machine learning

How to train surrogate models for simulations: from design of experiments to validation

Updated · Scientifically reviewed by Dinkar Mishra, PhD on

Short answer

Define the inputs, their ranges and the outputs you need; sample the input space with a space-filling design such as a Latin hypercube; run the simulation at those points; fit a surrogate (Gaussian process for tens to hundreds of samples, neural networks for larger datasets); validate on held-out runs using error metrics and coverage of the predicted uncertainty; then add simulations where the surrogate is most uncertain (active learning) until it meets your accuracy target.

Who this is for

Engineers and scientists who want fast approximations of expensive simulations for design scans, optimisation or uncertainty quantification.

Software

Python ≥ 3.9scikit-learn / SciPy ≥ 1.3 / ≥ 1.7

Prerequisites

  • A verified simulation you can run in batch, with inputs and outputs that can be scripted. Slurm job arrays make this easy; see how to submit a Slurm job.
  • Python with NumPy, SciPy and scikit-learn.

Step 1: define inputs, ranges and outputs

List each input with physically meaningful bounds, for example laser a0∈[1.5,4]a_0 \in [1.5, 4] and plasma density ne∈[1018,5×1018]n_e \in [10^{18}, 5\times10^{18}] cm⁻³. Use log scales for inputs spanning orders of magnitude. Choose scalar outputs (peak energy, efficiency) or field outputs. Field outputs suit neural operators; see the neural operator tutorial.

Step 2: design the experiments

import numpy as np
from scipy.stats import qmc

bounds_low = np.array([1.5, np.log10(1e18)])
bounds_high = np.array([4.0, np.log10(5e18)])
sampler = qmc.LatinHypercube(d=2, seed=0)
design = qmc.scale(sampler.random(n=20), bounds_low, bounds_high)
for a0, log_ne in design:
    print(f"a0={a0:.2f}  ne={10**log_ne:.2e} cm^-3")      # write these into your input decks

A Latin hypercube spreads points evenly in every input. Run the simulation at each design point and collect the outputs.

Step 3: fit the surrogate

import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import ConstantKernel, Matern, WhiteKernel
from sklearn.model_selection import train_test_split

# X: (n_runs, n_inputs) normalised to [0, 1]; y: simulation outputs
rng = np.random.default_rng(1)
X = rng.uniform(0, 1, size=(30, 2))
y = np.tanh(3 * X[:, 0] - 1) + 0.3 * X[:, 1] ** 2                 # stand-in for simulation results

X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.25, random_state=0)
kernel = ConstantKernel() * Matern(length_scale=[0.3, 0.3], nu=2.5) + WhiteKernel(1e-6)
gp = GaussianProcessRegressor(kernel, normalize_y=True, n_restarts_optimizer=5).fit(X_tr, y_tr)

mean, std = gp.predict(X_te, return_std=True)
rmse = np.sqrt(np.mean((mean - y_te) ** 2))
coverage = np.mean(np.abs(mean - y_te) <= 2 * std)
print(f"test RMSE = {rmse:.3e}, 2-sigma coverage = {100 * coverage:.0f}%")

Step 4: validate

  • Hold-out or cross-validation error relative to the output range and to your accuracy target.
  • Uncertainty calibration: about 95% of test points should fall within ±2σ. Much lower coverage means the surrogate is overconfident.
  • Worst-case error and where it occurs in input space.
  • Physical checks: monotonic trends, known limits and bounds.

Step 5: improve actively

Add runs where the surrogate is most uncertain (maximum predicted σ), or where it matters most for your goal, for example near the predicted optimum (Bayesian optimisation). Refit and revalidate after each batch, and stop when validation meets the target.

Verify

A surrogate is ready when its validation error on runs it has never seen is below the accuracy you need, its uncertainty is calibrated, and you have documented the input ranges within which it is valid. Keep the validation set fixed so that improvements are measured honestly.

Troubleshooting

  • The GP fits noise or produces wild oscillations: add a WhiteKernel term, check for duplicate inputs, and normalise inputs to [0, 1].
  • Poor accuracy everywhere: the response is more complex than the sample size supports. Add samples, reduce the input ranges, or transform the output (for example a log transform).
  • Good in the middle, bad at the edges: space-filling designs sample boundaries sparsely. Add points near the edges of the range.

Assumptions and limitations

  • The code uses a synthetic stand-in function in place of real simulation results, to keep the example self-contained.
  • Rules of thumb for sample sizes are starting points, not guarantees.
  • Surrogates are valid only within the sampled ranges and for the same simulation setup. Document both. Our AI surrogates service builds and validates surrogates for plasma and engineering simulations.

Frequently asked questions

How many simulations do I need?+

A common rule of thumb for a first Gaussian-process design is about 10 runs per input dimension, then more where validation shows large errors. Highly non-linear responses or many inputs need more; neural networks generally need far more data than GPs.

Should I use a Gaussian process or a neural network?+

Gaussian processes are data-efficient and provide uncertainty estimates, ideal for up to a few thousand samples and modest input dimension. Neural networks scale to large datasets, high-dimensional inputs and field outputs (with neural operators), but need more data and separate uncertainty methods.

What if some simulations fail?+

Record the failures; they are information. A failure region may be physical (no solution) or numerical. A classifier for the feasible region alongside the surrogate is a common approach.

Can surrogates replace verification of the simulation?+

No. A surrogate reproduces the simulation, including its errors. The simulation must be verified and, where relevant, validated before its outputs are worth emulating.

References

  1. Forrester, Sóbester & Keane, Engineering Design via Surrogate Modelling (Wiley, 2008) · Standard textbook
  2. Rasmussen & Williams, Gaussian Processes for Machine Learning (MIT Press, 2006) · Standard textbook (free online)
  3. SciPy: quasi-Monte Carlo sampling (scipy.stats.qmc) · SciPy
  4. Loeppky, Sacks & Welch, Choosing the sample size of a computer experiment: a practical guide, Technometrics 51, 366 (2009) · Peer-reviewed article

Want this set up and verified for you?

We install, configure and validate scientific software on your workstation, cluster or cloud, and train your team to run it.

Services listed on this page are available today. Products marked “early access” or “in development” on our platform page are not yet generally available.

Spotted an error or an outdated command? Tell us. We correct verified issues promptly.

Related guides

How Vlasify can help

Get a Quote