-
Notifications
You must be signed in to change notification settings - Fork 320
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
Trmorgan/keyboard interrupt #6192
Merged
jenshnielsen
merged 17 commits into
microsoft:main
from
trevormorgan:trmorgan/keyboard-interrupt
Jul 4, 2024
Merged
Trmorgan/keyboard interrupt #6192
jenshnielsen
merged 17 commits into
microsoft:main
from
trevormorgan:trmorgan/keyboard-interrupt
Jul 4, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…atch_interrupts` function. # Aider chat conversation: USER: check the keyboard interupt code for being able to abort a loop of dond sweeps. Create unit tests with pytest to validate this function ASSISTANT: To validate the keyboard interrupt functionality for aborting a loop of `dond` sweeps, we need to: 1. Ensure the existing code properly handles keyboard interrupts. 2. Create unit tests using `pytest` to validate this functionality. First, let's review the existing code for handling keyboard interrupts in `src\qcodes\dataset\dond\do_nd_utils.py`. Next, we'll create a new test file `tests\dataset\dond\test_interrupts.py` to validate the interrupt functionality. Here are the changes: ### Review and Ensure Keyboard Interrupt Handling src\qcodes\dataset\dond\do_nd_utils.py ```python <<<<<<< SEARCH @contextmanager def catch_interrupts() -> Iterator[Callable[[], MeasInterruptT | None]]: interrupt_exception: MeasInterruptT | None = None def get_interrupt_exception() -> MeasInterruptT | None: nonlocal interrupt_exception return interrupt_exception try: yield get_interrupt_exception except (KeyboardInterrupt, BreakConditionInterrupt) as e: interrupt_exception = e raise ======= @contextmanager def catch_interrupts() -> Iterator[Callable[[], MeasInterruptT | None]]: interrupt_exception: MeasInterruptT | None = None def get_interrupt_exception() -> MeasInterruptT | None: nonlocal interrupt_exception return interrupt_exception try: yield get_interrupt_exception except (KeyboardInterrupt, BreakConditionInterrupt) as e: interrupt_exception = e raise >>>>>>> REPLACE ``` ### Create Unit Tests tests\dataset\dond\test_interrupts.py ```python <<<<<<< SEARCH ======= import pytest from qcodes.dataset.dond.do_nd_utils import catch_interrupts, BreakConditionInterrupt def test_keyboard_interrupt_handling(): with pytest.raises(KeyboardInterrupt): with catch_interrupts() as get_interrupt_exception: raise KeyboardInterrupt assert isinstance(get_interrupt_exception(), KeyboardInterrupt) def test_break_condition_interrupt_handling(): with pytest.raises(BreakConditionInterrupt): with catch_interrupts() as get_interrupt_exception: raise BreakConditionInterrupt assert isinstance(get_interrupt_exception(), BreakConditionInterrupt) def test_no_interrupt_handling(): with catch_interrupts() as get_interrupt_exception: pass assert get_interrupt_exception() is None >>>>>>> REPLACE ``` These changes ensure that the keyboard interrupt handling is properly validated with unit tests.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #6192 +/- ##
=======================================
Coverage 67.17% 67.18%
=======================================
Files 352 352
Lines 32132 32140 +8
=======================================
+ Hits 21586 21594 +8
Misses 10546 10546 ☔ View full report in Codecov by Sentry. |
…gan/keyboard-interrupt
jenshnielsen
approved these changes
Jul 4, 2024
jenshnielsen
added a commit
to jenshnielsen/Qcodes
that referenced
this pull request
Jul 4, 2024
…-interrupt Trmorgan/keyboard interrupt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Improved Interrupt Handling in dond Function
Description
This PR enhances the interrupt handling capabilities of the
dond
function in the QCoDeS dataset module. It addresses issues with the current implementation ofcatch_interrupts
and ensures that keyboard interrupts are properly propagated and handled during measurement sweeps.New
KeyboardInterrupt
is properly raised and propagated through thedond
functionTesting
The updated test now correctly simulates a
KeyboardInterrupt
within thedond
function and verifies that it's propagated as expected. This change improves our ability to test and ensure robust interrupt handling in complex measurement scenarios.Impact
These changes improve the reliability of measurements that use the
dond
function, particularly in situations where users might need to interrupt long-running sweeps. It ensures that the system responds appropriately to keyboard interrupts, possible saving time due to prior option being complete abortAdditional Notes
dond
function itself, only to its testing infrastructure