First pass: start the long-axis searches ahead of the hypothesis
The long-axis hypothesis (the coarse 1200 A search, then a re-index of each cell it offers) was 1.10 s of thau's Step 3 and 0.36 s of its Step 6, almost all of it CPU work after a few ms of FFT, while the rest of the machine sat idle. Its searches need only the fed spots and the experiment, so they now start ahead of it, on a copy of the experiment and a pool of their own (FirstPassRun::long_axis_spec): the coarse search beside the file centre's schemes (IndexSchemes), the re-index of each cell it offers beside the beam-centre check. The hypothesis then asks the same questions, and RotationIndexer's memo, keyed on every input an indexer reads, answers them. Where the run moved in between (the axis-sign rescue, another centre), the key differs and the hypothesis indexes as before; a search that failed leaves no memo and the hypothesis meets the failure itself. The parameter code the two share is factored out (LongAxisBound, LongAxisCoarseSettings, LongAxisReindexSettings, LongAxisOffers). Results identical by construction. Rotation first pass, -N 28, 5950X + RTX 5080, machine shared with other jobs (median of 2 before, 4 after, s): Step 3 / Step 6, after the two indexer commits thau 1000 images: 2.10 / 1.00 -> 1.65 / 0.84 (long-axis line 1.16 -> 0.02 s) cytc: 1.62 -> 1.50 lyso: 1.76 / 0.84 -> 1.40 / 0.65 a ~1000 A-axis crystal (private): wall 84 -> 70 s _report.txt (minus run-specific lines) and .hkl identical on all four. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HVeDQsU5a8AJUdJPgWevAK
This commit is contained in:
1 parent
388474ba4a
commit
556e61b3c1
4 files changed
+144
-30
No files matched your search
@@ -121,7 +121,7 @@ For each direction, the FFT magnitude spectrum is computed; peaks correspond to
|
||||
|
||||
The running-mean background window keeps a **constant width** and is slid inward at the ends of the spectrum rather than truncated there, so a peak within half a window of either end — which is where the longest cells sit — is judged against as much background as any other. Both window bounds stay monotonically non-decreasing in the bin index, so the GPU kernel's running sum is still valid.
|
||||
|
||||
The longest basis vector the transform can return is `fft_max_unit_cell_A`, since the histogram is sized from it and its last usable bin *is* that length; the shortest is `fft_min_unit_cell_A` (`rugnux --fft-min-unit-cell`, default 10 Å), below which a candidate is discarded. The defaults are unchanged (500 Å and 10 Å), but the accepted range for the maximum now reaches 1200 Å, and a reference cell given with `-C` moves **both** bounds on its own — up to reach a long axis, down to admit a small-molecule cell — since a cell the search cannot represent cannot be found by it. A de-novo rotation run asks the long end a second time as a **long-axis hypothesis**: the detector separates the rows of an axis of length $L$ while their spacing near the beam, $D\lambda/L$, exceeds the measured spot width, so wherever $D\lambda/(p\,r_{80})$ ($p$ the pixel size, $r_{80}$ the pre-scan's spot width) exceeds the standard bound, a coarse search (3.5 Å histogram) to that length, at most 1200 Å, offers its lattices. Each is re-indexed at full resolution with its cell as the reference, and the one putting the largest share of the pooled validation spots on itself beyond chance replaces the standing lattice where that share is significantly larger (the pooled-spot comparison the first pass uses for every competing lattice) — except an exact superlattice of the standing cell, for which the pooled count is biased and which is left to the supercell probe of the merge. It is asked of every such run, whatever the standing pass indexed: a wrong axis along a fine row still indexes most frames.
|
||||
The longest basis vector the transform can return is `fft_max_unit_cell_A`, since the histogram is sized from it and its last usable bin *is* that length; the shortest is `fft_min_unit_cell_A` (`rugnux --fft-min-unit-cell`, default 10 Å), below which a candidate is discarded. The defaults are unchanged (500 Å and 10 Å), but the accepted range for the maximum now reaches 1200 Å, and a reference cell given with `-C` moves **both** bounds on its own — up to reach a long axis, down to admit a small-molecule cell — since a cell the search cannot represent cannot be found by it. A de-novo rotation run asks the long end a second time as a **long-axis hypothesis**: the detector separates the rows of an axis of length $L$ while their spacing near the beam, $D\lambda/L$, exceeds the measured spot width, so wherever $D\lambda/(p\,r_{80})$ ($p$ the pixel size, $r_{80}$ the pre-scan's spot width) exceeds the standard bound, a coarse search (3.5 Å histogram) to that length, at most 1200 Å, offers its lattices. Each is re-indexed at full resolution with its cell as the reference, and the one putting the largest share of the pooled validation spots on itself beyond chance replaces the standing lattice where that share is significantly larger (the pooled-spot comparison the first pass uses for every competing lattice) — except an exact superlattice of the standing cell, for which the pooled count is biased and which is left to the supercell probe of the merge. It is asked of every such run, whatever the standing pass indexed: a wrong axis along a fine row still indexes most frames. Its searches are started ahead of the question - the coarse one beside the file centre's schemes, the re-index of what it offers beside the beam-centre check - and the question then reads their answers from the indexer's memo: this changes when they run, not what they find.
|
||||
|
||||
Candidate vectors are $\mathbf{v}_d = L_d\,\mathbf{u}_d$.
|
||||
|
||||
|
||||
@@ -484,6 +484,7 @@ bool Rugnux::FirstPassRotationIndexing(PipelineLocals &p) {
|
||||
run.PrefetchCertainFrames();
|
||||
FirstPass best = run.IndexSchemes();
|
||||
best = run.AxisSignRescue(std::move(best));
|
||||
run.StartLongAxisReindex(best);
|
||||
bool long_axis_asked = false;
|
||||
best = run.BeamCentreCheck(std::move(best), long_axis_asked);
|
||||
// The long-axis hypothesis, at the centre the run now stands on.
|
||||
@@ -1516,7 +1517,10 @@ void Rugnux::FirstPassRun::StartCentreSpeculation() {
|
||||
}
|
||||
|
||||
auto Rugnux::FirstPassRun::IndexSchemes() -> FirstPass {
|
||||
return PickBest(*indexer_pool, *indexer, [&] { StartCentreSpeculation(); });
|
||||
return PickBest(*indexer_pool, *indexer, [&] {
|
||||
StartLongAxisCoarse();
|
||||
StartCentreSpeculation();
|
||||
});
|
||||
}
|
||||
|
||||
// Twinning by reticular merohedry: two domains of one lattice whose nodes coincide on a sub-lattice
|
||||
|
||||
@@ -69,6 +69,10 @@ struct Rugnux::FirstPassRun {
|
||||
// The beam-centre check; sets long_axis_asked where it has asked the long-axis hypothesis itself.
|
||||
FirstPass BeamCentreCheck(FirstPass best, bool &long_axis_asked);
|
||||
FirstPass LongAxisHypothesis(FirstPass standing);
|
||||
// Its searches, started ahead of it (see long_axis_spec): the coarse one beside the file centre's
|
||||
// schemes, the re-index of what that offers beside the beam-centre check.
|
||||
void StartLongAxisCoarse();
|
||||
void StartLongAxisReindex(const FirstPass &standing);
|
||||
FirstPass AddEndWedge(FirstPass bp, IndexerThreadPool &pool, IndexAndRefine &idx);
|
||||
void ReleaseSpotEngines();
|
||||
// Throws where the pass ends with no lattice at all.
|
||||
@@ -143,6 +147,16 @@ struct Rugnux::FirstPassRun {
|
||||
const std::function<void()> &alongside = {});
|
||||
void ApplyState(const FirstPassState &st);
|
||||
void StartCentreSpeculation();
|
||||
// How long an axis the detector separates the rows of, for the spots the run has.
|
||||
struct LongAxisReach {
|
||||
float width_px = 0.0f, resolvable_A = 0.0f, bound_A = 0.0f;
|
||||
};
|
||||
LongAxisReach LongAxisBound() const;
|
||||
// The settings of the coarse search, and of the re-index of the cell `x` holds.
|
||||
IndexingSettings LongAxisCoarseSettings(float bound_A) const;
|
||||
IndexingSettings LongAxisReindexSettings(const DiffractionExperiment &x) const;
|
||||
// The coarse cells other than the standing lattice, each once.
|
||||
static std::vector<UnitCell> LongAxisOffers(const SchemeIndexers &ris, const FirstPass &standing);
|
||||
|
||||
// --- Near ties ---
|
||||
//
|
||||
@@ -330,4 +344,23 @@ struct Rugnux::FirstPassRun {
|
||||
std::future<void> done; // last, so it is waited for before the rest goes
|
||||
};
|
||||
std::optional<CentreSpeculation> centre_spec;
|
||||
|
||||
// The long-axis hypothesis's FFT searches need only the fed spots and the experiment, and leave
|
||||
// most of the machine idle (the card does a few percent of the work). So they are started ahead of
|
||||
// it, on a copy of the experiment and a pool of their own: the coarse search beside the file
|
||||
// centre's schemes, and the re-index of each cell it offers beside the beam-centre check. The
|
||||
// hypothesis then asks the same questions and RotationIndexer's memo, keyed on everything an
|
||||
// indexer reads, answers them; where the run has moved in between (another centre or axis sign)
|
||||
// the keys differ and it indexes as before. Nothing here is read but the memo.
|
||||
struct LongAxisSpeculation {
|
||||
std::unique_ptr<DiffractionExperiment> experiment;
|
||||
std::unique_ptr<IndexerThreadPool> own_pool; // none where the run's pool is wide enough
|
||||
SchemeIndexers ris;
|
||||
std::future<void> done; // last, so it is waited for before the rest goes
|
||||
};
|
||||
std::vector<LongAxisSpeculation> long_axis_spec;
|
||||
// The experiment the coarse search was started on.
|
||||
std::vector<double> long_axis_spec_key;
|
||||
void StartLongAxisSearch(std::unique_ptr<DiffractionExperiment> x, const IndexingSettings &settings, bool own_pool);
|
||||
void JoinLongAxisSpeculation();
|
||||
};
|
||||
@@ -143,6 +143,99 @@ auto Rugnux::FirstPassRun::AxisSignRescue(FirstPass best) -> FirstPass {
|
||||
return best;
|
||||
}
|
||||
|
||||
// The parts of the long-axis hypothesis below, shared with the searches started ahead of it (long_axis_spec).
|
||||
auto Rugnux::FirstPassRun::LongAxisBound() const -> LongAxisReach {
|
||||
LongAxisReach r;
|
||||
r.width_px = rx.spot_width_r80_px_.value_or(rx.experiment_.GetBraggIntegrationSettings().GetR1());
|
||||
r.resolvable_A = ResolvableAxisLength_A(rx.experiment_.GetDetectorDistance_mm(), rx.experiment_.GetWavelength_A(),
|
||||
rx.experiment_.GetPixelSize_mm(), r.width_px);
|
||||
r.bound_A = std::min(r.resolvable_A, IndexingSettings::fft_max_unit_cell_limit_A);
|
||||
return r;
|
||||
}
|
||||
|
||||
IndexingSettings Rugnux::FirstPassRun::LongAxisCoarseSettings(float bound_A) const {
|
||||
auto settings = rx.experiment_.GetIndexingSettings();
|
||||
settings.FFT_HighResolution_A(3.5f);
|
||||
settings.FFT_MaxUnitCell_A(bound_A);
|
||||
settings.IndexingThreads(rx.FirstPassIndexerThreads());
|
||||
settings.RefineThreads(std::clamp(rx.config_.nthreads / 2, 1, MAX_REFINE_THREADS));
|
||||
return settings;
|
||||
}
|
||||
|
||||
IndexingSettings Rugnux::FirstPassRun::LongAxisReindexSettings(const DiffractionExperiment &x) const {
|
||||
auto settings = x.GetIndexingSettings();
|
||||
settings.IndexingThreads(rx.FirstPassIndexerThreads());
|
||||
settings.RefineThreads(std::clamp(rx.config_.nthreads / 2, 1, MAX_REFINE_THREADS));
|
||||
RaiseFFTBoundForKnownCell(settings, x);
|
||||
return settings;
|
||||
}
|
||||
|
||||
std::vector<UnitCell> Rugnux::FirstPassRun::LongAxisOffers(const SchemeIndexers &ris, const FirstPass &standing) {
|
||||
std::vector<RotationIndexerResult> offered;
|
||||
for (auto &ri : ris) {
|
||||
auto r = ri->GetLattice();
|
||||
if (!r.has_value() || (standing.result && SameLattice(*r, *standing.result))
|
||||
|| std::ranges::any_of(offered, [&](const auto &o) { return SameLattice(*r, o); }))
|
||||
continue;
|
||||
offered.push_back(std::move(*r));
|
||||
}
|
||||
std::vector<UnitCell> cells;
|
||||
for (const auto &o : offered)
|
||||
cells.push_back(o.lattice.GetUnitCell());
|
||||
return cells;
|
||||
}
|
||||
|
||||
// One search of long_axis_spec, on its own copy of the experiment, in a pool of its own or in the run's.
|
||||
void Rugnux::FirstPassRun::StartLongAxisSearch(std::unique_ptr<DiffractionExperiment> x,
|
||||
const IndexingSettings &settings, bool own_pool) {
|
||||
auto &s = long_axis_spec.emplace_back();
|
||||
s.experiment = std::move(x);
|
||||
if (own_pool)
|
||||
s.own_pool = std::make_unique<IndexerThreadPool>(settings, IndexerConstruction::OnFirstUse,
|
||||
rx.gpu_work_beside_);
|
||||
s.ris = FeedSchemes(own_pool ? *s.own_pool : *indexer_pool, s.experiment.get());
|
||||
std::vector<RotationIndexer *> ris;
|
||||
for (const auto &ri : s.ris)
|
||||
ris.push_back(ri.get());
|
||||
s.done = std::async(std::launch::async, [ris] { RunIndexing(ris); });
|
||||
}
|
||||
|
||||
void Rugnux::FirstPassRun::StartLongAxisCoarse() {
|
||||
if (rx.cancelled_ || rx.experiment_.GetUnitCell().has_value())
|
||||
return;
|
||||
const LongAxisReach reach = LongAxisBound();
|
||||
if (!(reach.bound_A > indexing_bound_A))
|
||||
return;
|
||||
long_axis_spec_key = rx.ExperimentKey();
|
||||
StartLongAxisSearch(std::make_unique<DiffractionExperiment>(rx.experiment_),
|
||||
LongAxisCoarseSettings(reach.bound_A), true);
|
||||
}
|
||||
|
||||
void Rugnux::FirstPassRun::StartLongAxisReindex(const FirstPass &standing) {
|
||||
if (long_axis_spec.empty())
|
||||
return;
|
||||
// A search that failed leaves no memo; the hypothesis then meets the failure itself.
|
||||
long_axis_spec.front().done.wait();
|
||||
const bool same_run = long_axis_spec_key == rx.ExperimentKey();
|
||||
const std::vector<UnitCell> offered = same_run ? LongAxisOffers(long_axis_spec.front().ris, standing)
|
||||
: std::vector<UnitCell>{};
|
||||
long_axis_spec.clear();
|
||||
for (const auto &cell : offered) {
|
||||
if (rx.cancelled_)
|
||||
break;
|
||||
auto x = std::make_unique<DiffractionExperiment>(rx.experiment_);
|
||||
x->SetUnitCell(cell);
|
||||
const IndexingSettings settings = LongAxisReindexSettings(*x);
|
||||
StartLongAxisSearch(std::move(x), settings, settings.GetFFT_MaxUnitCell_A() > indexing_bound_A);
|
||||
}
|
||||
}
|
||||
|
||||
void Rugnux::FirstPassRun::JoinLongAxisSpeculation() {
|
||||
for (auto &s : long_axis_spec)
|
||||
s.done.wait();
|
||||
long_axis_spec.clear();
|
||||
}
|
||||
|
||||
// Long-axis hypothesis. The standard search reaches fft_max_unit_cell_A (500 A), and DeAlias unfolds
|
||||
// rows up to twice that, so a longer axis is not a candidate at all: it comes back as a sub-multiple,
|
||||
// or as a folded row that unfolds to the wrong length, and the cell built on it puts only a minority
|
||||
@@ -168,14 +261,12 @@ auto Rugnux::FirstPassRun::AxisSignRescue(FirstPass best) -> FirstPass {
|
||||
//
|
||||
// Not when a cell was given: the standard pass was already sized for it (RaiseFFTBoundForKnownCell).
|
||||
auto Rugnux::FirstPassRun::LongAxisHypothesis(FirstPass standing) -> FirstPass {
|
||||
JoinLongAxisSpeculation();
|
||||
if (rx.cancelled_ || rx.experiment_.GetUnitCell().has_value())
|
||||
return standing;
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
const float width_px = rx.spot_width_r80_px_.value_or(rx.experiment_.GetBraggIntegrationSettings().GetR1());
|
||||
const float resolvable_A = ResolvableAxisLength_A(rx.experiment_.GetDetectorDistance_mm(),
|
||||
rx.experiment_.GetWavelength_A(),
|
||||
rx.experiment_.GetPixelSize_mm(), width_px);
|
||||
const float bound_A = std::min(resolvable_A, IndexingSettings::fft_max_unit_cell_limit_A);
|
||||
const LongAxisReach reach = LongAxisBound();
|
||||
const float width_px = reach.width_px, resolvable_A = reach.resolvable_A, bound_A = reach.bound_A;
|
||||
if (!(bound_A > indexing_bound_A)) {
|
||||
logger.Info("Long-axis hypothesis: not asked - at {:.0f} mm, {:.4f} A and {:.0f} um pixels the rows of an "
|
||||
"axis are separated up to {:.0f} A for {:.2f} px spots, within the {:.0f} A the standard "
|
||||
@@ -183,30 +274,19 @@ auto Rugnux::FirstPassRun::LongAxisHypothesis(FirstPass standing) -> FirstPass {
|
||||
1000.0f * rx.experiment_.GetPixelSize_mm(), resolvable_A, width_px, indexing_bound_A);
|
||||
return standing;
|
||||
}
|
||||
|
||||
auto coarse_settings = rx.experiment_.GetIndexingSettings();
|
||||
coarse_settings.FFT_HighResolution_A(3.5f);
|
||||
coarse_settings.FFT_MaxUnitCell_A(bound_A);
|
||||
coarse_settings.IndexingThreads(rx.FirstPassIndexerThreads());
|
||||
coarse_settings.RefineThreads(std::clamp(rx.config_.nthreads / 2, 1, MAX_REFINE_THREADS));
|
||||
std::vector<RotationIndexerResult> offered;
|
||||
std::vector<UnitCell> offered;
|
||||
{
|
||||
IndexerThreadPool coarse_pool(coarse_settings, IndexerConstruction::OnFirstUse, rx.gpu_work_beside_);
|
||||
IndexerThreadPool coarse_pool(LongAxisCoarseSettings(bound_A), IndexerConstruction::OnFirstUse,
|
||||
rx.gpu_work_beside_);
|
||||
const SchemeIndexers cris = FeedSchemes(coarse_pool);
|
||||
RunIndexing(cris);
|
||||
for (auto &ri : cris) {
|
||||
auto r = ri->GetLattice();
|
||||
if (!r.has_value() || (standing.result && SameLattice(*r, *standing.result))
|
||||
|| std::ranges::any_of(offered, [&](const auto &o) { return SameLattice(*r, o); }))
|
||||
continue;
|
||||
offered.push_back(std::move(*r));
|
||||
}
|
||||
offered = LongAxisOffers(cris, standing);
|
||||
}
|
||||
|
||||
const auto cell_text = [](const RotationIndexerResult &r) {
|
||||
const auto uc = r.lattice.GetUnitCell();
|
||||
const auto uc_text = [](const UnitCell &uc) {
|
||||
return fmt::format("{:.1f} {:.1f} {:.1f} {:.1f} {:.1f} {:.1f}", uc.a, uc.b, uc.c, uc.alpha, uc.beta, uc.gamma);
|
||||
};
|
||||
const auto cell_text = [&](const RotationIndexerResult &r) { return uc_text(r.lattice.GetUnitCell()); };
|
||||
const auto share = [](const PooledEvidence &e) {
|
||||
return fmt::format("{}/{} pooled spots ({} by chance)", e.on_lattice, e.spots, e.by_chance);
|
||||
};
|
||||
@@ -222,11 +302,8 @@ auto Rugnux::FirstPassRun::LongAxisHypothesis(FirstPass standing) -> FirstPass {
|
||||
// The re-index must be able to REPRESENT the cell the coarse pass offered; the standard pool was
|
||||
// sized at the default bound. CountIndexed forces the lattice and never touches the pool, so the
|
||||
// run's IndexAndRefine is reused and only the FFT needs the wider one.
|
||||
rx.experiment_.SetUnitCell(coarse.lattice.GetUnitCell());
|
||||
auto wide_settings = rx.experiment_.GetIndexingSettings();
|
||||
wide_settings.IndexingThreads(rx.FirstPassIndexerThreads());
|
||||
wide_settings.RefineThreads(std::clamp(rx.config_.nthreads / 2, 1, MAX_REFINE_THREADS));
|
||||
RaiseFFTBoundForKnownCell(wide_settings, rx.experiment_);
|
||||
rx.experiment_.SetUnitCell(coarse);
|
||||
const auto wide_settings = LongAxisReindexSettings(rx.experiment_);
|
||||
FirstPass c;
|
||||
if (wide_settings.GetFFT_MaxUnitCell_A() > indexing_bound_A) {
|
||||
IndexerThreadPool wide_pool(wide_settings, IndexerConstruction::OnFirstUse, rx.gpu_work_beside_);
|
||||
@@ -235,7 +312,7 @@ auto Rugnux::FirstPassRun::LongAxisHypothesis(FirstPass standing) -> FirstPass {
|
||||
c = PickBest(*indexer_pool, *indexer);
|
||||
}
|
||||
rx.experiment_.SetUnitCell(std::nullopt); // leave the space-group / cell determination de-novo
|
||||
counts += fmt::format("; coarse {}", cell_text(coarse));
|
||||
counts += fmt::format("; coarse {}", uc_text(coarse));
|
||||
if (!c.result.has_value()) {
|
||||
counts += " re-indexes to nothing";
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user