Add forbidden channel cache to Keithley3706a to improve performance #7771
+38
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
Primary Issue
When using the Keithley3706A switch matrix in complex and long-running measurements, it may be the case that
close_channelsis called many times. Whenclose_channelsis called,get_forbidden_channels()subsequently calls_validator()on the returned forbidden channels string. The_validator()makes multiple queries to the instrument which can eat up a lot of time.Proposed Solution
Since users may not require that the instrument is queried every single time to fetch the list of forbidden channels (especially if users are not setting any forbidden channels to begin with), I propose adding a forbidden channels cache variable to the
Keithley3706Ainstrument class. If the cache is enabled, then the cache will be returned instead of needing to query the instrument, thus saving time during measurements with many switching operations.To summarize the logic when using the forbidden channels cache:
set_forbidden_channels()is called.set_forbidden_channels()is called, update the local cache with the validated input.get_forbidden_channels()is called, check to see if using local cache. If using local cache, return local cache instead, which should already be validated from callingset_forbidden_channels().clear_forbidden_channels()is called, update cache by callingget_forbidden_channels("allslots").Summary of changes
Keithley3706Ato store forbidden channelsuse_forbidden_channels_cacheto class init.Notes on changes
You might notice that
get_forbidden_channels()has an extra argument to control logic flow whileset_forbidden_channels()andclear_forbidden_channels()useuse_forbidden_channels_cacheto control logic flow. This is because we want to preserve the ability to get forbidden channels from the instrument by default but never want to update theforbidden_channels_cacheifuse_forbidden_channels_cacheis false.