Skip to main content

optunizer

Optuna extension for JSON and YAML configuration files

Installation

pip install optunizer
  • with PostresSQL connector
pip install optunizer[psycopg]

Running

  1. Suppose you have some script/program (e.g. main.py) with config in YAML/JSON file (e.g. config.yaml) that returns some output (e.g. metrics.json)
  • main.py
import json
import yaml
config_file = 'config.yaml'
with open(config_file) as f:
  params = yaml.safe_load(f)
metric = params['param1'] + params['param2']
metrics = {'metric': metric}
metrics_file = 'metrics.json'
with open(metrics_file, 'w') as f:
  json.dump(metrics, f)
  • config.yaml
param1: 2
param2: 0.5
param3: c
  • metrics.json
{
  "metric": 0.3
}
  1. Make optunizer config file, e.g. optunizer.yaml
attrs:  # track all fields in files
  config.yaml: true
  metrics.json: true
  optunizer_sysinfo.json: true
class: optunizer.optimizer.Optimizer
load_if_exists: true
export_csv: optunizer_results.csv
export_metrics: optunizer_metrics.json
export_sysinfo: optunizer_sysinfo.json
study: optunizer_test
objectives:  # Specify objectives, e.g. fields in metrics.json file
  metric@metrics.json: minimize
params:  # Specify params, e.g. fields in config.yaml file
  param1@config.yaml:
    method: suggest_int
    method_kwargs:
      high: 3
      low: 0
  param2@config.yaml:
    method: suggest_float
    method_kwargs:
      high: 1.0
      low: 0.01
      log: true
  param3@config.yaml:
    method: suggest_categorical
    method_kwargs:
      choices: [a, b, c]
pruner: PatientPruner
pruner_kwargs:  # Specify pruner, e.g. PatientPruner with NopPruner subpruner
  min_delta: 0
  patience: 0
  wrapped_pruner: NopPruner
  wrapped_pruner_kwargs: {}
sampler: PartialFixedSampler
sampler_kwargs:   # Specify sampler, e.g. PartialFixedSampler with GridSampler subsampler
  base_sampler: RandomSampler
  base_sampler_kwargs: {}
  # base_sampler: GridSampler
  # base_sampler_kwargs:
  #   search_space:
  #     param1@config.yaml: [0, 1, 2]
  #     param2@config.yaml: [0.01, 0.5]
  fixed_params:
    param3@config.yaml: a
subprocess_kwargs:  # Specify your command
  args:
  - python
  - main.py
  - config.yaml
  1. Run optunizer
OPTUNA_CONFIG=optunizer.yaml python -m optunizer

or

python -m optunizer optunizer.yaml
  1. Run optunizer streamlit viz
pip install optunizer[viz]
python -m optunizer app
  1. There are several useful environment variables, that could be set in command line, .env or .env.secret files
OPTUNA_CONFIG=optunizer.yaml
OPTUNA_CONFIG_APP=app.yaml
OPTUNA_SHARED=.env
OPTUNA_SECRET=.env.secret
OPTUNA_URL=postgresql+psycopg2://USER:PASSWORD@IP:PORT/DB  # see https://docs.sqlalchemy.org/en/14/core/engines.html
OPTUNA_STUDY=STUDY_NAME
OPTUNA_TRIALS=3
OPTUNA_TIMEOUT=3600
OPTUNA_LOAD_IF_EXISTS=1
OPTUNA_EXPORT_CSV=CSV_FILE_NAME
OPTUNA_EXPORT_METRICS=METRICS_FILE_NAME
OPTUNA_EXPORT_SYSINFO=SYSINFO_FILE_NAME

Metadata

Release files for optunizer 0.1.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optunizer 0.1.17
File Size Uploaded Provenance Actions
optunizer-0.1.17.tar.gz 16.8 kB Without provenance Details for optunizer-0.1.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optunizer 0.1.17
File Interpreter ABI Platform Actions
optunizer-0.1.17-py3-none-any.whl Python 3 none any Details for optunizer-0.1.17-py3-none-any.whl

Total release size: 33.2 kB

Release files / optunizer-0.1.17.tar.gz

Download URL optunizer-0.1.17.tar.gz
Size 16.8 kB
Tags Source
SHA-256 checksum
How to use checksums
60044878c28a516d6660e31fb17cc290b76b4a99b3535f04fafd354e83f28931
BLAKE2b-256 checksum
How to use checksums
d7ed04220cc442c03853f9b24a20f860d74c7b17dc3cf1ca8a73db1013fbbb65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / optunizer-0.1.17-py3-none-any.whl

Download URL optunizer-0.1.17-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fe8ec6ad6054bff936640fc31f969b84a0a14d56525cac53f55441b1b6b501f
BLAKE2b-256 checksum
How to use checksums
0334e81571002c4fe04dd5dc905ffd3402081053105f4c5e74ac2a42429dcc71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for optunizer 0.1.17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page