Enforce time limit

Back

Hey,

    I use a very vanilla ML pipeline. I use the train function made available and its working well. My training function is iterative and thus can be interrupted at any point in time: How can I monitor time used to make sure that I don't overrun the 10min time limit?

Here is the Train call:

self.Train(self.DateRules.Every(DayOfWeek.Sunday), self.TimeRules.At(8 , 0), self.train)

The train function:

def train(self):
        keep_training = 1

       while keep_training:
            #Train function call
            #...
           #check time spent ??? How???
           #Update keep_training

I tried with a straightforward datetime delta but it doesn't seem to work:

def train(self):
        start_time = datetime.now()
        keep_training = 1

       while keep_training:
            #Train function call
            #...
           #time delta
           train_time = datetime.now() - start_time
           #Update keep_training
           if train_time >= datetime.delta(minutes=9):
                keep_training = 0

 

 

Thank you for any pointers or suggestions!

 

Update Backtest







 
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


 

Hi Louis,

You can use the self.Train method to train your model. Within self.Train, the normal 10 minute time limit is increased with time taken from a 30 minute "reservoir", allowing you more time to train your models. You can learn more about training ML models in the documentation.

Best
Rahul

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Thank you Rahul,

I am using the train method (great feature btw, thanks) and it's very practical. Is there a way to monitor time use by a function? Be it train or another function to ensure that they do not pass whatever time limit I want to put on them?

 

Best,

 

Louis

0

Hi Louis Gobin,

We can limit the duration of a function’s execution by returning from the function after a specified time interval has passed. The code below will return to the caller after it has been executing for at least `self.max_train_seconds`.

def train(self):
start_time = datetime.now() # Current time
    while True:
        # Train function call...
            
        # Stop looping if reached maximum training duration
        if (datetime.now() - start_time).seconds >= self.max_train_seconds:
            break

This function can be adjusted to apply a threshold based on minutes by replacing the seconds attribute with minutes. Note that if we want the function to take no longer than 10 minutes, we should place the threshold just below 10 minutes as the break condition checks whether the max train duration has been reached.

See the attached backtest for a full working example.

1

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed