Abstract
Imaging, scattering, and spectroscopy are fundamental in understanding and discovering new functional materials. Contemporary innovations in automation and experimental techniques have led to these measurements being performed much faster and with higher resolution, thus producing vast amounts of data for analysis. These innovations are particularly pronounced at user facilities and synchrotron light sources. Machine learning (ML) methods are regularly developed to process and interpret large datasets in real-time with measurements. However, there remain conceptual barriers to entry for the facility general user community, whom often lack expertise in ML, and technical barriers for deploying ML models. Herein, we demonstrate a variety of archetypal ML models for on-the-fly analysis at multiple beamlines at the National Synchrotron Light Source II (NSLS-II). We describe these examples instructively, with a focus on integrating the models into existing experimental workflows, such that the reader can easily include their own ML techniques into experiments at NSLS-II or facilities with a common infrastructure. The framework presented here shows how with little effort, diverse ML models operate in conjunction with feedback loops via integration into the existing Bluesky Suite for experimental orchestration and data management.
Introduction
Modern synchrotron facilities like the National Synchrotron Light Source II (NSLS-II) are generating data at an unprecedented rate—reaching approximately 42 petabytes in 2021 alone. This "data deluge" presents two major bottlenecks: an expertise gap, where materials scientists often lack the specialized skills to deploy complex ML models, and an integration gap, where post-hoc analysis is too slow to influence live experiments. To address these, we present a framework for real-time ML integration into experimental workflows, allowing researchers to catch fleeting transitions and avoid wasting beam time on low-quality data.
Experimental Framework
The core of our approach is a standardized "tell-report-ask" interface integrated into the Bluesky Suite, the standard tool for experimental orchestration at NSLS-II. This abstraction allows diverse ML models to be seamlessly plugged into the orchestration layer. The workflow follows a structured path from task specification and model identification to real-time deployment.
In this framework, the "tell" method feeds new data to the model, "report" generates visualizations or predictions, and "ask" queries the model for the next experimental action (e.g., "Should I continue this scan?"). This setup enables remote monitoring and rapid decision-making, even allowing researchers to receive real-time updates via communication tools like Slack.
Applications and Results
We demonstrated the framework using three ML archetypes across different beamlines:
Unsupervised Learning: Spectral Decomposition
Using Non-negative Matrix Factorization (NMF) at the Total Scattering (PDF) beamline, we decomposed complex scattering data from molten salts into chemically meaningful end-members.
This allowed researchers to identify four distinct phases on-the-fly, providing immediate insight into coordination changes that would normally require weeks of post-experiment analysis to uncover.
Anomaly Detection and Quality Control
At the CSX beamline, we evaluated Local Outlier Detection (LOD), Elliptical Envelope (EE), and Isolation Forest (IFT) for flagging experimental failures like beam drift. The EE model was particularly robust, achieving a recall of 0.98 for anomalies with a false discovery rate of only 0.036. For X-ray absorption (XAFS) data at the BMM beamline, supervised classifiers like Random Forests and Multi-layer Perceptrons (MLP) achieved near-perfect accuracy in categorizing data quality, especially when leveraging expert-engineered features.
Discussion and Key Insights
A critical finding was the importance of feature engineering for small datasets (<10,000 points). Models using engineered features (like mean intensity or autocorrelation) significantly outperformed those trained on raw data, highlighting that expert domain knowledge remains a powerful tool in ML performance. Furthermore, the integration with Bluesky allows for efficient remote operation, where researchers can monitor experiment health via simple emoji-based reports.
Conclusion and Future Work
While deep learning models like Convolutional Neural Networks (CNNs) offer high accuracy without manual feature engineering, they currently face higher barriers regarding data requirements and accessibility. Future efforts will focus on moving from "human-in-the-loop" to fully "closed-loop" autonomous science, where the ML model directly controls hardware to optimize experimental outcomes. As detector speeds continue to increase, robust distributed computing will be essential to maintain real-time processing capabilities.
Summary updated