Skip to content

TP: Skip amplifier calls during Auto TP amplitude update#2694

Open
timjarsky with Copilot wants to merge 8 commits into
mainfrom
copilot/skip-amplifier-calls-auto-tp-update
Open

TP: Skip amplifier calls during Auto TP amplitude update#2694
timjarsky with Copilot wants to merge 8 commits into
mainfrom
copilot/skip-amplifier-calls-auto-tp-update

Conversation

Copilot AI commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for opening a PR in MIES ✨!

  • Code can only be merged if the continous integration tests pass
  • Please ensure that the branch is named correctly. See
    here for the detailed explanation.

Description

Auto TP IC amplitude updates previously routed through DAP_TPSettingsToGUIDAP_TPGUISettingToWaveTP_RestartTestPulse (non-fast) → TPS_StartTestPulseSingleDevice/TPM_StartTestPulseMultiDeviceDAP_CheckSettingsDAP_CheckHeadStage, triggering AI_* 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 fast flag 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 new TP_FAST_CONFIG mode. In that mode TP_Setup runs DC_Configure (so the DAQ data wave is rebuilt from the updated TPSettings[%amplitudeIC]) and then takes the existing fast early-return — short-circuiting before DAP_CheckSettings/DAP_CheckHeadStage and the resulting AI_* 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_TPSettingsToGUI accepts a fast parameter and is the single entry point for syncing TP settings to the GUI.

Changes

  • MIES_Constants.ipf — new @ref TestPulseFastModes enum next to TestPulseRunModes:
    • TP_FAST_NONE = 0 — full setup, including DAP_CheckSettings and DC_Configure
    • TP_FAST_NO_CONFIG = 1 — skip DAP_CheckSettings, UI work, and DC_Configure (existing fast behavior)
    • TP_FAST_CONFIG = 2 — skip DAP_CheckSettings and UI work but still run DC_Configure
  • TP_Setup — accepts the enum and asserts a valid value; when fast == TP_FAST_CONFIG it calls DC_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 on if(fast) truthiness.
  • TP_RestartTestPulse / TPS_StartTestPulseSingleDevice / TPM_StartTestPulseMultiDevice / TPM_StartTPMultiDeviceLow — accept and forward the fast enum, asserting the value is one of TP_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 optional fast parameter (one of the TestPulseFastModes values, asserted). It still uses PGC_SetAndActivateControl in its loop (unchanged). When fast != TP_FAST_NONE it uses TP_StopTestPulseFast for the stop and forwards fast to TP_RestartTestPulse. DAP_TPGUISettingToWave is unchanged.
  • TP_AutoAmplitudeAndBaseline — calls DAP_TPSettingsToGUI(device, entry = "amplitudeIC", fast = TP_FAST_CONFIG) directly. The previously introduced TP_ApplyAutoTPAmplitudeUpdate helper has been removed (no more code duplication).
if(needsUpdate)
    DAP_TPSettingsToGUI(device, entry = "amplitudeIC", fast = TP_FAST_CONFIG)
endif

The new TP_FAST_CONFIG enum value is the only new fast mode introduced; existing callers keep the previous behavior since TP_FAST_NONE = 0 matches the prior fast = 0 default and TP_FAST_NO_CONFIG = 1 matches the prior fast = 1 semantics. With the refactor, an Auto TP IC amplitude update now performs exactly one fast TP stop/restart with no AI_* amplifier calls.

Copilot AI requested review from Copilot and removed request for Copilot April 24, 2026 17:03
Copilot AI linked an issue Apr 24, 2026 that may be closed by this pull request
Copilot AI requested review from Copilot and removed request for Copilot April 24, 2026 17:09
Copilot AI changed the title [WIP] Skip amplifier calls during auto TP amplitude update TP: Skip amplifier calls during Auto TP amplitude update Apr 24, 2026
Copilot AI requested a review from timjarsky April 24, 2026 17:11
Comment thread Packages/MIES/MIES_TestPulse.ipf Outdated
PUB_TPSettingChange(device, headstage, "amplitudeIC", val, "mV")

if(IsFinite(TPState))
TP_RestartTestPulse(device, TPState, fast = 1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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_CheckSettingsDAP_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:

  1. Use fast = 0 on the restart (so DC_Configure rebuilds the DAQ wave correctly) and add an internal opt-out on the TP-start path to skip DAP_CheckSettings for this Auto-TP-only case (the check has already been performed when TP was originally started, and we're only rescaling the DAC).
  2. Introduce a narrower helper that just rebuilds the TP DAC wave (DC_FillDAQDataWaveForTP and its prerequisites) under a fast restart, without going through the full DC_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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot Let's try option 1 first to check functionality.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copilot AI requested review from Copilot and removed request for Copilot April 24, 2026 20:43
@timjarsky timjarsky assigned t-b and unassigned timjarsky Apr 25, 2026
@timjarsky

Copy link
Copy Markdown
Collaborator

Tested this PR on Rig 5

@t-b

t-b commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

I'll have a look. But unfortunately this is quite shitty code.

@t-b

t-b commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Review:

  • PR description should include a close statement
  • If you stop the TP with the fast option, you also need to start it again with fast. And if starting with fast is wrong, so is stopping.
  • TP_ApplyAutoTPAmplitudeUpdate: This duplicates a lot of code from DAP_TPGUISettingToWave. Instead of doing that we want to special case SetVar_DataAcq_TPAmplitudeIC in DAP_SetVarProc_TestPulseSett to pass skipCheckSettings to DAP_TPGUISettingToWave. Or even special case in DAP_TPGUISettingToWave.
  • All TP functions accepting both fast and skipCheckSettings need an assertion to verify that only one of them is set
  • The function comment for TP_ApplyAutoTPAmplitudeUpdate is too long and not helping
  • Boolean flags should be not negative if possible. So use checkSettings instead of skipCheckSettings.
  • No updating releasenotes.rst
  • It would make sense to promote the boolean fast flag to an enumeration. Because what we actually want to do is fast together with calling DC_Configure, DAP_CheckSettings is a red herring.
  • Missing test

@t-b t-b unassigned t-b and Copilot Apr 27, 2026
@timjarsky

Copy link
Copy Markdown
Collaborator

@copilot, switching to current clamp while the TP is running gives the following assertion:

  !!! Assertion FAILED !!!
  Message: "Control is not a setvariable"
  Please provide the following information if you contact the MIES developers:
  ################################
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Stacktrace:
  DAP_CheckProc_ClampMode(...)#L3307 [MIES_DAEphys.ipf]
DAP_ChangeHeadStageMode(...)#L3448 [MIES_DAEphys.ipf]
PGC_SetAndActivateControl(...)#L390 [MIES_ProgrammaticGUIControl.ipf]
DAP_SliderProc_MIESHeadStage(...)#L3704 [MIES_DAEphys.ipf]
DAP_TPSettingsToGUI(...)#L5795 [MIES_DAEphys.ipf]
SetSetVariable(...)#L304 [MIES_GuiUtilities.ipf]
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Time: 2026-05-04T10:29:12.667-07:00
  Locked device: [ITC1600_Dev_0]
  Current sweep: [NaN]
  DAQ: [DAQ_NOT_RUNNING]
  Testpulse: [TEST_PULSE_NOT_RUNNING]
  Acquisition state: [AS_INACTIVE]
  Fifo position: [0]
  Experiment: Untitled ()
  Igor Pro version: 10.1.2.30009 (30009)
  MIES version:
  Release_2.9_20250502-861-g5b455545e
Date and time of last commit: 2026-05-04T16:54:12Z
Submodule status: 
 5a898c7109ba9db4c5addce78496f31cf19f5967 Packages/IPNWB (v0.20-37-g5a898c7)
 5270cb8911ff888ae74f6d3ee2b7b0d49235f98b Packages/doc/doxygen-filter-ipf (remotes/origin/HEAD)
 995e48203398ad085f372c0ec6b9f7cbb2bb0362 Packages/igortest (heads/main-2-g995e482)
  ################################

The control in question is : Control = "check_DataAcq_AutoTP" (String)

It is a checkbox. You can tell because the name prefix says "check_"

Copilot AI requested review from Copilot and removed request for Copilot May 4, 2026 17:36

Copilot AI commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot, switching to current clamp while the TP is running gives the following assertion:

...

Fixed in 3788b24. The new DAP_TPSettingsToGUI loop was unconditionally calling SetSetVariable for every control in DAEPHYS_TP_CONTROLS_ALL, but that list contains checkboxes (Check_TP_SendToAllHS, check_DataAcq_AutoTP) too. The loop now dispatches on GetControlType and uses SetCheckBoxState for checkboxes. The previous PGC_SetAndActivateControl-based path handled this implicitly, which is why only the refactor was affected.

@timjarsky timjarsky assigned t-b and unassigned timjarsky May 4, 2026
@timjarsky

Copy link
Copy Markdown
Collaborator

I tested with two headstages, and it's working well.

@t-b

t-b commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Review:

  • No updating releasenotes.rst
  • As fast is now an enumeration this can't be checked with plain if(fast) (which currently only works because TP_FAST_NONE is 0). Use == instead. The general rule is that the enumeration values itself should not matter.
  • DAP_TPSettingsToGUI does not use PGC anymore, which is wrong. There is no harm in using PGC here as stopping/starting a stopped TP is quick. Then also DAP_ApplyTPSetting can be removed again.
  • The comments for fast are wrong: When non-zero, starts TP without any checks; We don't care about the numerical values, the constants should be used.

@timjarsky Feel free to assign it back to me so that I can make the changes directly.

@t-b t-b assigned timjarsky and unassigned t-b May 5, 2026
Comment thread Packages/doc/releasenotes.rst Outdated
- 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot, please do not update the release notes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted in 1d1b62b.

Copilot AI requested review from Copilot and removed request for Copilot May 6, 2026 17:04

Copilot AI commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

Review:

  • No updating releasenotes.rst
  • As fast is now an enumeration this can't be checked with plain if(fast) (which currently only works because TP_FAST_NONE is 0). Use == instead. The gen...

Addressed in 1d1b62b:

  • Reverted release notes changes.
  • Restored DAP_TPSettingsToGUI to use PGC_SetAndActivateControl (and DAP_TPGUISettingToWave to its original form). Removed DAP_ApplyTPSetting. Only addition is the optional fast parameter forwarded to the surrounding stop/restart.
  • Replaced if(fast) enum tests with explicit == TP_FAST_NO_CONFIG || == TP_FAST_CONFIG comparisons in TP_Setup, TPS_StartTestPulseSingleDevice, TPM_StartTestPulseMultiDevice.
  • Updated fast doc comments on TPS_StartTestPulseSingleDevice and TPM_StartTestPulseMultiDevice to reference the enum constants instead of "non-zero".

Copilot AI requested a review from timjarsky May 6, 2026 17:06
@timjarsky

timjarsky commented May 6, 2026

Copy link
Copy Markdown
Collaborator
  • DAP_TPSettingsToGUI does not use PGC anymore, which is wrong. There is no harm in using PGC here as stopping/starting a stopped TP is quick. Then also DAP_ApplyTPSetting can be removed again.

@t-b Doesn't starting or stopping a stopped TP induce calls to the MCC?

@t-b

t-b commented May 6, 2026

Copy link
Copy Markdown
Collaborator
  • DAP_TPSettingsToGUI does not use PGC anymore, which is wrong. There is no harm in using PGC here as stopping/starting a stopped TP is quick. Then also DAP_ApplyTPSetting can be removed again.

@t-b Doesn't starting or stopping a stopped TP induce calls to the MCC?

No.

@timjarsky

Copy link
Copy Markdown
Collaborator
  • DAP_TPSettingsToGUI does not use PGC anymore, which is wrong. There is no harm in using PGC here as stopping/starting a stopped TP is quick. Then also DAP_ApplyTPSetting can be removed again.

@t-b Doesn't starting or stopping a stopped TP induce calls to the MCC?

No.

@t-b AI_QueryGainsUnitsForClampMode() is getting called. Is that expected?

@t-b

t-b commented May 11, 2026

Copy link
Copy Markdown
Collaborator
  • DAP_TPSettingsToGUI does not use PGC anymore, which is wrong. There is no harm in using PGC here as stopping/starting a stopped TP is quick. Then also DAP_ApplyTPSetting can be removed again.

@t-b Doesn't starting or stopping a stopped TP induce calls to the MCC?

No.

@t-b AI_QueryGainsUnitsForClampMode() is getting called. Is that expected?

@timjarsky As mentioned in #2694 (comment) the special casing in DAP_TPSettingsToGUI to not use PGC for this particular control is missing.

Copilot AI requested review from Copilot and removed request for Copilot June 8, 2026 16:48
@t-b

t-b commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Review:

DAP_TPSettingsToGUI:

	if(fast == TP_FAST_NONE)
		TPState = TP_StopTestPulse(device)
	else
		TPState = TP_StopTestPulseFast(device)
	endif

This means we call TP_StopTestPulseFast for both TP_FAST_NO_CONFIG and TP_FAST_CONFIG. Which although looks a bit odd is correct.

What still needs fixing there are functions left which still use binary 0/1 fast:

$ git grep --show-function  '!!fast'
Packages/MIES/MIES_TestPulse.ipf=static Function TP_StopTestPulseWrapper(string device, [variable fast])
Packages/MIES/MIES_TestPulse.ipf:        fast = !!fast
Packages/MIES/MIES_TestPulse.ipf=Function TP_Teardown(string device, [variable fast])
Packages/MIES/MIES_TestPulse.ipf:        fast = !!fast
Packages/MIES/MIES_TestPulse_Multi.ipf=Function TPM_StopTestPulseMultiDevice(string device, [variable fast])
Packages/MIES/MIES_TestPulse_Multi.ipf:      fast = !!fast
Packages/MIES/MIES_TestPulse_Single.ipf=Function TPS_StopTestPulseSingleDevice(string device, [variable fast])
Packages/MIES/MIES_TestPulse_Single.ipf:     fast = !!fast

These should also be ported to the new TP_FAST_XXX flags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip Amplifier Calls During Auto TP Amplitude Update

4 participants