A flexible optimization tool that connects (hyper)parameter optimization engines with custom experiments through template-based configuration and a task, e.g. scripting.
Project description
Stexus
Study, Experiment, adjUst, Study
A flexible optimization tool that connects (hyper)parameter optimization engines with custom experiments through template-based configuration and a task, e.g. scripting.
Stexus enables you to optimize any parameterized process by:
- Rendering template files with trial parameters.
- Executing custom experiment scripts.
- Collecting and optimizing results.
- Rendering template files with optimized trial parameters.
- (Repeat.)
Currently supported engines:
- Optuna (optuna.org)
We use Jinja (site) for our templating engine.
Why Stexus?
Existing hyperparameter optimization tools are typically designed for specific use cases, primarily machine learning workflows. This leaves a significant gap in automation: there is no general purpose solution for optimizing parameters in arbitrary processes.
Whether it's tuning system configurations, optimizing algorithm parameters in different languages, or finding optimal settings for complex services, often we are left to manually iterate or build custom optimization script from scratch.
Stexus bridges this gap by providing general-purpose parameter optimization tool that can work with arbitrary processes, like scripting. By combining template rendering with an optimization engines, Stexus enables dynamic experimentation across diverse domains and technologies.
Stexus takes the stance on anything that can be parameterized, can be optimized, therefore enabling wider parameter optimization tasks.
Installation
You can install Stexus via pip (we are on PyPI!)
python3 -m pip install stexus
Quick Start
-
Create your experiment template (e.g.,
config_template.yaml,config.txt, whatever that is desired).For example, this is the content of template containing single number that will be read into a linux shell script:
{{ number1 }} -
Create your experiment script (e.g.,
guess.sh):#!/bin/bash number=55 guess=$(cat config.txt) diff=$((number > guess ? number - guess : guess - number)) sleep 1 # does not have to have sleep, this is just so that # observer has time to spawn echo "$diff" >./result # write metric to the score file
(or you can combine 1 and 2 together, so that experiment is using rendered script directly)
-
Configure Stexus (
config.yaml):study_name: "My Optimization Study" engine: optuna trials: 50 source_templates: - ./config.txt rendered_templates_path: rendered score_path: ./result storage: sqlite:///study.sqlite3 direction: minimize experiment: type: script args: ./guess.sh adjustments: - name: number1 type: int config: low: 1 high: 50
-
Run the optimization:
python3 -m stexus -c config.yaml
Or, go to one of the examples and run python3 -m stexus -c config.yaml to see how Stexus run.
Usage
Basic Usage
python3 -m stexus -c <config_file_path>
Observer Mode
Monitor an existing study without running new trials:
python3 -m stexus -c <config_file_path> --observe-only
Configuration Reference
Stexus uses YAML configuration files. All required fields must be specified.
Core Settings
study_name (required)
- Type: string
- Description: Unique identifier for your optimization study
engine
- Type: string
- Default:
optuna - Allowed values:
optuna - Description: Optimization backend engine
trials (required)
- Type: integer
- Minimum: 1
- Description: Number of optimization trials to run
direction (required)
- Type: string
- Allowed values:
minimize,maximize - Description: Optimization direction for the objective function
Storage & Persistence
storage (required)
- Type: string
- Description: Backend storage URL (follows Optuna storage format)
- Example:
sqlite:///study.db,postgresql://user:pass@host/db
load_if_exists
- Type: boolean
- Default:
true - Description: Whether to resume existing studies with the same name
Template System
source_templates (required)
- Type: list of strings
- Minimum length: 1
- Description: Files or directories containing Jinja template files
- Example:
["./config.yaml.j2", "./scripts/"]
rendered_templates_path
- Type: string
- Default:
rendered - Description: Directory where rendered templates will be saved
Experiment Configuration
experiment (required)
- Type: object
- Description: Defines how experiments are executed
Script Type (currently the only supported type):
experiment:
type: script # required
args: "./run_experiment.sh" # required - script to execute
ignore_exit_code: false # optional, default: false
type: Must bescriptargs: Path to script or command to execute for each trialignore_exit_code: Iftrue, non-zero exit codes won't fail the trial
Results
score_path (required)
- Type: string
- Description: File path where the experiment writes the objective value
- Note: Must contain a single numeric value
Parameter Space
adjustments (required)
- Type: list of parameter objects
- Minimum length: 1
- Description: Defines the parameter search space
Each parameter object must have name, type, and config fields:
Integer Parameters:
- name: batch_size
type: int
config:
low: 16 # required
high: 128 # required
step: 16 # optional
log: false # optional, default: false
Float Parameters:
- name: learning_rate
type: float
config:
low: 0.001 # required
high: 0.1 # required
step: 0.001 # optional
log: true # optional, default: false (use log scale)
Categorical Parameters:
- name: optimizer
type: categorical
config:
choices: ["adam", "sgd", "rmsprop"] # required, min 1 choice
Uniform Distribution:
- name: dropout_rate
type: uniform
config:
low: 0.0 # required
high: 0.5 # required
Log-Uniform Distribution:
- name: weight_decay
type: loguniform
config:
low: 1e-5 # required
high: 1e-2 # required
Discrete Uniform:
- name: hidden_size
type: discrete_uniform
config:
low: 64.0 # required
high: 512.0 # required
q: 64.0 # required (step size)
Observer (Study Monitoring)
observer
- Type: object
- Description: Configuration for study observation and monitoring
observer:
enabled: false # default: false
host: "127.0.0.1" # default: "127.0.0.1"
port: 8080 # default: 8080
server: auto # default: "auto"
artifact_dir: "./artifacts" # optional
storage_class: "RDBStorage" # optional
quiet: false # default: false
enabled: Whether to enable the observerhost: Host address for the observer serverport: Port for the observer serverserver: Server type (typically leave as "auto")artifact_dir: Directory for storing artifactsstorage_class: Storage class for the observerquiet: Suppress observer output
How It Works
In stages, Stexus do:
-
Template Rendering
Stexus processes your template files, replacing parameter placeholders with trial values
-
Experiment Execution
Runs your specified script or command with the rendered templates
-
Result Collection
Reads the objective value from the specified score file
-
Optimization
Uses the configured engine to suggest better parameters for the next trial
This repeats until the specified number of trials is complete.
Use Cases
Well, you can:
- Find optimal settings for applications or services via system configurations. Or other configuration.
- Optimize parameters for custom algorithms, choose it yourself.
- Find optimal resource allocation settings in infrastructure or deployment that you have.
- Basically optimizing any process that can be scripted and measured.
Contributing
TODO
License
See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stexus-0.0.2.tar.gz.
File metadata
- Download URL: stexus-0.0.2.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0910c0478315d2b17537f4b1b24768eeed147515b979f88248b4dded280a158c
|
|
| MD5 |
0cbd31783a9583b40da7c43f24a3c888
|
|
| BLAKE2b-256 |
1c15a086133a8c26f707bdb4c50aa101bbc95e5ef6370a636c6eb0dec51ccf24
|
Provenance
The following attestation bundles were made for stexus-0.0.2.tar.gz:
Publisher:
publish-to-pypi.yml on jundi77/stexus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stexus-0.0.2.tar.gz -
Subject digest:
0910c0478315d2b17537f4b1b24768eeed147515b979f88248b4dded280a158c - Sigstore transparency entry: 584130385
- Sigstore integration time:
-
Permalink:
jundi77/stexus@ff2bfe4126e44d442c374035aa142fe0ab8a8190 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/jundi77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ff2bfe4126e44d442c374035aa142fe0ab8a8190 -
Trigger Event:
release
-
Statement type:
File details
Details for the file stexus-0.0.2-py3-none-any.whl.
File metadata
- Download URL: stexus-0.0.2-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b234c5e9078d4a922eccb6b97993a3eacd31747b1588bfa1241820aafac01b7
|
|
| MD5 |
4621ffc66b98acf2602d889dd0773bf7
|
|
| BLAKE2b-256 |
c9365cc535b8e5fd085f615c0145798edfda24c00ce24df415f640b13404187c
|
Provenance
The following attestation bundles were made for stexus-0.0.2-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on jundi77/stexus
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stexus-0.0.2-py3-none-any.whl -
Subject digest:
6b234c5e9078d4a922eccb6b97993a3eacd31747b1588bfa1241820aafac01b7 - Sigstore transparency entry: 584130388
- Sigstore integration time:
-
Permalink:
jundi77/stexus@ff2bfe4126e44d442c374035aa142fe0ab8a8190 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/jundi77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@ff2bfe4126e44d442c374035aa142fe0ab8a8190 -
Trigger Event:
release
-
Statement type: