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.

Pass arguments to callback

See original GitHub issue

I would like to be able to give heavy objects computed in optimize(trial) as parameters to the callback(study, trial).

Motivation

I want to save predictions when I have an improvement, that is when study.best_trial.number == trial.number.

Description

My optimize(trial) function performs cross-validation, and I would like to be able to reuse the fitted estimators to make my predictions.

The models are too heavy to be stored in trial.user_attrs.

Propositions

I think there are 2 options:

  • provide a field callback_data in FrozenTrial that can be set from objective(trial) with trial.set_callback_data(value) or trial.set_callback_data(key, value)

  • allow objective(trial) to return more complex values, e.g. through an object Result(value, *args, **kwargs) that is then used on callback(study, trial, *args, **kwargs)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nlgrangercommented, Jan 22, 2020

Yes. Contrary to a lambda function, the output of partial is picklable if its arguments are (the function is importable and the arguments are pickable) so I believe it should work. If I understand you problem correctly, I don’t think the arguments will be sent to the process anyway in this case, they will just be there in memory after forking the main process.

1reaction
nlgrangercommented, Jan 8, 2020

FYI functools.partial might be a simpler and more idiomatic solution as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript: Passing parameters to a callback function
When you have a callback that will be called by something other than your code with a specific number of params and ...
Read more >
JavaScript | Passing parameters to a callback function
Callback Function: Passing a function to another function or passing a function inside another function is known as a Callback Function.
Read more >
Passing arguments to callback functions - Js Tips
By default you cannot pass arguments to a callback function. For example: function callback() { console.log( ...
Read more >
Callback Function Javascript
A JavaScript Callback is a function passed as an argument to another function. In the above example, we passed in as an argument...
Read more >
How to pass a Variable or Argument to a callback function in ...
The assignment is simple. Search user with the name given, update the address of the user and print the user details after the...
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