Production scientific code needs reproducible seeds, input validation, solver success checks, unit tests on known analytic cases, and pinned library versions—especially before ML deployment on the AI track.
Before shipping numerical code
- Assert array shapes, dtypes, and finite values (no NaN/inf)
- Check
result.successon optimizers; inspect residuals - Pin NumPy/SciPy versions in requirements.txt
- Unit test against closed-form solutions where possible
- Log test statistics, parameters, and solver messages
- Document statistical assumptions for compliance reviews
Testing example
import numpy as np
from scipy import integrate
val, _ = integrate.quad(lambda x: x ** 2, 0, 1)
assert np.isclose(val, 1/3), val
print('quad test OK')
Performance
Profile hot paths—sparse vs dense, FFT size powers of two, avoid Python loops on millions of elements. Scale out with batch jobs or C++/Julia only when profiling proves need.
Important interview questions and answers
- Q: Why pin SciPy?
A: Patch releases can change numerical outputs—reproducibility and regression tests depend on versions. - Q: optimize success false?
A: Treat as failure—do not deploy parameters from unsuccessful fits.
Self-check
- List five production SciPy checklist items.
- Why assert isclose on integrate.quad in tests?
- What do you check when minimize returns success=False?
Tip: Pin numpy and scipy versions in CI—numerical outputs can shift on upgrades.
Interview prep
- Pin versions?
Reproducible numerics across CI and deployment.
- Test analytically?
quad, solve, eig on toy cases with known answers.
- optimize failure?
Do not ship parameters when success is False.