Skip to content

Conversation

@trlemon
Copy link
Contributor

@trlemon trlemon commented Jan 10, 2026

Background

Primary Issue

When using the Keithley3706A switch matrix in complex and long-running measurements, it may be the case that close_channels is called many times. When close_channels is 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 Keithley3706A instrument 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:

  1. Cache is updated when set_forbidden_channels() is called.
  2. If set_forbidden_channels() is called, update the local cache with the validated input.
  3. If 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 calling set_forbidden_channels().
  4. If clear_forbidden_channels() is called, update cache by calling get_forbidden_channels("allslots").

Summary of changes

  • Added variable to Keithley3706A to store forbidden channels
  • Added use_forbidden_channels_cache to class init.
  • Updated set, get, and clear forbidden channels logic to update/use the new cache variable when the cache is enabled.

Notes on changes

You might notice that get_forbidden_channels() has an extra argument to control logic flow while set_forbidden_channels() and clear_forbidden_channels() use use_forbidden_channels_cache to 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 the forbidden_channels_cache if use_forbidden_channels_cache is false.

@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

❌ Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.88%. Comparing base (043c9df) to head (3683656).

Files with missing lines Patch % Lines
...odes/instrument_drivers/Keithley/Keithley_3706A.py 30.76% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7771      +/-   ##
==========================================
- Coverage   59.89%   59.88%   -0.02%     
==========================================
  Files         352      352              
  Lines       31806    31817      +11     
==========================================
+ Hits        19051    19054       +3     
- Misses      12755    12763       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant