Skip to content
VLASIFY™
GuideScientific AI & machine learning

Scientific machine learning in Python: tools, workflow and good practice

Updated · Scientifically reviewed by Dinkar Mishra, PhD on

Short answer

Scientific machine learning (SciML) combines machine learning with physical models: surrogates trained on simulations, physics-informed networks, neural operators, equation discovery and hybrid physics-ML models. In Python, PyTorch and JAX provide differentiable array computing; DeepXDE and neuraloperator offer PINNs and operator learning; PySINDy discovers equations from data; scikit-learn covers classical surrogates such as Gaussian processes. Success depends less on the tool than on data quality, physics constraints and rigorous validation.

Who this is for

Physicists, engineers and data scientists choosing Python tools for combining machine learning with physical models and simulation data.

Software

Python ≥ 3.10

How it works

SciML methods sit on a spectrum between pure physics and pure data:

ApproachPhysics usedData neededTypical use
Classical simulationFull modelNone (inputs only)Ground truth, training data
Physics-informed neural networksPDE in the lossLittle to moderateInverse problems, sparse data
Neural operatorsImplicitly, via simulation dataModerate to largeFast surrogates over input families
Hybrid models (learned closures)Most of the model, with an ML componentModerateUnknown terms in otherwise known equations
Equation discovery (SINDy)Candidate term libraryClean time seriesInterpretable models from data
Black-box surrogates (GP, NN)NoneModerateDesign optimisation, uncertainty quantification

The Python toolbox

NeedTools
Differentiable arrays and neural networksPyTorch, JAX (with Flax or Equinox)
PINNsDeepXDE, or custom PyTorch/JAX code
Neural operatorsneuraloperator (FNO and variants), DeepXDE (DeepONet)
Equation discoveryPySINDy
Classical surrogates and UQscikit-learn (Gaussian processes), SALib (sensitivity analysis), scipy.stats.qmc (sampling designs)
Differentiable ODE solverstorchdiffeq, Diffrax (JAX)
Data handlingNumPy, xarray, h5py, Zarr

A reproducible SciML workflow

  1. Frame the question. Inputs, outputs, accuracy target and the input range of interest.
  2. Generate or curate data with a verified solver or calibrated instruments. Record versions and parameters.
  3. Start simple. A Gaussian process or small MLP baseline tells you how hard the problem is.
  4. Add physics where it helps: conservation laws, symmetries, PDE residuals or known model structure.
  5. Validate on held-out data and beyond: worst-case errors, physical consistency and out-of-distribution probes.
  6. Package it: pinned environment, seeds, data versioning, and a model card stating the valid range.
# A strong, simple baseline: Gaussian-process surrogate with uncertainty
import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, ConstantKernel

rng = np.random.default_rng(0)
X = rng.uniform(0, 1, size=(40, 2))                          # e.g. two normalised design parameters
y = np.sin(6 * X[:, 0]) * np.exp(-X[:, 1])                   # stand-in for simulation outputs
gp = GaussianProcessRegressor(ConstantKernel() * RBF([0.2, 0.2]), normalize_y=True).fit(X, y)
mean, std = gp.predict(np.array([[0.5, 0.5]]), return_std=True)
print(f"prediction {mean[0]:.3f} ± {2 * std[0]:.3f} (2σ)")

Where SciML goes wrong

  • Training and test sets drawn from the same few simulations: an over-optimistic accuracy.
  • No uncertainty estimate, so users cannot tell when the model is guessing.
  • Averaged metrics hiding catastrophic failures on rare inputs.
  • Errors in the underlying simulation data, inherited silently. Verify the data source first; see simulation verification.

Assumptions and limitations

  • The tool list reflects widely used open-source packages at the time of writing. The ecosystem changes quickly, so check project activity before adopting one.
  • The code example uses a synthetic function as a stand-in for simulation outputs. It illustrates the workflow, not a physics result.
  • Choosing between approaches depends on data availability and accuracy needs. Our AI surrogates service helps scope this.

Frequently asked questions

Should I learn PyTorch or JAX for SciML?+

Both are excellent. PyTorch has the largest ecosystem and community; JAX's function transformations (jit, grad, vmap) suit scientific computing and differentiable simulators particularly well. Choose based on the libraries you need and your team's experience.

Is Julia better for SciML?+

Julia's SciML ecosystem (DifferentialEquations.jl and related packages) is strong, especially for differentiable ODE/PDE solvers. Python has a wider general ML ecosystem and more users. Many groups use Python unless they need Julia-specific solvers.

What is equation discovery?+

Methods such as SINDy (sparse identification of nonlinear dynamics) fit a sparse combination of candidate terms to time-series data, producing interpretable governing equations. They work best with clean, well-sampled data and a good library of candidate terms.

How do I make SciML results reproducible?+

Fix random seeds, record library versions (a lock file or container), version your datasets, report results over several seeds, and keep the data-generation code with the training code.

References

  1. Karniadakis et al., Physics-informed machine learning, Nat. Rev. Phys. 3, 422 (2021) · Review article
  2. Brunton, Proctor & Kutz, Discovering governing equations from data by sparse identification of nonlinear dynamical systems, PNAS 113, 3932 (2016) · Peer-reviewed article
  3. DeepXDE documentation · DeepXDE project
  4. PySINDy documentation · PySINDy project
  5. scikit-learn: Gaussian processes · scikit-learn

Need help applying this?

Our physicists turn concepts into working, verified simulations for research groups and companies.

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