Skip to main content

Extensible MDAO framework with zero boilerplate integration and plug-and-play optimization.

Project description

SmartMDAO 🚀

Extensible MDAO framework with zero boilerplate integration and plug-and-play optimization.

SmartMDAO is a lightweight, purely Pythonic framework for Multidisciplinary Design Analysis and Optimization (MDAO).

Define your physics and engineering models, and let SmartMDAO handle the complex dependency mapping, cyclic feedback loops, and caching. Once your Multidisciplinary Analysis (MDA) is built, seamlessly plug it into your favorite optimization library.

🌟 Why SmartMDAO?

  1. Effortless MDA: No heavy Domain-Specific Languages. Just use @pipeline.step and standard Python type hints. SmartMDAO automatically maps dependencies and resolves cyclic feedback loops. Compatible with with any standard Python types, such as strings and user-specific objects.

  2. Built-in Caching: Speed up your pipelines instantly by layering @cached decorators (RAM, HDF5, Pickle) onto expensive functions.

  3. Agnostic MDO: Bring your own optimizer. Our PipelineEvaluator bridge works flawlessly with SciPy, OpenTURNS, PyOptSparse, or any other algorithm you prefer.

  4. Also Built for Researchers (Highly Extensible) SmartMDAO is designed to be a sandbox for innovation. Our solvers are built on standard Python Protocol interfaces. If you want to research and implement your own custom MDA convergence algorithms, you can easily write a new solver class and inject it into the pipeline without touching the core framework.

⚡ Quick Start: Caching, Constraints, and Optimization

Here is how easily you can solve the classic Sellar coupled problem.

Sellar Coupling Workflow

Notice how SmartMDAO automatically converges the $y_1 \leftrightarrow y_2$ cyclic dependency, caches the heavy lifting, and elegantly bridges to SciPy - even allowing you to flip constraint signs on the fly.

import math
import logging
from scipy.optimize import minimize
from smartmdao import (
    Pipeline,
    HybridSolver,
    PipelineEvaluator,
    cached,
    MemoryBackend,
    configure_logging
)

# --- Setup Logging and Cache ---
configure_logging(level=logging.WARNING)
mem_cache = MemoryBackend() # HDF5 and Pickle also available

# ==============================================================================
# PART 1: Initialize the Pipeline with the HybridSolver
# ==============================================================================
# The HybridSolver automatically detects and converges cyclic dependencies
pipeline = Pipeline(
    solver=HybridSolver(max_iterations=100, tolerance=1e-6)
)

# ==============================================================================
# PART 2: Define the Sellar Disciplines (MDA)
# ==============================================================================
@pipeline.step(outputs=["y1"])
@cached(mem_cache) # Instantly cache this discipline to speed up evaluations
def discipline_1(z1: float, z2: float, x1: float, y2: float) -> float:
    return (z1 ** 2) + z2 + x1 - (0.2 * y2)

@pipeline.step(outputs=["y2"])
@cached(mem_cache) 
def discipline_2(z1: float, z2: float, y1: float) -> float:
    return math.sqrt(abs(y1)) + z1 + z2

@pipeline.step(outputs=["objective"])
@cached(mem_cache) 
def compute_objective(x1: float, z2: float, y1: float, y2: float) -> float:
    return (x1 ** 2) + z2 + (y1 ** 2) + math.exp(-y2)

@pipeline.step(outputs=["constraint_1"])
@cached(mem_cache) 
def compute_constraint_1(y1: float) -> float:
    """Constraint formulation: 3.16 - y1 <= 0"""
    return 3.16 - y1

@pipeline.step(outputs=["constraint_2"])
@cached(mem_cache) 
def compute_constraint_2(y2: float) -> float:
    """Constraint formulation: y2 - 24.0 <= 0"""
    return y2 - 24.0

# ==============================================================================
# PART 3: Setup the Evaluator Bridge
# ==============================================================================
# Map the optimizer's numeric array back to our named design variables
evaluator = PipelineEvaluator(
    pipeline=pipeline,
    design_vars=["z1", "z2", "x1"],
    constants={"y2": 1.0} # Initial guess to kick off the cycle
)

# Setup Optimizer parameters
initial_guess = [1.0, 1.0, 1.0] 
bounds = [(-10.0, 10.0), (0.0, 10.0), (0.0, 10.0)]

# Constraints for scipy.optimize
# SciPy expects f(x) >= 0. Since our pipeline outputs f(x) <= 0, we use multiplier=-1.0
# The evaluator returns a callable function so the optimizer can access it
cons = [
    {'type': 'ineq', 'fun': evaluator.get_constraint("constraint_1", multiplier=-1.0)},
    {'type': 'ineq', 'fun': evaluator.get_constraint("constraint_2", multiplier=-1.0)}
]

# ==============================================================================
# PART 4: Run Optimization (MDO)
# ==============================================================================
print(f"Starting scipy optimization from initial guess: {initial_guess}")
result = minimize(
    evaluator.get_objective("objective"), 
    initial_guess, 
    method='SLSQP', 
    bounds=bounds, 
    constraints=cons,
    options={'disp': True, 'ftol': 1e-6}
)

# ==============================================================================
# PART 5: Extract Full State at Optimum
# ==============================================================================
# By passing the optimal 'x' back to the evaluator, we retrieve the full dictionary
# of intermediate variables, constraints, and objective values.
# Results automatically recovered from cache (no additional run).
# Change log to DEBUG to see cache hit. 
optimal_state = evaluator.evaluate(result.x)

print("\nOptimization Success! Final State:")
for key, value in optimal_state.items():
    if isinstance(value, float):
        print(f"  {key}: {value:.4f}")
    else:
        print(f"  {key}: {value}")

# Optional - visualizing the workflow
pipeline.visualize(inputs=["z1", "z2", "x1"],  # <-- if not provided, pipeline tries to infer it
    output_path = str("sellar_mdao.svg"), # choose your format svg, pdf, png
    orientation = "LR",
    graph_type = "bipartite",
    view = False)

🧠 Advanced Examples

The Quick Start above just scratches the surface! If you want to see how SmartMDAO handles deeper nesting, custom optimization solvers, or more complex multidisciplinary systems, check out the scripts folder in our GitHub repository.

📦 Installation

SmartMDAO is available on PyPI. We recommend using uv for lightning-fast installation, but standard pip works perfectly.

Using uv:

uv add smartmdao

Using pip:

pip install smartmdao

(Note: Visualization features require the graphviz system binary to be installed on your OS).

Installing Graphviz (Optional System Requirement)

While smartmdao works perfectly on its own, generating pipeline diagrams requires the graphviz system binary to be installed on your OS.

macOS (Homebrew):

brew install graphviz

Linux (Ubuntu/Debian):

sudo apt-get install graphviz

Windows (winget):

winget install graphviz

(Alternatively, you can download the Windows installer directly from the official Graphviz website)

🤝 Contributing & License

Contributions are welcome! Please feel free to submit a Pull Request.This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartmdao-1.2.3.tar.gz (216.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartmdao-1.2.3-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file smartmdao-1.2.3.tar.gz.

File metadata

  • Download URL: smartmdao-1.2.3.tar.gz
  • Upload date:
  • Size: 216.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for smartmdao-1.2.3.tar.gz
Algorithm Hash digest
SHA256 cecbfa1e5278cdaaebf09dfa6c8ef656ab68c1523752c02b2aef5e2bad8c5720
MD5 ef47b24948cbe80d2b589094fac00441
BLAKE2b-256 fb601a1c99494a08be129dfbcda18416d14fea78af4676e8cb8062a30fac1329

See more details on using hashes here.

File details

Details for the file smartmdao-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: smartmdao-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"20.04","id":"focal","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for smartmdao-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0827018f8f37cb068182fa9ec57eb5455e9aab5a5e83a7f2caf908b03d64070b
MD5 39b9e799cccc1cdb94218095c0ea0fc3
BLAKE2b-256 5bae369350c3644bfdec8a0531dec70a44b2fa14de6c76a3c682fa76d863f5dc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page