Skip to content

Add @interruptable macro #554

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

sebastiendesignolle
Copy link
Collaborator

Works like a charm! Scoping was indeed a bit delicate...

In many cases, we could actually skip the extra iteration since everything is recomputed one last time, but there's a argument for that if needed (default to 1 currently).

@pokutta
Copy link
Member

pokutta commented Feb 19, 2025

very cool - and even better than we discussed with the number of final iterations adjustable. i think 1 is good for some algorithms. stupid question: upon ctrl-c is the "remainder" of the loop iteration still correctly executed? I assume yes? @sebastiendesignolle

@sebastiendesignolle
Copy link
Collaborator Author

Unfortunately no! The macro only has access to the body of the loop as a whole, so the breaking point is unknown. This may indeed lead to unexpected behaviours, but this is probably fine for testing, which is anyway the purpose of this feature.

Btw, I've just done a quick performance test and could not see any measurable drawback.

@pokutta
Copy link
Member

pokutta commented Feb 19, 2025

Unfortunately no! The macro only has access to the body of the loop as a whole, so the breaking point is unknown. This may indeed lead to unexpected behaviours, but this is probably fine for testing, which is anyway the purpose of this feature.

Btw, I've just done a quick performance test and could not see any measurable drawback.

let's discuss this soon - maybe there is a way to ensure that always "full" loops are executed.

@pokutta
Copy link
Member

pokutta commented Feb 19, 2025

from the logic it seems that the full loop is completed as you only change the variable interrupted via the exception

@sebastiendesignolle
Copy link
Collaborator Author

As discussed today, this feature is unfortunately not possible in Julia. Unlike languages with longjmp-style exception handling (like C's setjmp/longjmp or SEH in Windows), Julia's exceptions immediately unwind the stack to the nearest catch. This means that we have no way of going back to the code where the Ctrl-C raised the exception.

I've just added a warning, this is ready to merge for me.

@SetaR0202
Copy link
Collaborator

It seems that @interruptable macro is slowing done the code by adding allocations.

I've tested locally the @interruptable macro on the 159-add-ctrl-c branch (with macro) and on the master branch (without macro) with @btime from BenchmarkTools.jl over some examples from the examples folder.

  • docs_00_fw_visualized.jl
    • with macro: 453.887 ms (340386 allocations: 18.85 MiB)
    • without macro: 344.428 ms (274277 allocations: 14.67 MiB)
  • docs_04_rational_opt.jl
    • with macro: 1.129 s (1304290 allocations: 61.97 MiB)
    • without macro: 751.028 ms (1180819 allocations: 55.56 MiB)
  • docs_06_spectrahedron.jl
    • with macro: 4.272 s (459838 allocations: 329.59 MiB)
    • without macro: 4.010 s (364488 allocations: 324.34 MiB)
  • docs_07_shifted_norm_polytopes.jl
    • with macro: 651.116 ms (272223 allocations: 14.69 MiB)
    • without macro: 369.010 ms (201782 allocations: 10.51 MiB)
  • docs_08_callback_and_tracking.jl
    • with macro: 720.030 ms (423697 allocations: 23.35 MiB)
    • without macro: 429.394 ms (315637 allocations: 16.73 MiB)
  • docs_09_extra_vertex_storage.jl
    • with macro: 3.162 s (1786604 allocations: 99.26 MiB)
    • without macro: 1.777 s (1107891 allocations: 61.71 MiB)
  • docs_10_alternating_methods.jl
    • with macro: 1.737 s (4307555 allocations: 264.63 MiB)
    • without macro: 1.548 s (4094604 allocations: 252.96 MiB)
  • docs_11_block_coordinate_fw.jl
    • with macro: 5.188 s (15495988 allocations: 2.80 GiB)
    • without macro: 4.065 s (15049039 allocations: 2.77 GiB)

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.

add Ctrl-C handling to prematurely end solve (convenience feature)
3 participants