TP: Skip amplifier calls during Auto TP amplitude update#2694
Conversation
Agent-Logs-Url: https://github.com/AllenInstitute/MIES/sessions/e60e071a-b1e4-47c9-813e-6c2f5fa1d955 Co-authored-by: timjarsky <5693697+timjarsky@users.noreply.github.com>
| PUB_TPSettingChange(device, headstage, "amplitudeIC", val, "mV") | ||
|
|
||
| if(IsFinite(TPState)) | ||
| TP_RestartTestPulse(device, TPState, fast = 1) |
There was a problem hiding this comment.
@copilot, I don't think using fast mode will work because the DAC isn't reconfigured with the updated TP DA waveform. Can you confirm?
There was a problem hiding this comment.
Confirmed, you're right. TP_Setup with fast = 1 short-circuits before DC_Configure, so DC_PlaceDataInDAQDataWave / DC_FillDAQDataWaveForTP — which multiply the TP template by s.DACAmp[%TPAMP] = TPSettings[%amplitudeIC] — never run, and the DAQ wave keeps the previous amplitude. So the fast restart here is incorrect.
Tracing it further, the AI_* calls in the non-fast restart path don't actually originate from DC_Configure itself — they come from DAP_CheckSettings → DAP_CheckHeadStage (AI_SelectMultiClamp, AI_EnsureCorrectMode, AI_QueryGainsUnitsForClampMode), which TPS_StartTestPulseSingleDevice invokes on the non-fast path (MIES_TestPulse_Single.ipf:103). So the target we actually want to skip is DAP_CheckSettings, not DC_Configure.
How would you like to proceed? A couple of options:
- Use
fast = 0on the restart (soDC_Configurerebuilds the DAQ wave correctly) and add an internal opt-out on the TP-start path to skipDAP_CheckSettingsfor this Auto-TP-only case (the check has already been performed when TP was originally started, and we're only rescaling the DAC). - Introduce a narrower helper that just rebuilds the TP DAC wave (
DC_FillDAQDataWaveForTPand its prerequisites) under a fast restart, without going through the fullDC_Configure.
Option 1 is the smaller change and keeps the existing contract of DC_Configure intact. I'll hold off on further changes until you confirm the preferred direction.
There was a problem hiding this comment.
@copilot Let's try option 1 first to check functionality.
There was a problem hiding this comment.
Implemented option 1 in fc733e0. TP_ApplyAutoTPAmplitudeUpdate now restarts TP with fast = 0 (so DC_Configure rebuilds the DAQ wave from the updated TPSettings[%amplitudeIC]) and passes a new skipCheckSettings = 1 flag. Added that flag as an optional parameter on TP_RestartTestPulse, TPS_StartTestPulseSingleDevice, and TPM_StartTestPulseMultiDevice; when set, the TP start path skips DAP_CheckSettings, which is what actually drives the AI_* amplifier calls via DAP_CheckHeadStage. Existing callers keep the default behavior.
…pdate Agent-Logs-Url: https://github.com/AllenInstitute/MIES/sessions/7c91cdb8-ee23-407d-b327-42a0c710f29b Co-authored-by: timjarsky <5693697+timjarsky@users.noreply.github.com>
|
Tested this PR on Rig 5 |
|
I'll have a look. But unfortunately this is quite shitty code. |
|
Review:
|
|
@copilot, switching to current clamp while the TP is running gives the following assertion: The control in question is : Control = "check_DataAcq_AutoTP" (String) It is a checkbox. You can tell because the name prefix says "check_" |
Agent-Logs-Url: https://github.com/AllenInstitute/MIES/sessions/bf940376-e9cd-4532-a66b-5fef7d54638d Co-authored-by: timjarsky <5693697+timjarsky@users.noreply.github.com>
... Fixed in 3788b24. The new |
|
I tested with two headstages, and it's working well. |
|
Review:
@timjarsky Feel free to assign it back to me so that I can make the changes directly. |
| - Use valid initial values for some more amplifier controls | ||
| - Rework amplififer getting and setting | ||
| - Auto TP: Skip unnecessary amplifier (``AI_*``) calls when updating only the IC | ||
| amplitude by using a fast TP restart that rebuilds only the DAQ data wave |
Agent-Logs-Url: https://github.com/AllenInstitute/MIES/sessions/7c1c5356-ae6e-43fb-bf60-300cb9ba4aa2 Co-authored-by: timjarsky <5693697+timjarsky@users.noreply.github.com>
Addressed in 1d1b62b:
|
@t-b Doesn't starting or stopping a stopped TP induce calls to the MCC? |
No. |
@t-b |
@timjarsky As mentioned in #2694 (comment) the special casing in DAP_TPSettingsToGUI to not use PGC for this particular control is missing. |
|
Review: DAP_TPSettingsToGUI: This means we call What still needs fixing there are functions left which still use binary 0/1 fast: These should also be ported to the new TP_FAST_XXX flags. |
Thanks for opening a PR in MIES ✨!
here for the detailed explanation.
Description
Auto TP IC amplitude updates previously routed through
DAP_TPSettingsToGUI→DAP_TPGUISettingToWave→TP_RestartTestPulse(non-fast) →TPS_StartTestPulseSingleDevice/TPM_StartTestPulseMultiDevice→DAP_CheckSettings→DAP_CheckHeadStage, triggeringAI_*amplifier interactions (AI_SelectMultiClamp,AI_EnsureCorrectMode,AI_QueryGainsUnitsForClampMode) on every adjustment. This adds MCC communication load and risks amplifier glitches for what is only a DAC waveform rescale.The boolean
fastflag on the TP setup/start path has been promoted to a 3-valued enum, and Auto TP IC amplitude updates now restart TP using the newTP_FAST_CONFIGmode. In that modeTP_SetuprunsDC_Configure(so the DAQ data wave is rebuilt from the updatedTPSettings[%amplitudeIC]) and then takes the existing fast early-return — short-circuiting beforeDAP_CheckSettings/DAP_CheckHeadStageand the resultingAI_*amplifier calls. Stop and restart are now symmetric (both use the fast path).The Auto TP call site no longer uses a bespoke helper. Instead,
DAP_TPSettingsToGUIaccepts afastparameter and is the single entry point for syncing TP settings to the GUI.Changes
MIES_Constants.ipf— new@ref TestPulseFastModesenum next toTestPulseRunModes:TP_FAST_NONE = 0— full setup, includingDAP_CheckSettingsandDC_ConfigureTP_FAST_NO_CONFIG = 1— skipDAP_CheckSettings, UI work, andDC_Configure(existing fast behavior)TP_FAST_CONFIG = 2— skipDAP_CheckSettingsand UI work but still runDC_ConfigureTP_Setup— accepts the enum and asserts a valid value; whenfast == TP_FAST_CONFIGit callsDC_Configure(device, TEST_PULSE_MODE, multiDevice = (runMode & TEST_PULSE_BG_MULTI_DEVICE))before the fast early-return. Branches use explicit==comparisons against the enum constants instead of relying onif(fast)truthiness.TP_RestartTestPulse/TPS_StartTestPulseSingleDevice/TPM_StartTestPulseMultiDevice/TPM_StartTPMultiDeviceLow— accept and forward thefastenum, asserting the value is one ofTP_FAST_NONE/TP_FAST_NO_CONFIG/TP_FAST_CONFIG. Branches use explicit==comparisons against the enum constants. Doc comments reference the enum constants (no "non-zero" wording).DAP_TPSettingsToGUI— gained an optionalfastparameter (one of theTestPulseFastModesvalues, asserted). It still usesPGC_SetAndActivateControlin its loop (unchanged). Whenfast != TP_FAST_NONEit usesTP_StopTestPulseFastfor the stop and forwardsfasttoTP_RestartTestPulse.DAP_TPGUISettingToWaveis unchanged.TP_AutoAmplitudeAndBaseline— callsDAP_TPSettingsToGUI(device, entry = "amplitudeIC", fast = TP_FAST_CONFIG)directly. The previously introducedTP_ApplyAutoTPAmplitudeUpdatehelper has been removed (no more code duplication).The new
TP_FAST_CONFIGenum value is the only new fast mode introduced; existing callers keep the previous behavior sinceTP_FAST_NONE = 0matches the priorfast = 0default andTP_FAST_NO_CONFIG = 1matches the priorfast = 1semantics. With the refactor, an Auto TP IC amplitude update now performs exactly one fast TP stop/restart with noAI_*amplifier calls.