AttributeError is raised when using RDB storage.
See original GitHub issueReproducible 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
- Optimize with RDB storage backend.
Additional context (optional)
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I failed to reproduce this problem when I used docker as follows:
938.py
Could you share more information about your environment such as the output of
pip freeze
?I once closed this but I wonder that someone will report the same issue because
prompt_toolkit
is in dependencies ofjupyter
. Hmm…