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.

AttributeError is raised when using RDB storage.

See original GitHub issue

Reproducible examples (optional)

import optuna

# Define a simple 2-dimensional objective function whose minimum value is -1 when (x, y) = (0, -1).
def objective(trial):
    x = trial.suggest_uniform('x', -100, 100)
    y = trial.suggest_categorical('y', [-1, 0, 1])
    return x**2 + y


if __name__ == '__main__':
    # Let us minimize the objective function above.
    print('Running 10 trials...')
    study = optuna.create_study(storage="sqlite:///db.sqlite3")
    study.optimize(objective, n_trials=10)
    print('Best value: {} (params: {})\n'.format(study.best_value, study.best_params))

Expected behavior

tag: v1.1.0

$ git co v1.1.0
$ python examples/quadratic_simple.py 
Running 10 trials...
[I 2020-02-18 14:05:57,875] A new study created with name: no-name-a2889f9d-79d7-40cc-aff4-f4021183b6aa
[I 2020-02-18 14:05:57,977] Finished trial#0 resulted in value: 78.25382960871015. Current best value is 78.25382960871015 with parameters: {'x': -8.78941577175128, 'y': 1}.
[I 2020-02-18 14:05:58,067] Finished trial#1 resulted in value: 1601.2080527969047. Current best value is 78.25382960871015 with parameters: {'x': -8.78941577175128, 'y': 1}.
[I 2020-02-18 14:05:58,159] Finished trial#2 resulted in value: 155.3355136572432. Current best value is 78.25382960871015 with parameters: {'x': -8.78941577175128, 'y': 1}.
[I 2020-02-18 14:05:58,252] Finished trial#3 resulted in value: 4928.445801453334. Current best value is 78.25382960871015 with parameters: {'x': -8.78941577175128, 'y': 1}.
[I 2020-02-18 14:05:58,349] Finished trial#4 resulted in value: 5494.046052713425. Current best value is 78.25382960871015 with parameters: {'x': -8.78941577175128, 'y': 1}.
[I 2020-02-18 14:05:58,451] Finished trial#5 resulted in value: 7.806334896764313. Current best value is 7.806334896764313 with parameters: {'x': -2.793981907021646, 'y': 0}.
[I 2020-02-18 14:05:58,540] Finished trial#6 resulted in value: 3581.7294062867. Current best value is 7.806334896764313 with parameters: {'x': -2.793981907021646, 'y': 0}.
[I 2020-02-18 14:05:58,633] Finished trial#7 resulted in value: 6157.892248662727. Current best value is 7.806334896764313 with parameters: {'x': -2.793981907021646, 'y': 0}.
[I 2020-02-18 14:05:58,729] Finished trial#8 resulted in value: 538.9770074142994. Current best value is 7.806334896764313 with parameters: {'x': -2.793981907021646, 'y': 0}.
[I 2020-02-18 14:05:58,824] Finished trial#9 resulted in value: 2453.3913002520094. Current best value is 7.806334896764313 with parameters: {'x': -2.793981907021646, 'y': 0}.
Best value: 7.806334896764313 (params: {'x': -2.793981907021646, 'y': 0})

Error log

rev: 7344ee0f

$ git co master
$ rm db.sqlite3 | true && python examples/quadratic_simple.py 
Running 10 trials...
[I 2020-02-18 14:06:51,506] A new study created with name: no-name-32a1bb2f-64c7-4faa-8834-0bbdbaff508b
[I 2020-02-18 14:06:51,635] Finished trial#0 resulted in value: 2420.888780807176. Current best value is 2420.888780807176 with parameters: {'x': -49.192365066208964, 'y': 1}.
[I 2020-02-18 14:06:51,746] Finished trial#1 resulted in value: 145.24171551709355. Current best value is 145.24171551709355 with parameters: {'x': 12.093044096384233, 'y': -1}.
[I 2020-02-18 14:06:51,857] Finished trial#2 resulted in value: 1.014598248626613. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:51,957] Finished trial#3 resulted in value: 8577.24930691218. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:52,068] Finished trial#4 resulted in value: 8417.027436775961. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:52,181] Finished trial#5 resulted in value: 319.0475577707139. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:52,288] Finished trial#6 resulted in value: 4.4949007058993296. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:52,391] Finished trial#7 resulted in value: 2865.4595762936938. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:52,500] Finished trial#8 resulted in value: 2027.0173870485705. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
[I 2020-02-18 14:06:52,605] Finished trial#9 resulted in value: 7283.744078340451. Current best value is 1.014598248626613 with parameters: {'x': -0.12082321228395188, 'y': 1}.
Best value: 1.014598248626613 (params: {'x': -0.12082321228395188, 'y': 1})

Exception ignored in: <function RDBStorage.__del__ at 0x130bd7ca0>
Traceback (most recent call last):
  File "/Users/a14737/src/github.com/pfnet/optuna/optuna/storages/rdb/storage.py", line 943, in __del__
  File "/Users/a14737/src/github.com/pfnet/optuna/optuna/storages/rdb/storage.py", line 932, in remove_session
  File "/Users/a14737/src/github.com/pfnet/optuna/venv/lib/python3.8/site-packages/SQLAlchemy-1.3.12-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/orm/scoping.py", line 94, in remove
  File "/Users/a14737/src/github.com/pfnet/optuna/venv/lib/python3.8/site-packages/SQLAlchemy-1.3.12-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/orm/session.py", line 1298, in close
  File "/Users/a14737/src/github.com/pfnet/optuna/venv/lib/python3.8/site-packages/SQLAlchemy-1.3.12-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/orm/session.py", line 1334, in _close_impl
  File "/Users/a14737/src/github.com/pfnet/optuna/venv/lib/python3.8/site-packages/SQLAlchemy-1.3.12-py3.8-macosx-10.15-x86_64.egg/sqlalchemy/orm/session.py", line 1352, in expunge_all
AttributeError: 'NoneType' object has no attribute 'InstanceState'

Environment

  • Optuna version: 1.2.0 (master branch, rev: 7344ee0f).
  • Python version: 3.8.1
  • OS: macOS
  • (Optional) Other libraries and their versions:

Steps to reproduce

  1. Optimize with RDB storage backend.

Additional context (optional)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
toshihikoyanasecommented, Feb 18, 2020

I failed to reproduce this problem when I used docker as follows:

938.py

import optuna

# Define a simple 2-dimensional objective function whose minimum value is -1 when (x, y) = (0, -1).
def objective(trial):
    x = trial.suggest_uniform('x', -100, 100)
    y = trial.suggest_categorical('y', [-1, 0, 1])
    return x**2 + y


if __name__ == '__main__':
    # Let us minimize the objective function above.
    print('Running 10 trials...')
    study = optuna.create_study(storage="sqlite:///db.sqlite3")
    study.optimize(objective, n_trials=10)
    print('Best value: {} (params: {})\n'.format(study.best_value, study.best_params))
$ docker run -v $(pwd)/:/var/examples --rm -it python:3.8.1 /bin/bash

# pip install git+https://github.com/optuna/optuna.git@7344ee0fcdddb28b18a292e63caea425ae08da95
# python 938.py

Could you share more information about your environment such as the output of pip freeze?

0reactions
c-batacommented, Feb 18, 2020

I once closed this but I wonder that someone will report the same issue because prompt_toolkit is in dependencies of jupyter. Hmm…

(venv) $ pip install jupyter

...

Successfully installed MarkupSafe-1.1.1 Send2Trash-1.5.0 appnope-0.1.0 attrs-19.3.0 backcall-0.1.0 bleach-3.1.0 decorator-4.4.1 defusedxml-0.6.0 entrypoints-0.3 ipykernel-5.1.4 ipython-7.12.0 ipython-genutils-0.2.0 ipywidgets-7.5.1 jedi-0.16.0 jinja2-2.11.1 jsonschema-3.2.0 jupyter-1.0.0 jupyter-client-5.3.4 jupyter-console-6.1.0 jupyter-core-4.6.2 mistune-0.8.4 nbconvert-5.6.1 nbformat-5.0.4 notebook-6.0.3 pandocfilters-1.4.2 parso-0.6.1 pexpect-4.8.0 pickleshare-0.7.5 prometheus-client-0.7.1 prompt-toolkit-3.0.3 ptyprocess-0.6.0 pygments-2.5.2 pyrsistent-0.15.7 python-dateutil-2.8.1 pyzmq-18.1.1 qtconsole-4.6.0 six-1.14.0 terminado-0.8.3 testpath-0.4.4 tornado-6.0.3 traitlets-4.3.3 wcwidth-0.1.8 webencodings-0.5.1 widgetsnbextension-3.5.1
Read more comments on GitHub >

github_iconTop Results From Across the Web

RethinkDB connect AttributeError - python - Stack Overflow
It worked for me when I ran: import rethinkdb as rdb r = rdb.
Read more >
optuna/optuna - Gitter
Hi, if I use sqlite to store the study by using this commmand (study ... published Optuna (v1.3.0) hasn't included it yet, the...
Read more >
0.9 Changelog — SQLAlchemy 2.0 Documentation
Fixed ORM bug where the class_mapper() function would mask AttributeErrors or KeyErrors that should raise during mapper configuration due to user errors. The ......
Read more >
Change History — ZODB documentation
For other storages, MVCC is implemented using an additional storage layer. ... Now BTrees raise TypeError if an attempt is made to save...
Read more >
Full Changelog — Astropy v3.2.dev994
Sped up creating new composite units, and raising units to some power [#7549, ... Fixed the AttributeError exception that was raised when using...
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