Build Packages / Create release (push) Successful in 7s
Build Packages / build:portable:macos-arm64:nocuda (push) Successful in 4m56s
Build Packages / build:rugnux:linux-aarch64:cuda (push) Successful in 9m10s
Build Packages / build:portable:linux-x86_64:nocuda (push) Successful in 13m51s
Build Packages / build:portable:linux-x86_64:cuda (push) Successful in 16m56s
Build Packages / build:jfjoch:rocky8:nocuda (push) Successful in 20m59s
Build Packages / build:portable:windows-x86_64:nocuda (push) Successful in 21m25s
Build Packages / build:jfjoch:rocky9:nocuda (push) Successful in 21m17s
Build Packages / build:jfjoch:ubuntu2204:nocuda (push) Successful in 14m14s
Build Packages / HDF5 consumer tests (DIALS, XDS) (push) Successful in 25m59s
Build Packages / build:portable:windows-x86_64:cuda (push) Successful in 25m48s
Build Packages / build:jfjoch:ubuntu2404:nocuda (push) Successful in 15m52s
Build Packages / build:jfjoch:rocky8:cuda-sls9 (push) Successful in 19m33s
Build Packages / Generate python client (push) Successful in 29s
Build Packages / Build documentation (push) Successful in 1m19s
Build Packages / build:jfjoch:ubuntu2204:cuda (push) Successful in 20m49s
Build Packages / build:jfjoch:rocky9:cuda-sls9 (push) Successful in 25m31s
Build Packages / build:jfjoch:rocky8:cuda (push) Successful in 25m24s
Build Packages / build:jfjoch:rocky9:cuda (push) Successful in 26m5s
Build Packages / build:jfjoch:ubuntu2404:cuda (push) Successful in 22m19s
Build Packages / Unit tests (push) Failing after 2h28m24s
Build Packages / Validation Battery (push) Successful in 40m33s
* Rugnux: Processes a collection live while jfjoch_broker writes it (`rugnux <master.h5> <broker URL>`). * Rugnux: Processing starts on the first images and confirms its choices once all are in, so analysis can begin during collection. * Rugnux: Faster processing, especially on servers with several GPUs and CPU sockets and on computers without a GPU (`--no-gpu`, macOS). * Rugnux: Uses much less GPU memory, so large data sets stay on the GPU of smaller cards, and a data set too large for the card is processed on the CPU instead. * Rugnux: On macOS, Bragg integration runs on the Apple GPU. * Rugnux: Better handling of twinning and pseudo-symmetry, with the twin hypothesis written as `<prefix>_twin_<SG>.mtz`, and a wrong `--model` no longer confirms the data or decides the hand. * Rugnux: `--model` accepts predicted (AlphaFold) models and falls back to molecular replacement when the model is not placed as a rigid body (experimental `--mr` forces it), settling space group, hand and twinning and writing a different answer as `<prefix>_mr.mtz`. * Rugnux: Molecular replacement is faster and settles the space group in more cases with several copies in the asymmetric unit. * Rugnux: Deposition-ready mmCIF, a richer report, and numbered steps on the terminal with the full log in `<prefix>_log.txt`; `_P1.mtz`, `--estimate-beam-center` and `--beam-center-search` are removed. * Rugnux: The beam-stop shadow is found correctly on tilted detectors. * Rugnux: Stills files that record a stationary goniometer axis get the default stills geometry refinement. * jfjoch_viewer: "Analyze dataset" uses the same defaults as a bare `rugnux <file>`, and shows the results of processed CBF, marCCD and SMV sweeps. * jfjoch_viewer: The Files panel refreshes on F5 and every few seconds, and the plot type and other selections stay put during live collection. * jfjoch_writer: Memory stays bounded and old data files are closed efficiently on long runs, any failure ends the run in an error state the broker is told about, and the master file appears only after its data files; the ZeroMQ pusher logs when a stalled writer makes it drop images. * Fixes: The TCP image pusher no longer blocks the broker's receiver, GPU out-of-memory failures stop with a clear message, and the XDS plugin masks module and chip edges. --------- Co-authored-by: Filip Leonarski <jungfrau@filips-mac-mini.home> Reviewed-on: #85 Co-authored-by: Filip Leonarski <filip.leonarski@psi.ch>
183 lines
7.8 KiB
C++
183 lines
7.8 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochProcessController.h"
|
|
#include "../reader/JFJochCBFReader.h"
|
|
#include "../reader/JFJochMarCCDReader.h"
|
|
#include "../reader/JFJochSMVReader.h"
|
|
#include "../reader/JFJochHDF5Reader.h"
|
|
#include "../rugnux/ResultReport.h"
|
|
|
|
#include <QElapsedTimer>
|
|
#include <QMetaType>
|
|
|
|
#include <cmath>
|
|
|
|
JFJochProcessController::JFJochProcessController(QObject *parent) : QObject(parent) {
|
|
qRegisterMetaType<ProcessResult>("ProcessResult");
|
|
qRegisterMetaType<std::shared_ptr<const JFJochReaderDataset>>("std::shared_ptr<const JFJochReaderDataset>");
|
|
qRegisterMetaType<std::vector<ReportCheck>>("std::vector<ReportCheck>");
|
|
}
|
|
|
|
JFJochProcessController::~JFJochProcessController() {
|
|
cancel();
|
|
joinWorker_();
|
|
}
|
|
|
|
void JFJochProcessController::joinWorker_() {
|
|
if (worker_.joinable())
|
|
worker_.join();
|
|
}
|
|
|
|
void JFJochProcessController::start(const QString &file_path, DiffractionExperiment experiment,
|
|
PixelMask pixel_mask, ProcessConfig config) {
|
|
if (running_.exchange(true))
|
|
return; // a job is already running
|
|
|
|
cancel_pending_ = false;
|
|
joinWorker_(); // reap the previous (finished) worker, if any
|
|
worker_ = std::thread(&JFJochProcessController::run_, this,
|
|
file_path, std::move(experiment), std::move(pixel_mask), std::move(config));
|
|
emit started();
|
|
}
|
|
|
|
void JFJochProcessController::cancel() {
|
|
cancel_pending_ = true;
|
|
if (auto *p = active_.load())
|
|
p->Cancel();
|
|
}
|
|
|
|
void JFJochProcessController::run_(QString file_path, DiffractionExperiment experiment,
|
|
PixelMask pixel_mask, ProcessConfig config) {
|
|
try {
|
|
JFJochHDF5Reader hdf5_reader;
|
|
JFJochCBFReader cbf_reader;
|
|
JFJochMarCCDReader marccd_reader;
|
|
JFJochSMVReader smv_reader;
|
|
JFJochReader *reader_ptr;
|
|
const std::string path = file_path.toStdString();
|
|
if (JFJochCBFReader::CanRead(path)) {
|
|
cbf_reader.ReadFiles(path);
|
|
reader_ptr = &cbf_reader;
|
|
} else if (JFJochMarCCDReader::CanRead(path)) {
|
|
marccd_reader.ReadFiles(path);
|
|
reader_ptr = &marccd_reader;
|
|
config.counts_in_adu = true; // a CCD: pixel values are ADU, as for rugnux
|
|
} else if (JFJochSMVReader::CanRead(path)) {
|
|
smv_reader.ReadFiles(path);
|
|
reader_ptr = &smv_reader;
|
|
config.counts_in_adu = true;
|
|
} else {
|
|
hdf5_reader.ReadFile(path);
|
|
reader_ptr = &hdf5_reader;
|
|
}
|
|
JFJochReader &reader = *reader_ptr;
|
|
|
|
// Seed the live dataset with the experiment so the chart has geometry context; per-image
|
|
// results are filled in by OnImageProcessed as the run progresses.
|
|
{
|
|
auto base = std::make_shared<JFJochReaderDataset>();
|
|
base->experiment = experiment;
|
|
std::lock_guard lock(live_mutex_);
|
|
live_dataset_ = std::move(base);
|
|
last_live_emit_ = {};
|
|
}
|
|
|
|
// The report is rendered from the run's own results after Run(); keep what it needs
|
|
// before Rugnux consumes the experiment and the config.
|
|
const DiffractionExperiment report_experiment = experiment;
|
|
const std::string output_prefix = config.output_prefix;
|
|
QElapsedTimer run_timer;
|
|
run_timer.start();
|
|
|
|
Rugnux process(reader, std::move(experiment), std::move(pixel_mask), std::move(config));
|
|
active_ = &process;
|
|
if (cancel_pending_)
|
|
process.Cancel();
|
|
|
|
ProcessResult result = process.Run(this);
|
|
|
|
// The same text the CLI writes as <prefix>_report.txt, shown in the analysis window. As
|
|
// with WriteResultReport, a run that produced results must not be lost to a report
|
|
// failure, so a throw here leaves the report empty rather than failing the job.
|
|
QString report;
|
|
std::vector<ReportCheck> checks;
|
|
if (!result.cancelled) {
|
|
try {
|
|
RunProvenance provenance;
|
|
provenance.wall_time_s = run_timer.elapsed() / 1000.0;
|
|
ReportDocument doc = BuildReportDocument(output_prefix, file_path.toStdString(),
|
|
report_experiment, result, provenance);
|
|
report = QString::fromStdString(RenderReportText(doc, provenance.developer));
|
|
checks = std::move(doc.checks);
|
|
} catch (...) {
|
|
}
|
|
}
|
|
|
|
active_ = nullptr;
|
|
running_ = false;
|
|
emit finished(result, report, checks);
|
|
} catch (const std::exception &e) {
|
|
active_ = nullptr;
|
|
running_ = false;
|
|
emit failed(QString::fromStdString(e.what()));
|
|
}
|
|
}
|
|
|
|
void JFJochProcessController::OnPhase(const std::string &phase) {
|
|
emit phaseChanged(QString::fromStdString(phase));
|
|
}
|
|
|
|
void JFJochProcessController::OnProgress(uint64_t done, uint64_t total) {
|
|
// Throttle to ~200 updates so a long run does not flood the GUI event queue.
|
|
const uint64_t step = total > 200 ? total / 200 : 1;
|
|
if (done == total || done % step == 0)
|
|
emit progress(done, total);
|
|
}
|
|
|
|
void JFJochProcessController::OnImageProcessed(const DataMessage &msg) {
|
|
std::shared_ptr<JFJochReaderDataset> snapshot;
|
|
{
|
|
std::lock_guard lock(live_mutex_);
|
|
if (!live_dataset_)
|
|
return;
|
|
|
|
// Place each available per-image result at its ordinal; gaps (images still being processed
|
|
// by other threads) read back as NaN.
|
|
const int64_t i = msg.number;
|
|
auto put = [i](std::vector<float> &v, float val) {
|
|
if (static_cast<int64_t>(v.size()) <= i)
|
|
v.resize(i + 1, NAN);
|
|
v[i] = val;
|
|
};
|
|
auto &d = *live_dataset_;
|
|
// Map this ordinal back to its original image number (for the x-axis of subset/strided runs).
|
|
if (static_cast<int64_t>(d.source_image_number.size()) <= i)
|
|
d.source_image_number.resize(i + 1, 0);
|
|
d.source_image_number[i] = static_cast<int>(msg.original_number.value_or(msg.number));
|
|
if (msg.spot_count) put(d.spot_count, *msg.spot_count);
|
|
if (msg.spot_count_indexed) put(d.spot_count_indexed, *msg.spot_count_indexed);
|
|
if (msg.spot_count_low_res) put(d.spot_count_low_res, *msg.spot_count_low_res);
|
|
if (msg.spot_count_ice_rings) put(d.spot_count_ice_rings, *msg.spot_count_ice_rings);
|
|
if (msg.indexing_result) put(d.indexing_result, *msg.indexing_result ? 1.0f : 0.0f);
|
|
if (msg.indexing_lattice_count) put(d.indexing_lattice_count, *msg.indexing_lattice_count);
|
|
if (msg.bkg_estimate) put(d.bkg_estimate, *msg.bkg_estimate);
|
|
if (msg.spindle_blind_fraction) put(d.spindle_blind_fraction, *msg.spindle_blind_fraction);
|
|
if (msg.resolution_estimate) put(d.resolution_estimate, *msg.resolution_estimate);
|
|
if (msg.profile_radius) put(d.profile_radius, *msg.profile_radius);
|
|
if (msg.mosaicity_deg) put(d.mosaicity_deg, *msg.mosaicity_deg);
|
|
if (msg.b_factor) put(d.b_factor, *msg.b_factor);
|
|
if (msg.integrated_reflections) put(d.integrated_reflections, *msg.integrated_reflections);
|
|
if (msg.image_scale_factor) put(d.image_scale_factor, *msg.image_scale_factor);
|
|
if (msg.image_scale_cc) put(d.image_scale_cc, *msg.image_scale_cc);
|
|
|
|
// Throttle to ~4 Hz so the GUI plots refresh smoothly without flooding the event queue.
|
|
const auto now = std::chrono::steady_clock::now();
|
|
if (now - last_live_emit_ < std::chrono::milliseconds(250))
|
|
return;
|
|
last_live_emit_ = now;
|
|
snapshot = std::make_shared<JFJochReaderDataset>(d); // immutable copy for the GUI thread
|
|
}
|
|
emit liveDataset(snapshot);
|
|
}
|