Simu-Opt is a modular, schema-driven optimization test project designed for solving optimization problems and parameter optimization for systems defined through schemas.
git clone https://github.com/RHG101997/simu-op.git
cd simu-op
pip install -e .# Install with web interface support
pip install -e ".[web]"
# Install with additional optimization algorithms
pip install -e ".[optimization]"
# Install with plotting capabilities
pip install -e ".[plotting]"
# Install everything
pip install -e ".[all]"-
Create an example optimization problem:
simu-opt create-example simple_problem.json
-
Run the optimization:
simu-opt optimize simple_problem.json --verbose
-
List available algorithms:
simu-opt algorithms
-
Start the web server:
python -m simu_opt.web.app
-
Open your browser to:
http://localhost:8000 -
Use the step-by-step interface to:
- Define variables
- Set objectives
- Add constraints
- Select algorithms
- Run optimizations
Optimization problems are defined using JSON or YAML schemas:
{
"name": "My Optimization Problem",
"description": "Description of the problem",
"system": {
"name": "System Name",
"variables": [
{
"name": "x",
"type": "continuous",
"bounds": [-10.0, 10.0],
"description": "Variable description"
}
],
"objectives": [
{
"name": "minimize_f",
"type": "minimize",
"expression": "x**2 + 2*x + 1"
}
],
"constraints": [
{
"name": "constraint_1",
"type": "inequality",
"expression": "x - 1"
}
]
},
"algorithm": {
"name": "scipy_minimize",
"parameters": {"method": "BFGS"},
"max_iterations": 1000,
"tolerance": 1e-6
}
}The examples/ directory contains several example optimization problems:
- simple_quadratic.json: Basic single-variable optimization
- constrained_optimization.json: Multi-variable with constraints
- rosenbrock.json: Classic Rosenbrock function
- custom_simulation.json: Custom Python simulation code
Run any example:
simu-opt optimize examples/simple_quadratic.json --verbose- continuous: Real-valued variables with bounds
- integer: Integer-valued variables with bounds
- binary: Boolean variables (0/1)
- categorical: Discrete choice from a set of categories
- scipy_minimize: Local optimization (BFGS, L-BFGS-B, SLSQP, etc.)
- differential_evolution: Global optimization algorithm
- scipy_minimize_scalar: Single-variable optimization
Define objectives and constraints using mathematical expressions:
{
"expression": "x1**2 + x2**2 + sin(x1*x2)"
}Include custom simulation code directly in the schema:
{
"simulation_code": "import numpy as np\nresult = np.sum(x**2)\n",
"objectives": [{"name": "obj", "type": "minimize", "expression": "result"}]
}Reference external Python simulation files:
{
"simulation_file": "path/to/simulation.py"
}from simu_opt import Optimizer, OptimizationSchema
# Load from schema file
optimizer = Optimizer.from_schema_file("problem.json")
result = optimizer.optimize()
# Create programmatically
from simu_opt.schemas.schema import SystemSchema, VariableSchema, ObjectiveSchema
system = SystemSchema(
name="Test System",
variables=[
VariableSchema(name="x", type="continuous", bounds=[-5, 5])
],
objectives=[
ObjectiveSchema(name="f", type="minimize", expression="x**2")
]
)
schema = OptimizationSchema(
name="Test Problem",
system=system,
algorithm={"name": "scipy_minimize"}
)
optimizer = Optimizer.from_schema_dict(schema.dict())
result = optimizer.optimize()
print(f"Optimal solution: {result.x}")
print(f"Optimal value: {result.fun}")git clone https://github.com/RHG101997/simu-op.git
cd simu-op
pip install -e ".[dev]"pytest tests/- Create a new algorithm class inheriting from
OptimizationAlgorithm - Implement the required methods
- Register using the
@register_algorithmdecorator
from simu_opt.algorithms.base import OptimizationAlgorithm, register_algorithm
@register_algorithm("my_algorithm")
class MyAlgorithm(OptimizationAlgorithm):
def optimize(self, objective_func, variables, constraints=None, **kwargs):
# Implementation here
pass
def supports_constraints(self):
return True
def supports_multi_objective(self):
return False- Fix web server errors
- Address pending GUI issues
- Server stalls when solving constrained problems
- Resctructure the directory, and remove unnecessary scripts
simu_opt/
├── core/ # Core optimization logic
├── schemas/ # Schema definitions
├── algorithms/ # Optimization algorithms
├── simulation/ # Simulation engines
├── cli/ # Command-line interface
├── web/ # Web interface
└── utils/ # Utility functions