Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

Timelimit Parameter Not Working?

  • 1.  Timelimit Parameter Not Working?

    Posted Thu November 08, 2018 02:03 PM

    Originally posted by: JPRyan


    I have an Advanced Model that generally runs in well under a second for almost all inputs in my problem space but occasionally seems to take hours (or never finishes) for some random inputs.  I've been trying to figure out why this happens.  My plan was to set a timelimit and print the inputs to a file if CPlex breaks the timelimit.

     

    My function looks like

     

        mdl = AdvModel()

        mdl.parameters.optimalitytarget.set(3)

        mdl.parameters.timelimit.set(20)

     

        # Set up problem with piecewise linear, linear and convex terms

        # Set up parameter constraints and sum contraint

     

        log.info('Entering CPlex Solve')

        mdl.minimize(...)

        log.info('Exiting CPlex Solve')

     

       The last log I will see is "Entering CPlex Solve" and that 1/1000 tests that take forever will never trigger the timeout.   Have I set up the timeout incorrectly?  Is this a known issue?

       

    Python 2.6, Docplex 2.7.113, CPlex 12.8, Win 10

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Timelimit Parameter Not Working?

    Posted Fri November 09, 2018 04:51 AM

    I cannot reproduce this here (although I am using Python 2.7).

    In the code you posted there is no call to solve(). I suspect this happens between "Entering" and "Exiting"? Can you call solve with log_output=True. At the beginning of the engine log you should see all non-default parameter settings. Among those you should have a setting for CPXPARAM_TimeLimit.

    Can you also try with Python 2.7 or newer?


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Timelimit Parameter Not Working?

    Posted Fri November 09, 2018 12:08 PM

    Originally posted by: JPRyan


    You are correct there was a solve() in that block.

     

    I'll check the engine log for CPXPARAM_TimeLimit and try to get the log for a problem case.  Though that may take awhile as the problem is erratic.

     

      Thanks


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Timelimit Parameter Not Working?

    Posted Fri November 09, 2018 08:21 PM

    Originally posted by: JPRyan


    I can't move over to 2.7 yet as some of the inputs require libraries that only have 2.6 implementations.  Hopefully that will be resolved soon.

     

    The log_output shows:

    CPXPARAM_TimeLimit                               20

    so at least it is getting the parameter.  Thanks.

     

    If the call breaks this limit I'm using the below as a test but it doesn't seem to be triggered.

    if mdl.solve_details.has_hit_limit():

     

    My current plan is to use mdl.export_as_lp(...) to try to capture the inputs that are causing the slow down.

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Timelimit Parameter Not Working?

    Posted Mon November 12, 2018 03:25 AM

    With this output my best guess is that this is a bug deep inside CPLEX. Apparently CPLEX goes off into some subroutine that does not check time-limits. So yes, if you have any chance to provide an LP file with which the issue reproduces then this would be very helpful. By the way, in the cases in which the time-limit gets ignored, do you see any progress in the log or does it appear as if CPLEX is stuck?


    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Timelimit Parameter Not Working?

    Posted Tue November 13, 2018 01:26 PM

    Originally posted by: JPRyan


    So this problem has become more crazy and I'm pretty stuck.  Below is the core of the code I ran starting yesterday.  The last timestamp I had from datetime.now() was 6pm last night.   At 9am this morning it was still running and using about 20% of my CPU.

     

            mdl = AdvModel(...)

            # Other Parameters

            mdl.parameters.timelimit.set(20)

            # Build model

     

            mdl.minimize(self.clean_expr(...))

            print(datetime.now())

            mdl.parameters.export_prm_to_path(...)
            mdl.export_as_lp(path=r'...')
            self.solution = mdl.solve(log_output=verbose)

            print(human_time(mdl.solve_details.time))

     

    I attached the last parameter file and LP file in the directory also written at 6pm the night before.  So it doesn't appear to be a logging problem.

     

    The odd thing is when I load the problem using cpx = Cplex(...\bad_inputs.lp) the problem runs just fine in 0.01 seconds.

     

    It's worth mentioning that we discussed another problem recently.  I'm the person that had the MIQP that needed fix that you suggested some weeks back using the clean_expr.  This may be why the lp file has a odd structure.

     

        def clean_expr(expr)

            quadterms = dict()
            idxmap = dict()
            for v1, v2, a in expr.iter_quad_triplets():
                idxmap[v1._index] = v1
                idxmap[v2._index] = v2
                key = (min(v1._index, v2._index), max(v1._index, v2._index))
                quadterms[key] = quadterms.get(key, 0.0) + a
            lin = expr.linear_part  # includes the constant
            return lin + sum([idxmap[k[0]] * idxmap[k[1]] * quadterms[k] for k in sorted(quadterms)])

     

     A final note was there was >1000 slightly different problems that DocPlex handled always under 5 seconds and usually under 0.01 seconds before this problem MIQP.

         


    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Timelimit Parameter Not Working?

    Posted Tue November 13, 2018 04:23 PM

    Originally posted by: JPRyan


    A second set of failed inputs.


    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Timelimit Parameter Not Working?

    Posted Tue November 13, 2018 08:34 PM

    Originally posted by: JPRyan


    One more but this time I grabbed the logs from DocPlex.  It clearly stops about half way

     

    2018-11-13 16:15:38.878852
    CPXPARAM_Simplex_Tolerances_Optimality           9.9999999999999995e-08
    CPXPARAM_TimeLimit                               20
    CPXPARAM_Read_DataCheck                          1
    CPXPARAM_OptimalityTarget                        3
    CPXPARAM_MIP_Tolerances_AbsMIPGap                9.9999999999999995e-08
    CPXPARAM_MIP_Tolerances_MIPGap                   9.9999999999999995e-08
    Tried aggregator 2 times.
    MIQP Presolve eliminated 31 rows and 29 columns.
    Aggregator did 29 substitutions.
    Reduced MIQP has 59 rows, 90 columns, and 176 nonzeros.
    Reduced MIQP has 14 binaries, 0 generals, 15 SOSs, and 2 indicators.
    Reduced MIQP objective Q matrix has 196 nonzeros.
    Presolve time = 0.00 sec. (0.23 ticks)
    Probing fixed 0 vars, tightened 2 bounds.
    Probing time = 0.00 sec. (0.04 ticks)
    Tried aggregator 1 time.
    Reduced MIQP has 61 rows, 90 columns, and 180 nonzeros.
    Reduced MIQP has 14 binaries, 0 generals, 15 SOSs, and 0 indicators.
    Reduced MIQP objective Q matrix has 196 nonzeros.
    Presolve time = 0.00 sec. (0.10 ticks)
    Probing time = 0.00 sec. (0.04 ticks)
    MIP emphasis: balance optimality and feasibility.
    MIP search method: dynamic search.
    Parallel mode: deterministic, using up to 8 threads.
    Root relaxation solution time = 0.00 sec. (1.02 ticks)

            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

          0     0        0.0000     8                      0.0000       16         
    *     0+    0                            0.0000        0.0000             0.00%


    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Timelimit Parameter Not Working?

    Posted Wed November 14, 2018 05:01 AM

    The odd thing here is that the according to the log the problem is solved. So there should be nothing to do.

    In any case, your model has a lot of rather small numbers (around 1e-6). One reason things do not reproduce with the LP files may be that these numbers get truncated on output and then CPLEX ends up solving a slightly different model. If you are using a local solve and thus have a local CPLEX installation, then instead of export_as_lp() you can use export_as_sav(). That gives a binary file which is an exact representation of your model. Can you please try that?

    Also, depending on how familiar you are with debuggers, can you attach a debugger (not a Python debugger but something like gdb) to the running process and produce a backtrace? That may help getting to the bottom of things.


    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Timelimit Parameter Not Working?

    Posted Wed November 14, 2018 12:57 PM

    Originally posted by: JPRyan


    I attached the SAV file.  Unfortunately, I'm not really familiar with gdb.  I'll could put some time into figuring that out, but it'd have to be next week.  I tried lowering the tolerance a bit as you see below.  The natural scale for this problem has the answers in the 0-1 range and the cost function adding up 1e-6.  I can likely scale the costs up by 10000 if that would make the solver more comfortable, but it might be complicated operationally.

     

    CPXPARAM_Simplex_Tolerances_Optimality           1e-08
    CPXPARAM_TimeLimit                               20
    CPXPARAM_Read_DataCheck                          1
    CPXPARAM_OptimalityTarget                        3
    CPXPARAM_MIP_Tolerances_AbsMIPGap                1e-08
    CPXPARAM_MIP_Tolerances_MIPGap                   1e-08
    Tried aggregator 2 times.
    MIQP Presolve eliminated 31 rows and 29 columns.
    Aggregator did 29 substitutions.
    Reduced MIQP has 59 rows, 90 columns, and 176 nonzeros.
    Reduced MIQP has 14 binaries, 0 generals, 15 SOSs, and 2 indicators.
    Reduced MIQP objective Q matrix has 196 nonzeros.
    Presolve time = 0.00 sec. (0.23 ticks)
    Probing fixed 0 vars, tightened 2 bounds.
    Probing time = 0.00 sec. (0.04 ticks)
    Tried aggregator 1 time.
    Reduced MIQP has 61 rows, 90 columns, and 180 nonzeros.
    Reduced MIQP has 14 binaries, 0 generals, 15 SOSs, and 0 indicators.
    Reduced MIQP objective Q matrix has 196 nonzeros.
    Presolve time = 0.00 sec. (0.10 ticks)
    Probing time = 0.00 sec. (0.04 ticks)
    MIP emphasis: balance optimality and feasibility.
    MIP search method: dynamic search.
    Parallel mode: deterministic, using up to 8 threads.
    Root relaxation solution time = 0.00 sec. (0.98 ticks)

            Nodes                                         Cuts/
       Node  Left     Objective  IInf  Best Integer    Best Bound    ItCnt     Gap

          0     0        0.0000    12                      0.0000       14         
    *     0+    0                            0.0000        0.0000             0.00%


    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Timelimit Parameter Not Working?

    Posted Tue November 20, 2018 02:11 AM

    Sorry, I am still unable to reproduce the hang here. Would you be able to share your full code with daniel(dot)junglas(at)de(dot)ibm(dot)com? Maybe the issue is somewhere in the Python layer and one needs the whole code stack to reproduce.


    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Timelimit Parameter Not Working?

    Posted Fri November 30, 2018 01:25 PM

    Originally posted by: JPRyan


      Thanks Daniel.  I won't be able to share the full code and it is more complicated than I'd ask you to read anyway.

     

      Is there a way to turn off the multithreading in Python/DocPlex?  There seems to be a way in CPLEX, but I don't seem to be translating that correctly.   That is where I think the problem lies.  I have a complicated problem but only a 10-20 variables so I don't think it will slow the calculations down too much.

     

       Ryan


    #CPLEXOptimizers
    #DecisionOptimization


  • 13.  Re: Timelimit Parameter Not Working?

    Posted Fri November 30, 2018 01:37 PM

    You should be able to set the threads parameter to 1, like so:

    mdl.parameters.threads.set(1)
    

     

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 14.  Re: Timelimit Parameter Not Working?

    Posted Mon December 03, 2018 01:06 PM

    Originally posted by: JPRyan


    Turning off multithreading fixed the issue.  Thank you.


    #CPLEXOptimizers
    #DecisionOptimization