Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry up to 10 times when error requesting Koina predictions #3197

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pwiz_tools/Skyline/FileUI/PeptideSearch/SearchControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using pwiz.Common.SystemUtil;
using pwiz.Skyline.Alerts;
using pwiz.Skyline.Util;
using pwiz.Skyline.Util.Extensions;

namespace pwiz.Skyline.FileUI.PeptideSearch
{
Expand Down Expand Up @@ -142,8 +143,11 @@ protected void UpdateSearchEngineProgress(IProgressStatus status)
}

// look at the last 10 lines for the same message and if found do not relog the same message
if (_progressTextItems.Skip(Math.Max(0, _progressTextItems.Count - 10)).Any(entry => entry.Message == message))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this blatant missing optimization has been in .NET since 2016 or so, but alas doesn't seem to have made it into Framework.

if (Enumerable.Range(Math.Max(0, _progressTextItems.Count - 10), Math.Min(10, _progressTextItems.Count))
.Any(i => _progressTextItems[i].Message == message))
{
return;
}

if (message.EndsWith(@"%") && double.TryParse(message.Substring(0, message.Length - 1), out _))
{
Expand Down Expand Up @@ -229,8 +233,9 @@ private void showTimestampsCheckbox_CheckedChanged(object sender, EventArgs e)
private void RefreshProgressTextbox()
{
txtSearchProgress.Clear();
foreach (var entry in _progressTextItems)
txtSearchProgress.AppendText($@"{entry.ToString(showTimestampsCheckbox.Checked)}{Environment.NewLine}");
txtSearchProgress.AppendText(TextUtil.LineSeparate(_progressTextItems.Select(entry
=> entry.ToString(showTimestampsCheckbox.Checked))) + Environment.NewLine);

}

public string LogText => txtSearchProgress.Text;
Expand All @@ -247,7 +252,7 @@ public virtual UpdateProgressResponse UpdateProgress(IProgressStatus status)
if (InvokeRequired)
Invoke(new MethodInvoker(() => UpdateProgress(status)));
else
UpdateSearchEngineProgress(status.ChangeMessage(status.Message));
UpdateSearchEngineProgress(status);

return UpdateProgressResponse.normal;
}
Expand Down
35 changes: 22 additions & 13 deletions pwiz_tools/Skyline/Model/Koina/KoinaResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pwiz_tools/Skyline/Model/Koina/KoinaResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,7 @@
<data name="GraphSpectrum_UpdateUI_No_spectral_library_match" xml:space="preserve">
<value>No spectral library match</value>
</data>
<data name="KoinaModel_PredictBatches_Error___0__retrying__1_____2__" xml:space="preserve">
<value>Error: {0} retrying {1}/{2}.</value>
</data>
</root>
8 changes: 8 additions & 0 deletions pwiz_tools/Skyline/Model/Koina/Models/KoinaIntensityModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -28,6 +29,7 @@
using pwiz.Skyline.Model.DocSettings;
using pwiz.Skyline.Properties;
using pwiz.Skyline.Util;
using pwiz.Skyline.Util.Extensions;
using static Inference.ModelInferRequest.Types;

namespace pwiz.Skyline.Model.Koina.Models
Expand Down Expand Up @@ -271,6 +273,12 @@ public KoinaPrecursorInput(string peptideSequence, int precursorCharge, float no
public int PrecursorCharge { get; }

public float NormalizedCollisionEnergy { get; }

public override string ToString()
{
return TextUtil.SpaceSeparate(PeptideSequence + Transition.GetChargeIndicator(PrecursorCharge),
TextUtil.ColonSeparate(@"NCE", NormalizedCollisionEnergy.ToString(CultureInfo.CurrentCulture)));
}
}
}

Expand Down
32 changes: 28 additions & 4 deletions pwiz_tools/Skyline/Model/Koina/Models/KoinaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,39 @@ public TKoinaOut PredictBatches(GRPCInferenceService.GRPCInferenceServiceClient
var koinaOutput = new List<TKoinaOut>();
for (int i = 0; i < inputsList.Count; ++i)
koinaOutput.Add(null);

int retryCount = Settings.Default.KoinaRetryCount;
ParallelEx.For(0, inputsList.Count, batchIndex =>
{
var koinaIn = inputsList[batchIndex];

if (progressMonitor.UpdateProgress(localProgressStatus) == UpdateProgressResponse.cancel)
return;

koinaOutput[batchIndex] = Predict(predictionClient, koinaIn, token);
var koinaExceptions = new List<KoinaException>();
for (int attempt = 0;; attempt++)
{
try
{
koinaOutput[batchIndex] = Predict(predictionClient, koinaIn, token);
break;
}
catch (KoinaException koinaException)
{
koinaExceptions.Add(koinaException);
if (attempt >= retryCount)
{
throw new AggregateException(koinaExceptions);
}
lock (progressMonitor)
{
string message = string.Format(
KoinaResources.KoinaModel_PredictBatches_Error___0__retrying__1_____2__,
koinaException.Message,
attempt + 1, retryCount);
localProgressStatus = localProgressStatus.ChangeMessage(message);
progressMonitor.UpdateProgress(localProgressStatus);
}
}
}

lock(progressMonitor)
{
Expand Down Expand Up @@ -752,7 +776,7 @@ public static IEnumerable<IEnumerable<T>> EnumerateBatches<T>(IList<T> data, int
while (dataIndex < data.Count)
{
var size = Math.Min(data.Count - dataIndex, batchSize);
yield return data.Skip(dataIndex).Take(size);
yield return Enumerable.Range(dataIndex, size).Select(i => data[i]);
dataIndex += size;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ public KoinaPeptideInput(string peptideSequence)
}

public string PeptideSequence { get; private set; }
public override string ToString()
{
return PeptideSequence;
}
}
}

Expand Down
31 changes: 18 additions & 13 deletions pwiz_tools/Skyline/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pwiz_tools/Skyline/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -881,5 +881,8 @@
<Setting Name="RelativeAbundanceLogScale" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="KoinaRetryCount" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">10</Value>
</Setting>
</Settings>
</SettingsFile>
7 changes: 5 additions & 2 deletions pwiz_tools/Skyline/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,10 @@
<value>False</value>
</setting>
<setting name="FeatureFindingMinIntensityPPM" serializeAs="String">
<value>100.0</value>
<value>10.0</value>
</setting>
<setting name="FeatureFindingMinIdotP" serializeAs="String">
<value>0.9</value>
<value>0.98</value>
</setting>
<setting name="FeatureFindingSignalToNoise" serializeAs="String">
<value>3</value>
Expand Down Expand Up @@ -890,6 +890,9 @@
<setting name="InstalledVersion" serializeAs="String">
<value />
</setting>
<setting name="KoinaRetryCount" serializeAs="String">
<value>10</value>
</setting>
</pwiz.Skyline.Properties.Settings>
</applicationSettings>
<system.data>
Expand Down