Skip to content

Instantly share code, notes, and snippets.

# docker run -d --rm -p 3306:3306 -e MYSQL_USER=optuna -e MYSQL_DATABASE=optuna -e MYSQL_PASSWORD=password -e MYSQL_ALLOW_EMPTY_PASSWORD=yes --name optuna-mysql mysql:8.0
from __future__ import annotations
import math
import threading
import time
from sqlalchemy import event
from sqlalchemy.engine.base import Engine

Summary

Optuna uses CachedStorage, a wrapper class of BaseStorage interface, since the API calls of BaseStorage interface tends to be expensive. However, the implementation of CachedStorage is too complex and it's actually not a wrapper of BaseStorage since we've introduced some private storage APIs for CachedStorage like storage._check_and_set_param_distribution() and storage._get_trials().

So I implemented a prototype of a new simple caching mechanism to remove CachedStorage from Optuna. The change is only about 50 lines, but it is more efficient in many situations than CachedStorage. https://github.com/optuna/optuna/compare/master...c-bata:add-simple-inmemory-cache?expand=1

For the benchmark of the new caching mechanism, I prepared the same benchmark scenario with optuna/optuna#11

import time
import numpy
from bottle import Bottle
from optuna_dashboard import wsgi
from optuna.storages import RDBStorage
from python_tests.wsgi_client import send_request
import optuna
from optuna.trial import FrozenTrial
def objective(trial):
x0 = trial.suggest_int("x0", -10, 10)
x1 = trial.suggest_int("x1", -10, 10)
return x0 ** 2 + x1
import math
import optuna
import numpy as np
def six_hump_camel(x1, x2):
return (
(4 - 2.1 * (x1 ** 2) + (x1 ** 4) / 3) * (x1 ** 2)
+ x1 * x2
import os
import subprocess
from mutagen.id3 import TRCK, Encoding, TALB, TPE1
from mutagen.mp3 import MP3
original_dir = "mp3/Speaking for IELTS"
new_dir = original_dir + "_new"
title = 'Speaking for IELTS'
author = 'Karen Kovacs'
import multiprocessing
from concurrent.futures import ProcessPoolExecutor
results = {}
lock = multiprocessing.Lock()
def fn(n):
global results
with lock:

Case 1

int abs(int i) {
    if (i >= 0) {
        return i;
    } else {
        return -i;
    }
}
@c-bata
c-bata / asm_check.md
Created December 8, 2021 05:37
x86, x86_64のアセンブリを確認

ソースファイル

sample-pointer.c

void func(void) {
  int val;
  int *ptr = &val;
  *ptr = 41;
}
import ast
import sys
from typing import List
class Finder(ast.NodeVisitor):
def __init__(self, file_path: str, lines: List[str]) -> None:
self.file_path = file_path
self.lines = lines