Skip to content

RHG101997/simu-op

Repository files navigation

Simu-Opt: Schema-Driven Optimization Test Project

Simu-Opt is a modular, schema-driven optimization test project designed for solving optimization problems and parameter optimization for systems defined through schemas.

Installation

From Source

git clone https://github.com/RHG101997/simu-op.git
cd simu-op
pip install -e .

Optional Dependencies

# 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]"

Quick Start

Command Line Interface

  1. Create an example optimization problem:

    simu-opt create-example simple_problem.json
  2. Run the optimization:

    simu-opt optimize simple_problem.json --verbose
  3. List available algorithms:

    simu-opt algorithms

Web Interface

  1. Start the web server:

    python -m simu_opt.web.app
  2. Open your browser to: http://localhost:8000

  3. Use the step-by-step interface to:

    • Define variables
    • Set objectives
    • Add constraints
    • Select algorithms
    • Run optimizations

Schema Format

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
  }
}

Examples

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

Variable Types

  • 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

Available Algorithms

  • scipy_minimize: Local optimization (BFGS, L-BFGS-B, SLSQP, etc.)
  • differential_evolution: Global optimization algorithm
  • scipy_minimize_scalar: Single-variable optimization

Expression-Based

Define objectives and constraints using mathematical expressions:

{
  "expression": "x1**2 + x2**2 + sin(x1*x2)"
}

Python Code

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"}]
}

Python Files

Reference external Python simulation files:

{
  "simulation_file": "path/to/simulation.py"
}

API Usage

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}")

Development

Setting up Development Environment

git clone https://github.com/RHG101997/simu-op.git
cd simu-op
pip install -e ".[dev]"

Running Tests

pytest tests/

Adding New Algorithms

  1. Create a new algorithm class inheriting from OptimizationAlgorithm
  2. Implement the required methods
  3. Register using the @register_algorithm decorator
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

TODO

  • Fix web server errors
  • Address pending GUI issues
  • Server stalls when solving constrained problems
  • Resctructure the directory, and remove unnecessary scripts

Architecture

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

About

Application for creating/learning models and optimize them

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published