Skip to content

nan handling in trial.report and multi-objective study. #2169

@ytsmiling

Description

@ytsmiling

Expected behavior

  • trial.report() accepts nan
  • Return value of multi-objective study accepts nan
  • Multi-objective study mark trials as FAILED when one or more return values are nan.

Bugs

  1. trial.report fails when the value is nan when combined with MySQL backend.
  2. Multi-objective trial also fails on report with nan value when combined with MySQL backend.
  3. Multi-objective study internally depends on trial.report and thus error occurs when one or more return value is nan.
  4. With in-memory db, multi-objective study registers trials with nan return value as COMPLETED trial.

Notes

I think whether trial.report should accept nan or not requires discussion.

Environment

  • Optuna version: 2.3.0
  • Python version: 3.8
  • OS: macOS Catalina
  • PyMySQL version: 0.10.1

Error messages, stack traces, or logs

(When called trial.report with nan value w/ MySQL backend.)

ProgrammingError: (pymysql.err.ProgrammingError) nan can not be used with MySQL
[SQL: INSERT INTO trial_values (trial_id, step, value) VALUES (%(trial_id)s, %(step)s, %(value)s)]
[parameters: {'trial_id': 34849, 'step': 1, 'value': nan}]
(Background on this error at: http://sqlalche.me/e/13/f405)

Steps to reproduce

  1. trial.report(float(np.nan), 1)

Additional context (optional)

Single-objective study accepts nan as the return value and marks it as failed. This is achieved in the following.

if value is not None and math.isnan(value):

With in-memory db, trial.report accepts nan.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue/PR about behavior that is broken. Not for typos/examples/CI/test but for Optuna itself.no-staleExempt from stale botoptuna.studyRelated to the `optuna.study` submodule. This is automatically labeled by github-actions.optuna.trialRelated to the `optuna.trial` submodule. This is automatically labeled by github-actions.v3Issue/PR for Optuna version 3.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions