This release is a pre-release and may not be stable for production use.
Tyrannis
A flexible metaheuristic optimization framework built for diverse search spaces and scalable execution.
Tyrannis is a Python framework for solving optimization problems with population-based metaheuristic algorithms while keeping the problem definition independent from the execution strategy. Define your search space, choose an optimization algorithm, and decide how the workload should run—from a simple local execution to parallel or distributed processing. Tyrannis also provides support for mixed-variable optimization, allowing continuous, integer, binary, categorical, and permutation variables to coexist in the same problem.
Installation
Basic installation
For a local installation with the standard execution capabilities:
pip install tyrannis
This installation provides the core framework, including local execution and the basic LRU and disk caching mechanisms.
Advanced caching
To enable the additional caching capabilities:
pip install "tyrannis[cache]"
The cache extra installs the additional dependencies required by Tyrannis' advanced cache resources. Without this extra, only the basic LRU and disk cache mechanisms are available.
Distributed processing with Spark
To enable distributed processing with Spark:
pip install "tyrannis[spark]"
This installs the dependencies required by the Spark backend. Distributed execution with Spark requires an appropriate Spark infrastructure to be usable.
Combining extras
Extras can be installed together:
pip install "tyrannis[cache,spark]"
Public API
The core optimization requires only three components: an optimizer, a search space, and an optimization algorithm. The processor, backend, and migration components are optional and can be added to control how the optimization is executed, parallelized, distributed, and coordinated.
Algorithms
tyrannis.algorithm
Algorithms are the optimization methods used to search for the best solution within the defined search space.
| Import | Description |
|---|---|
PSO |
Particle Swarm Optimization algorithm for population-based continuous and encoded search. |
ArtificialBeeColony |
Artificial Bee Colony algorithm inspired by the foraging behavior of honey bees. |
Spaces
tyrannis.space
Spaces define the search space of the optimization problem, including the variables, their possible values or boundaries, and the cost function that is optimized.
| Import | Description |
|---|---|
Continuous |
Defines a continuous search space bounded by numerical lower and upper limits. |
Integer |
Defines an integer search space bounded by numerical lower and upper limits. |
Binary |
Defines a binary search space whose variables can take the values 0 or 1. |
Categorical |
Defines a categorical search space based on a finite set of discrete choices. |
Permutation |
Defines a search space for permutation-based optimization problems. |
Mixed |
Combines multiple search spaces, allowing optimization problems with heterogeneous variable types. |
Processors
tyrannis.processor
Processors define how the optimization algorithm is executed on each machine involved in the optimization, including whether particle processing is performed serially or in parallel.
| Import | Description |
|---|---|
Joblib |
Executes particle processing using Joblib-based parallelism. |
ProcessPool |
Executes particle processing using multiple processes. |
ThreadsPool |
Executes particle processing using a pool of threads. |
Backends
tyrannis.backend
Backends define how the processing of the optimization algorithm is distributed between machines, determining how the optimization workload and population are organized across the available execution resources.
| Import | Description |
|---|---|
SparkParallel |
Executes optimization using distributed processing with Spark on a single island. |
SparkDistributed |
Executes optimization using distributed processing with Spark across multiple islands, supporting distributed population and migration. |
Migrations
tyrannis.migration
Migrations define how the machines participating in distributed optimization communicate and exchange information about the optimization process, allowing solutions to move between islands.
| Import | Description |
|---|---|
GlobalBest |
Shares the globally best solution between islands during distributed optimization. |
IslandMigration |
Provides migration of solutions between islands according to the configured migration strategy. |
Examples
Basic optimization
A simple continuous optimization problem can be configured by defining a search space, selecting an algorithm, and creating an optimizer:
from tyrannis import Optimizer
from tyrannis.algorithm import PSO
from tyrannis.space import Continuous
def cost_function(x, y):
return x**2 + y**2
space = Continuous(
boundaries={"x": (-10, 10), "y": (-10, 10)},
cost_function=cost_function
)
algorithm = PSO()
optimizer = Optimizer(
space=space,
algorithm=algorithm,
n_iterations=100,
n_particles=50
)
optimizer.fit()
print(optimizer.best_solution)
# {"x": 0.0, "y": 0.0}
print(optimizer.best_fitness)
# 0.0
Mixed search space and parallel processing
Tyrannis can combine different variable types in the same optimization problem. In this example, a continuous variable and a categorical variable are optimized together using the Artificial Bee Colony algorithm and a Joblib processor:
from tyrannis import Optimizer
from tyrannis.algorithm import ArtificialBeeColony
from tyrannis.processor import Joblib
from tyrannis.space import Categorical, Continuous, Mixed
def cost_function(x, category):
category_target = {
"low": 0.0,
"medium": 1.0,
"high": 2.0,
}
return (x - category_target[category]) ** 2
space = Mixed(
spaces={
"x": Continuous((-5.0, 5.0)),
"category": Categorical(("low", "medium", "high"))
},
cost_function=cost_function
)
algorithm = ArtificialBeeColony()
processor = Joblib(joblib_backend="loky")
optimizer = Optimizer(
space=space,
algorithm=algorithm,
processor=processor,
n_iterations=100,
n_particles=50
)
optimizer.fit()
print(optimizer.best_solution)
# {"x": 0.0, "category": "low"}
print(optimizer.best_fitness)
# 0.0
In this example, no backend is specified, so the optimization runs locally. The Joblib processor parallelizes particle evaluation across the available CPUs.
Status
Tyrannis is currently in the alpha stage of development. The core architecture and initial optimization capabilities are already available, but the API and implementation are still evolving.
The following features are planned for future releases.
Roadmap
Algorithms
- PSOGSA
- Genetic Algorithm
- GSA — Gravitational Search Algorithm
- Differential Evolution
- CMA-ES — Covariance Matrix Adaptation Evolution Strategy
- Ant Colony Optimization
- Grey Wolf Optimization
- Whale Optimization Algorithm
Spaces
- Ordinal
- Set
- Graph
Backends
- MPI
- Ray
- Dask
Migration
- Diffusion
Testing
- Construction and maintenance of unit tests
- Construction and maintenance of integration tests
- Increased coverage of algorithms, spaces, processors, backends, and migration strategies
- Validation of distributed execution behavior
License
Tyrannis is distributed under the BSD 3-Clause License.
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 tyrannis-0.1.0a1.tar.gz.
File metadata
- Download URL: tyrannis-0.1.0a1.tar.gz
- Upload date:
- Size: 91.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c70df62682f997b841a05ec99a11301def0028f780a2691927b1f4f7a550234e
|
|
| MD5 |
032d370113135c01a56647e3270df7a3
|
|
| BLAKE2b-256 |
6a82189bbddde339fd82e03a3c8077a6ce5da1eb7512ff8b82ae1e28c322fc59
|
File details
Details for the file tyrannis-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: tyrannis-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 121.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fc4e68aadd87ca198cc571d46bf3260854bea9d8367d3bf36f10ec743c28ce0
|
|
| MD5 |
da3733ca80c834d4e4b0376af64b412f
|
|
| BLAKE2b-256 |
4054b4b44f24ce86616eb969332a033c691055f3a36454714c6bf49608e53b97
|