Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add facility to specify a default logger different from nothing #926

Open
1 task
ablaom opened this issue Aug 17, 2023 · 3 comments
Open
1 task

Add facility to specify a default logger different from nothing #926

ablaom opened this issue Aug 17, 2023 · 3 comments
Assignees

Comments

@ablaom
Copy link
Member

ablaom commented Aug 17, 2023

This could be provided as either part of #925 or as a follow-up PR.

The idea is to define a global variable DEFAULT_LOGGER and to make the default value of the logger keyword option in evaluate! equal to DEFAULT_LOGGER, rather than nothing. (And later, do the same for TunedModel and IteratedModel; see JuliaAI/MLJ.jl#1029.)

In __init__ the DEFAULT_LOGGER would be set to nothing but MLJBase will provide a public method default_logger to set and inspect the value. For example:

# inspecting:
julia> default_logger()
nothing

# changing:
using MLFlow
julia> default_logger(MLFlowLogger())
MLFlowLogger(MLFlow(
    baseuri = "http://127.0.0.1:5000", 
    apiversion = 2.0
), "MLJ experiment", nothing)

The required code can be modelled exactly on the DEFAULT_RESOURCE global variable (see src/init.jl) and the default_resource setter/getter (see src/MLJBase.jl).

To do after this integration:

  • Have MLJ re-export default_logger

@pebeto

@pebeto
Copy link
Member

pebeto commented Aug 28, 2023

Does this change replace our keyword argument in evaluate! and save?

@ablaom
Copy link
Member Author

ablaom commented Aug 28, 2023

Yes, everywhere we have a keyword argument logger=nothing , we need to change to logger=default_logger(). At present, that's just evaluate!.

In the case of MLJBase.save, there is nothing in MLJBase that connects save to logging. That happens only in MLJFlow.jl, where MLJBase.save(::MLFlowLogger, ::Machine) is overloaded. I suppose we could arrange that MLBase.save(mach) saves the machine to the default logger, ie, do something like this in MLJBase:

const ERR_INVALID_DEFAULT_LOGGER = ArgumentError(
    "`default_logger()` is currently `nothing`. Either specify an explicit path or stream as "
    "target of the save, or use `default_logger(logger)` to change the default logger. "
)
"""
    <new doc string>
"""
MLJBase.save(mach::Machine) = MLJBase(default_logger, mach)
MLJBase.save(::Nothing, ::Machine) = throw(ERR_INVALID_DEFAULT_LOGGER)

What do you think?

@pebeto
Copy link
Member

pebeto commented Aug 28, 2023

Awesome, how it could be used by MLJTuning and MLJIteration? Are we going to call to certain functions defined by us inside that packages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: priority low / straightforward
Development

No branches or pull requests

2 participants