question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I cannot see how to do this in asimple way withot subclassing your whole framework:

I want to write a message lets say every 1 hour to a file if my study is running.

start = time.time()
start_data= datetime.now()

def objective(trial):

  print("MULTIPLE OF 1 MIN: ", (time.time() - start) // 60)

  if (time.time() - start) // 60 == 1:
    print("1 MIN OVERb Since")
    print(start_data)
    start = time.time()
    start_data= datetime.now()

    ....
    
   return score


study = optuna.create_study(direction="maximize")
study.optimize(objective, n_trials=300, timeout=None)

But since start is outside the function it is unknown inside the trials…

UnboundLocalError: local variable 'start' referenced before assignment How can I handover a start time to measure how much time is elapsed? I just can start the time each trial…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
nzw0301commented, Mar 16, 2021

I think the simplest way to define your own objective as in this page. The objective stores the start_time and checks your condition in each call.

So how about this?

import time
from datetime import datetime

import optuna


class Objective(object):
    def __init__(self, min_x, max_x):
        self.min_x = min_x
        self.max_x = max_x
        self.start_time = time.time()

    def __call__(self, trial):
        time.sleep(0.5)  # for this example

        # Calculate an objective value by using the extra arguments.
        x = trial.suggest_uniform("x", self.min_x, self.max_x)

        current_time = time.time()

        if current_time - self.start_time >= 1.0:  # check the evaluation takes more than 1 second since ether the last message or the initialisation
            print("1 MIN OVER Since", self.start_time)
            self.start_time = current_time

        return (x - 2) ** 2


study = optuna.create_study(direction="maximize")
study.optimize(Objective(-1., 1.), n_trials=10, timeout=None)
0reactions
nzw0301commented, Apr 11, 2021

Please feel free to re-open the issue if the question was not solved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling time & estimated delivery dates | Seller Center - eBay
Handling time is the number of business days between when you receive payment for an item and when your package is scanned by...
Read more >
Maximum handling time [max_handling_time], minimum ...
Maximum and minimum handling time are the longest and shortest amounts of time between when an order is placed and when the product...
Read more >
Handling times - General Selling on Amazon Questions
Amazon generates handling time recommendations for products where there is a gap between your configured handling time, your actual handling ...
Read more >
What's Average Handle Time, & How Do You Cut It in Half (Or ...
Average handle time (AHT) is a metric that measures the average amount of time needed to resolve a support or service request. This...
Read more >
Processing Times - USCIS Case Status
Check Case Processing Times. Select your form, form category, and the office that is processing your case. Refer to your receipt notice to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found