HiGHS icon indicating copy to clipboard operation
HiGHS copied to clipboard

User callback interrupt (HighsCallbackDataIn%user_interrupt, Fortran syntax) does not seem to work for release 1.7.0

Open jeffreydeankelly2 opened this issue 1 year ago • 6 comments

Installed version 1.7.0.

Everything works great for our set of MIP problems but when the user callback sets the HighsCallbackDataIn data structure item user_interrupt to some non-zero value after a user interrupt event (Control-C), HiGHS does not terminate. It keeps going without gracefully exiting.

When we print/write the HighsCallbackDataIn%user_interrupt value (Fortran syntax) before the interrupt event, its value is zero (0) and after the event the value of HighsCallbackDataIn%user_interrupt is set to one (1).

On subsequent calls to the user callback the value of HighsCallbackDataIn%user_interrupt = 1 as expected but there is no graceful termination.

jeffreydeankelly2 avatar Mar 09 '24 14:03 jeffreydeankelly2

Not all callback permit an interrupt.

Which one are you setting to be "on"?

jajhall avatar Mar 09 '24 22:03 jajhall

It is your MIP improving solution i.e., kHighsCallbackMipImprovingSolution

Should it be kHighsCallbackLogging?

On Sat, Mar 9, 2024 at 5:28 PM Julian Hall @.***> wrote:

Not all callback permit an interrupt.

Which one are you setting to be "on"?

— Reply to this email directly, view it on GitHub https://github.com/ERGO-Code/HiGHS/issues/1660#issuecomment-1986996951, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHONEAYBTS3VQRIUEZR5XTYXOEHDAVCNFSM6AAAAABEOE2N22VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBWHE4TMOJVGE . You are receiving this because you authored the thread.Message ID: @.***>

--


I M P L - " M a k i n g O p t i m i z a t i o n a n d E s t i m i z a t i o n S m a r t e r"

Jeffrey D. Kelly Industrial Algorithms Limited - i n d u s t r i @ l g o r i t h m s Email: @.*** Phone: (647) 917-4675 (IMPL) Making Industrial AI (Algorithms & Integration) Real!


This email and any files transmitted with it are confidential, proprietary and intended solely for the individual or entity to whom they are addressed. If you have received this email in error please delete it immediately.

jeffreydeankelly2 avatar Mar 09 '24 22:03 jeffreydeankelly2

kHighsCallbackMipImprovingSolution doesn't allow an interrupt: if you set HighsCallbackDataIn%user_interrupt value then it is ignored. Note that the improving solution callback may not be called often, so it's not a great source of interrupt. It could be argued that it should still be a point where an interrupt can be forced, though...

We need to document which callbacks permit interrupt

You need kCallbackMipInterrupt. This is called frequently

jajhall avatar Mar 10 '24 23:03 jajhall

Thank you, however, I implemented the three callback types as below but it seems that the kHighsCallbackMipInterrupt does not gracefully terminate HIGHS as expected.

        rtnstat = Highs_setCallback(problem1_ptr,HIGHSintsolcb,PNULL)

        rtnstat =

Highs_startCallback(problem1_ptr,kHighsCallbackMipImprovingSolution) rtnstat = Highs_startCallback(problem1_ptr,kHighsCallbackMipInterrupt) rtnstat = Highs_startCallback(problem1_ptr,kHighsCallbackLogging)

Inside our user HIGHSintsolcb() user callback routine the logging statement HIGHS CALLBACK_TYPE reports your callback_type and the HIGHS USER_INTERRUPT reports the value of your HighsCallbackDataIn%user_interrupt (Fortran syntax).

As you will notice in the sample log output below, when* HIGHS USER_INTERRUPT* goes from zero (0) to one (1), there is no gracefully termination of HIGHS as it reports another integer-feasible solution after the USER_INTERRUPT = 1 (non-zero).

The STAYED statement reports the event where CONTROL-C is encountered and the STOPPED statement indicates when our STOP file indicates to the user callback HIGHintsolcb() that the user requests to exit, quit or terminate the third-party solver i.e., HIGHS before the usualMIP gap being satisfied.

Running HiGHS 1.7.0 (git hash: 50670fd4c): Copyright (c) 2024 HiGHS under MIT licence terms Cols: 2 lower bounds less than or equal to -1e+20 are treated as -Infinity Cols: 2 upper bounds greater than or equal to 1e+20 are treated as +Infinity Rows: 25170 lower bounds less than or equal to -1e+20 are treated as -Infinity SOLVE HIGHS CALLBACK_TYPE = 0 Coefficient ranges: HIGHS CALLBACK_TYPE = 0 Matrix [1e-04, 2e+04] HIGHS CALLBACK_TYPE = 0 Cost [1e+00, 1e+00] HIGHS CALLBACK_TYPE = 0 Bound [5e-01, 1e+04] HIGHS CALLBACK_TYPE = 0 RHS [1e+00, 2e+04] HIGHS CALLBACK_TYPE = 0 Presolving model HIGHS CALLBACK_TYPE = 0 27851 rows, 10067 cols, 306660 nonzeros 0s HIGHS CALLBACK_TYPE = 0 19582 rows, 9529 cols, 288351 nonzeros 0s HIGHS CALLBACK_TYPE = 0 15293 rows, 7648 cols, 280708 nonzeros 0s HIGHS CALLBACK_TYPE = 0 8664 rows, 4996 cols, 266757 nonzeros 0s HIGHS CALLBACK_TYPE = 0 5110 rows, 3159 cols, 68726 nonzeros 6s HIGHS CALLBACK_TYPE = 0 4628 rows, 2358 cols, 63406 nonzeros 12s HIGHS CALLBACK_TYPE = 0 4544 rows, 2312 cols, 62621 nonzeros 14s HIGHS CALLBACK_TYPE = 0

Solving MIP model with: 4544 rows 2312 cols (606 binary, 0 integer, 716 implied int., 990 continuous) 62621 nonzeros HIGHS CALLBACK_TYPE = 0

HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1576166.666667 -inf inf 0 0 0 0 14.6s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1083632.247809 -inf inf 0 0 3 2097 15.0s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1081852.823038 -inf inf 4438 309 628 2864 20.1s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1079725.973032 -inf inf 6244 396 820 11811 28.4s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1079725.973032 -inf inf 6244 226 1063 13791 34.1s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0

0.3% inactive integer columns, restarting HIGHS CALLBACK_TYPE = 0 Model after restart has 3893 rows, 2246 cols (595 bin., 0 int., 702 impl., 949 cont.), and 55693 nonzeros HIGHS CALLBACK_TYPE = 0

HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1079725.973032 -inf inf 224 0 0 13791 34.9s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1079725.973032 -inf inf 224 207 4 14529 35.1s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1079610.375024 -inf inf 1907 387 559 14838 40.3s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 3 impl> Logistics-Feasible Solution # 1 Found with Objective Function = 0.9318500000E+006 SOLUTIONSPOT1 HIGHS CALLBACK_TYPE = 0 L 0 0 0 0.00% 1079610.375024 931850 15.86% 1910 388 563 14839 42.0s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0

7.1% inactive integer columns, restarting HIGHS CALLBACK_TYPE = 3 impl> Logistics-Feasible Solution # 2 Found with Objective Function = 0.9318500000E+006 SOLUTIONSPOT2 HIGHS CALLBACK_TYPE = 0 Model after restart has 3485 rows, 1991 cols (510 bin., 0 int., 657 impl., 824 cont.), and 49037 nonzeros HIGHS CALLBACK_TYPE = 0

HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1079610.375024 931850 15.86% 198 0 0 15400 45.6s HIGHS CALLBACK_TYPE = 5 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1076213.616742 931850 15.49% 198 142 8 16229 45.8s HIGHS CALLBACK_TYPE = 5 STAYED HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1062445.107767 931850 14.01% 5991 215 10 18246 51.3s HIGHS CALLBACK_TYPE = 5 STOPPED

  • HIGHS USER_INTERRUPT = 0* HIGHS CALLBACK_TYPE = 0

4.1% inactive integer columns, restarting HIGHS CALLBACK_TYPE = 3 impl> Logistics-Feasible Solution # 3 Found with Objective Function = 0.9318500000E+006 SOLUTIONSPOT3 HIGHS CALLBACK_TYPE = 0 Model after restart has 3255 rows, 1868 cols (482 bin., 0 int., 641 impl., 745 cont.), and 45487 nonzeros HIGHS CALLBACK_TYPE = 0

HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1062445.107767 931850 14.01% 207 0 0 18246 54.2s

HIGHS CALLBACK_TYPE = 5STOPPED HIGHS USER_INTERRUPT = 1 HIGHS CALLBACK_TYPE = 0 0 0 0 0.00% 1062445.107767 931850 14.01% 207 190 4 19038 54.4s HIGHS CALLBACK_TYPE = 5 STOPPED

  • HIGHS USER_INTERRUPT = 1* HIGHS CALLBACK_TYPE = 0 2 0 1 50.00% 1061345.221622 931850 13.90% 1199 208 942 37407 65.3s HIGHS CALLBACK_TYPE = 5 STOPPED
  • HIGHS USER_INTERRUPT = 1* HIGHS CALLBACK_TYPE = 3 impl> Logistics-Feasible Solution # 4 Found with Objective Function = 0.9370000000E+006 SOLUTIONSPOT4 HIGHS CALLBACK_TYPE = 0 T 2 0 1 50.00% 1061345.221622 937000 13.27% 1203 208 995 37407 65.9s HIGHS CALLBACK_TYPE = 5 STOPPED
  • HIGHS USER_INTERRUPT = 1* HIGHS CALLBACK_TYPE = 0

HIGHS CALLBACK_TYPE = 0

HIGHS CALLBACK_TYPE = 0

On Sun, Mar 10, 2024 at 7:46 PM Julian Hall @.***> wrote:

kHighsCallbackMipImprovingSolution doesn't allow an interrupt: if you set HighsCallbackDataIn%user_interrupt value then it is ignored. Note that the improving solution callback may not be called often, so it's not a great source of interrupt. It could be argued that it should still be a point where an interrupt can be forced, though...

You need kCallbackMipInterrupt. This is called frequently

— Reply to this email directly, view it on GitHub https://github.com/ERGO-Code/HiGHS/issues/1660#issuecomment-1987415659, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHONEEIKFD5OXPCF4NZGJDYXTWEJAVCNFSM6AAAAABEOE2N22VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBXGQYTKNRVHE . You are receiving this because you authored the thread.Message ID: @.***>

--


I M P L - " M a k i n g O p t i m i z a t i o n a n d E s t i m i z a t i o n S m a r t e r"

Jeffrey D. Kelly Industrial Algorithms Limited - i n d u s t r i @ l g o r i t h m s Email: @.*** Phone: (647) 917-4675 (IMPL) Making Industrial AI (Algorithms & Integration) Real!


This email and any files transmitted with it are confidential, proprietary and intended solely for the individual or entity to whom they are addressed. If you have received this email in error please delete it immediately.

jeffreydeankelly2 avatar Mar 11 '24 12:03 jeffreydeankelly2

Since we have a C++ unit test for this interrupt,

TEST_CASE("highs-callback-mip-interrupt", "[highs-callback]") {

I'm wondering whether there's a problem when using the callback from Fortran - and possibly C

I'll investigate, but I can't do it for a few days, as I've got teaching issues to address

jajhall avatar Mar 11 '24 12:03 jajhall

No rush - thank you for re-opening.

On Mon, Mar 11, 2024 at 8:42 AM Julian Hall @.***> wrote:

Since we have a C++ unit test for this interrupt,

TEST_CASE("highs-callback-mip-interrupt", "[highs-callback]") {

I'm wondering whether there's a problem when using the callback from Fortran - and possibly C

I'll investigate, but I can't do it for a few days, as I've got teaching issues to address

— Reply to this email directly, view it on GitHub https://github.com/ERGO-Code/HiGHS/issues/1660#issuecomment-1988354019, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALHONEAEWDHSR2L67P4QEK3YXWREXAVCNFSM6AAAAABEOE2N22VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBYGM2TIMBRHE . You are receiving this because you authored the thread.Message ID: @.***>

--


I M P L - " M a k i n g O p t i m i z a t i o n a n d E s t i m i z a t i o n S m a r t e r"

Jeffrey D. Kelly Industrial Algorithms Limited - i n d u s t r i @ l g o r i t h m s Email: @.*** Phone: (647) 917-4675 (IMPL) Making Industrial AI (Algorithms & Integration) Real!


This email and any files transmitted with it are confidential, proprietary and intended solely for the individual or entity to whom they are addressed. If you have received this email in error please delete it immediately.

jeffreydeankelly2 avatar Mar 11 '24 12:03 jeffreydeankelly2