Skip to content

Tracking Issue: free-threaded Python support #5862

@porink0424

Description

@porink0424

Motivation

This issue aims to track and summarize Optuna’s support for the experimental free-threaded mode (Python v3.13t) introduced in CPython 3.13.

Description

The current status of Optuna’s compatibility with v3.13t is as follows:

Sampler

Sampler Support for 3.13t Remarks
RandomSampler Yes -
NSGAIISampler Yes -
TPESampler Yes Dependent on NumPy, but NumPy already supports 3.13t
GridSampler Yes Same as above
NSGAIIISampler Yes Same as above
BruteForceSampler No Despite the pure Python implementation, a RuntimeError: dictionary changed size during iteration was confirmed to occur when running in multi-threaded mode on Python 3.13t. The cause is currently under investigation (Link to reproduce the error without pytest-freethreaded).
CmaEsSampler Yes Dependent on NumPy and cmaes, but both already support 3.13t
GPSampler No Dependent on PyTorch, which is not yet supported on PyPI
QMCSampler No Dependent on SciPy, which is not yet supported on PyPI

Storage

Storage Support for 3.13t Remarks
InMemoryStorage Yes -
RDBStorage (sqlite) Partial sqlite3.OperationalError can occur, but this is not due to GIL. The issue arises because sqlite does not support high-level parallel processing. Errors can be resolved by reducing the number of threads (i.e., decreasing the values of n_jobs or --threads) or by extending the sqlite timeout. However, Optuna does not recommend using sqlite in cases where concurrent processing is performed with many threads (reference).
RDBStorage (MySQL) No Dependent on cryptography, which is not yet supported on PyPI
JournalStorage (File) Yes -
JournalStorage (Redis) No Despite the pure Python implementation, a RuntimeError: dictionary changed size during iteration was confirmed to occur when running in multi-threaded mode on Python 3.13t. The cause is currently under investigation (Link to reproduce the error without pytest-freethreaded).

Optuna-Integration

The current status has not yet been verified and requires further investigation.

Action Items

The possible action items are as follows (but may not be limited to) :

  • Verify the Optuna-Integration’s compatibility with v3.13t
  • Add unit tests for v3.13t

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureChange that does not break compatibility, but affects the public interfaces.needs-discussionIssue/PR which needs discussion.staleExempt from stale bot labeling.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions