rugnux: merge the quality guard's pre-pass frames beside the post-refinement
The guard's merge of the first prepass_images frames read nothing the post-refinement writes and the post-refinement reads nothing the guard writes, but the two ran one after the other at the start of the tail. The guard now merges the first frames of the outcomes in place (RotationScaleMerge::SetFrameLimit) with the per-frame scale not written back, instead of moving the reflections into a copy whose write-back was thrown away, and it runs on its own thread from just before the post-refinement; its log lines are held and replayed where the guard's result is read. Same observations in the same order, same settings: p.mtz is byte-identical (myob, thau, cytc, kdp, cytc -N 4 / -N 8, --prepass-fraction 1 on four sets, 8a1a). On 8a1a the 3.7 s guard is now inside the post-refinement, which itself goes from 4.5 to 6.0 s under the shared load: about 2 s off the tail. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SVmAWnzCmRKAXVUCdc4iNi
This commit is contained in:
1 parent
f97700e084
commit
de9b2a7cd6
3 files changed
+36
-31
No files matched your search
@@ -374,6 +374,7 @@ void RotationScaleMerge::Ingest() {
|
||||
TimingMark mark(*logger, "rsm ingest");
|
||||
scale_partials_choice.reset();
|
||||
n_frames = static_cast<int>(partials_out.size());
|
||||
if (frame_limit >= 0) n_frames = std::min(n_frames, frame_limit);
|
||||
partials_released = false;
|
||||
resident_ingest = false;
|
||||
#ifdef JFJOCH_USE_CUDA
|
||||
@@ -385,7 +386,7 @@ void RotationScaleMerge::Ingest() {
|
||||
#endif
|
||||
|
||||
size_t total = 0;
|
||||
for (const auto &o : partials_out) total += o.reflections.size();
|
||||
for (int o = 0; o < n_frames; ++o) total += partials_out[o].reflections.size();
|
||||
|
||||
frame_cell_ok.assign(n_frames, 1);
|
||||
g_partial.assign(n_frames, 1.0);
|
||||
|
||||
@@ -143,6 +143,9 @@ public:
|
||||
// unmerged MTZ describe the merge that was written.
|
||||
void SetWriteBackPerFrameScale(bool on) { write_back_per_frame_scale = on; }
|
||||
|
||||
// Merge only the first n frames of the outcomes (by default all of them). Set before Ingest().
|
||||
void SetFrameLimit(int n) { frame_limit = n; }
|
||||
|
||||
// Whether Run() also hands back the merge's fulls unmerged (Result::scaled_fulls). Off by default:
|
||||
// it is a copy as long as the fulls, wanted only by a caller that writes them.
|
||||
void SetExportScaledFulls(bool on) { export_scaled_fulls = on; }
|
||||
@@ -476,6 +479,7 @@ private:
|
||||
bool gpu_active_ = false;
|
||||
#endif
|
||||
bool write_back_per_frame_scale = true; // see SetWriteBackPerFrameScale
|
||||
int frame_limit = -1; // see SetFrameLimit
|
||||
bool export_scaled_fulls = false; // see SetExportScaledFulls
|
||||
bool french_wilson = true; // see SetFrenchWilson
|
||||
|
||||
|
||||
+30
-30
@@ -697,6 +697,33 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
// before the engine is built rather than beside it - the gathered observations and their
|
||||
// rocking events are gigabytes on a long axis, and beside the engine's own arrays they set
|
||||
// the pass's memory high-water mark.
|
||||
// The quality guard judges a refined pass against the pre-pass on the search merge, and a
|
||||
// pre-pass that integrated only the first part of the sweep merged only that part. Against
|
||||
// it a merge of the whole sweep holds more reflections, more signal and more of the axial
|
||||
// rows for no reason but the frames, and the guard could never find it worse. So the guard
|
||||
// reads this pass's own integration of the same frames, merged the way the pre-pass merged
|
||||
// them. It only reads the outcomes (the per-frame scale is not written back), and so does the
|
||||
// post-refinement, so it runs beside it; its log lines are held and replayed where it is used.
|
||||
const bool merge_first_part = is_rotation && quality_guard_pass1_ && prepass_images < images_to_process
|
||||
&& !experiment_.GetRefineRotationWedgeInScaling() && !rot_ss.GetRotationWedgeForScaling().has_value();
|
||||
Logger guard_log = Logger::Buffered();
|
||||
const auto merge_guard = [&] {
|
||||
TimingMark mark(guard_log, "merge quality guard (pre-pass frames)");
|
||||
RotationScaleMerge first_part_rsm(experiment_, indexer->GetIntegrationOutcome(), result.consensus_cell,
|
||||
static_cast<int>(config_.scaling_iter), config_.nthreads,
|
||||
guard_log, "");
|
||||
first_part_rsm.SetFrameLimit(prepass_images);
|
||||
first_part_rsm.SetWriteBackPerFrameScale(false);
|
||||
first_part_rsm.Ingest();
|
||||
first_part_rsm.SetExportScaledFulls(false);
|
||||
first_part_rsm.SetFrenchWilson(false);
|
||||
auto r = first_part_rsm.Run(!experiment_.GetGemmiSpaceGroup().has_value(),
|
||||
/*full_stats=*/false, /*measure_cc_before_corrections=*/true);
|
||||
return ScaleMergeResult{std::move(r.merged), std::move(r.statistics), r.cc_half_before_corrections};
|
||||
};
|
||||
std::future<ScaleMergeResult> guard_ahead;
|
||||
if (merge_first_part && !(postrefine_probe_ && !geometry_prepass && postrefine_probe_only_))
|
||||
guard_ahead = std::async(std::launch::async, merge_guard);
|
||||
if (postrefine_probe_ && !geometry_prepass && is_rotation) {
|
||||
post_refine_geometry();
|
||||
if (speculate_geometry_probe_ && !cancelled_ && prepass_detector_geometry_ && result.post_refine
|
||||
@@ -738,38 +765,11 @@ bool Rugnux::ScaleMergeAndSymmetry(PipelineLocals &p) {
|
||||
throw JFJochException(JFJochExceptionCategory::InputParameterInvalid,
|
||||
"Rotation scaling/merging (RotationScaleMerge) does not support "
|
||||
"wedge refinement");
|
||||
// The quality guard judges a refined pass against the pre-pass on the search merge, and a
|
||||
// pre-pass that integrated only the first part of the sweep merged only that part. Against
|
||||
// it a merge of the whole sweep holds more reflections, more signal and more of the axial
|
||||
// rows for no reason but the frames, and the guard could never find it worse. So the guard
|
||||
// reads this pass's own integration of the same frames, merged the way the pre-pass merged
|
||||
// them. The merge writes its per-frame scale back, so it gets copies of the outcomes and
|
||||
// only borrows the reflections.
|
||||
if (quality_guard_pass1_ && prepass_images < images_to_process) {
|
||||
if (merge_first_part) {
|
||||
logger.Info("Two-pass: the quality guard reads this pass's merge of the first {} images, "
|
||||
"the ones the pre-pass integrated", prepass_images);
|
||||
auto &outcomes = indexer->GetIntegrationOutcome();
|
||||
std::vector<IntegrationOutcome> first_part(prepass_images);
|
||||
for (int i = 0; i < prepass_images; ++i) {
|
||||
ReflectionVector reflections = std::move(outcomes[i].reflections);
|
||||
first_part[i] = outcomes[i];
|
||||
first_part[i].reflections = std::move(reflections);
|
||||
}
|
||||
{
|
||||
TimingMark mark(logger, "merge quality guard (pre-pass frames)");
|
||||
RotationScaleMerge first_part_rsm(experiment_, first_part, result.consensus_cell,
|
||||
static_cast<int>(config_.scaling_iter), config_.nthreads,
|
||||
logger, "");
|
||||
first_part_rsm.Ingest();
|
||||
first_part_rsm.SetExportScaledFulls(false);
|
||||
first_part_rsm.SetFrenchWilson(false);
|
||||
auto r = first_part_rsm.Run(!experiment_.GetGemmiSpaceGroup().has_value(),
|
||||
/*full_stats=*/false, /*measure_cc_before_corrections=*/true);
|
||||
guard_merge = ScaleMergeResult{std::move(r.merged), std::move(r.statistics),
|
||||
r.cc_half_before_corrections};
|
||||
}
|
||||
for (int i = 0; i < prepass_images; ++i)
|
||||
outcomes[i].reflections = std::move(first_part[i].reflections);
|
||||
guard_merge = guard_ahead.valid() ? guard_ahead.get() : merge_guard();
|
||||
guard_log.ReplayInto(logger);
|
||||
}
|
||||
// A reference MTZ is allowed for rotation: it fixes the space group / cell (on the CLI) and
|
||||
// resolves the indexing ambiguity (below), but is NOT used to scale - the rotation merge stays
|
||||
|
||||
Reference in new issue
Block a user