Skip to main content

SAMA Logo

Solar Alone Multi-Objective Advisor

Open-Source Hybrid Renewable Energy Microgrid Optimization

DOI License: GPL v3 PyPI Python 3.9+ GitHub Stars


SAMA is a free, open-source Python platform for the design, sizing, and operation optimization of hybrid renewable energy microgrids. It performs location-specific techno-economic assessment using site-dependent load profiles, meteorological data, component degradation models, and utility billing structures, with no license fees and no black-box code.

Developed by the FAST Research Group at Western University, London, Ontario, Canada.


Table of Contents


Why SAMA?

Proprietary tools like HOMER Pro and HOMER Grid are closed-source and license-restricted. SAMA was built to remove that barrier:

  • Free and open-source: GPL-3.0, forever
  • Transparent algorithms: read, modify, and extend every line
  • Validated: cross-validated against HOMER Pro across multiple U.S. climate zones
  • No cost barriers: designed for researchers, students, and resource-constrained institutions worldwide

What SAMA Optimizes

SAMA finds the optimal combination of five system design variables by minimizing Net Present Cost (NPC) over a 25-year project lifetime:

Variable Description
Npv Number of PV modules (kW of rated capacity)
Nwt Number of wind turbines
Nbat Number of battery packs
N_DG Number / size of diesel generator units
Cn_I Inverter capacity (kW)

Constraints include reliability (LPSP), renewable energy fraction, capital budget, and rooftop area limits. Multi-objective mode (EM=1) adds Levelized Emissions (LEM) as a second objective.


Key Capabilities

Category Details
System Components Solar PV, wind turbines, battery storage (Li-ion or lead-acid), diesel generator, utility grid, air-source heat pump (Bosch or Goodman), electric vehicle with V2X
Optimization Algorithms Particle Swarm Optimization (PSO), Advanced Differential Evolution (ADE), Artificial Bee Colony (ABC), Grey Wolf Optimizer (GWO)
Energy Simulation 8,760-hour hourly dispatch with marginal-cost-based EMS, EV smart charging and V2X lookahead arbitrage, heat pump thermal-electric coupling
Electricity Tariffs 8 structures: flat, seasonal, monthly, tiered, seasonal tiered, monthly tiered, Time-of-Use (TOU), Ultra-Low TOU (ULO)
Natural Gas Tariffs 8 structures including PG&E G-1 therms-based and Enbridge EGD 4-tier m³-based
Financial Analysis 25-year NPC, LCOE, levelized emissions, price escalation, RE incentives (30% ITC), net metering reconciliation
Load Inputs 10 electrical load input modes (CSV, monthly/annual averages, generic profiles), thermal load from Excel
Weather Inputs SAM NSRDB API integration, user CSV files, monthly/annual averages
Outputs Convergence plots, 25-year cash flow charts, energy distribution, battery SOC, grid interconnection, EV and heat pump performance charts, hourly CSV data

Getting Started

SAMA supports three usage methods. Choose the one that fits your workflow:

Method 1: Raw Python Code

For researchers and developers who want full access to source code and algorithms.

git clone https://github.com/Sas1997/SAMA.git
cd SAMA
pip install -e .

This installs SAMA in editable mode, so you can edit any file under src/samapy/ directly and see your changes immediately. Configure your system with the wizard or by editing src/samapy/core/Input_Data.py, then run:

samapy-run

Available algorithms: pso, ade, abc, gwo

Method 2: Python Package (pip)

The recommended method for most users. No source editing required.

pip install samapy

Note: The PyPI distribution name is samapy. Once installed, import and CLI commands use samapy. Step 1: Configure your project:

samapy-config

An interactive multi section wizard guides you through all parameters and saves samapy_config_COMPLETE.yaml. Step 2: Run the optimization:

samapy-run

Step 3: View results in samapy_outputs/

Additional run options:

samapy-run --algorithm ade          # override algorithm
samapy-run --output results/run1    # override output directory
samapy-run --dry-run --verbose      # validate config without running
samapy-run --no-gui                 # headless / server mode

Method 3: Windows .exe (Alpha)

A point-and-click GUI for non-technical users. No Python installation required. Currently in alpha.

https://github.com/Sas1997/SAMA


Quick Start

Run SAMAPY in five steps using bundled sample data (London, Ontario):

# 1. Install
pip install samapy

# 2. Create a project folder and navigate into it
mkdir my_samapy_project && cd my_samapy_project

# 3. Launch the configuration wizard (accept defaults for a quick test)
samapy-config

# 4. Run the optimization
samapy-run

# 5. View your results
#    samapy_outputs/figs/    → all charts (PNG/SVG)
#    samapy_outputs/data/    → Outputforplotting.csv (8,760-hour time series)

Expected runtime: 2–10 minutes for MaxIt=200, nPop=50 depending on hardware. The first run is slower due to one-time Numba JIT compilation of the EMS engine.


Optimization Algorithms

All four algorithms optimize the same 5-variable design space. Choose based on your preference for convergence speed vs. exploration depth:

Algorithm Key Behavior Best For
PSO: Particle Swarm Optimization Velocity-based swarm convergence Fast convergence
ADE: Advanced Differential Evolution Multi-strategy mutation with adaptive F and CR Thorough exploration
ABC: Artificial Bee Colony Foraging phases with guided reinitialization Balanced exploration
GWO: Grey Wolf Optimizer Pack hierarchy convergence; parallel variant available Fast convergence, parallel runs

For rigorous comparison, set Run_Time > 1 to average across multiple independent runs.


Output Examples

After samapy-run completes, results are organized in samapy_outputs/:

samapy_outputs/
├── Optimization.png                  ← convergence curve
├── figs/
│   ├── Cash_Flow.svg                 ← 25-year lifecycle cost breakdown
│   ├── Energy Distribution.png       ← annual energy supply by source
│   ├── Battery State of Charge.png   ← hourly SOC profile
│   ├── Grid Interconnection.png      ← hourly grid import/export
│   ├── electricity_comparison.png    ← SAMAPY system vs. grid-only cost
│   ├── hp_monthly_summary.png        ← heat pump COP and energy (if HP=1)
│   └── EV Energy.png                 ← EV charge/discharge (if EV=1)
└── data/
    ├── Outputforplotting.csv         ← full 8,760-hour time series
    └── cash_flow_data.csv            ← annual 25-year cash flow table

Documentation

Full documentation is available in this repository:

  • SAMA_Documentation.md: Complete user guide covering all parameters, algorithms, financial models, input formats, troubleshooting, and mathematical formulations

Key documentation sections:

Topic Location
All configuration parameters Section 6: Configuration File
Optimization algorithms (detail) Section 7
Energy management system Section 8
Component models Section 9
Financial model Section 10
Troubleshooting Section 13
Mathematical formulations Section 19
Where to find input data Appendix A

Publications

SAMA has been peer-reviewed and published across multiple journals. If you use SAMA in your research, please cite [A1]:

# Reference
A1 Sadat, S.A., Takahashi, J. and Pearce, J.M. (2023). A Free and open-source microgrid optimization tool: SAMA. Energy Conversion and Management, 298, 117686. DOI
A2 Sadat, S.A. and Pearce, J.M. (2024). The threat of economic grid defection in the US with solar PV, battery and generator hybrid systems. Solar Energy, 282, 112910. DOI
A3 Sadat, S.A. and Pearce, J.M. (2025). Techno-economic evaluation of electricity pricing structures on PV and PV-battery hybrid systems in Canada. Renewable Energy, 242, 122456. DOI
A4 Sadat, S.A., Mittal, K. and Pearce, J.M. (2025). Using investments in solar photovoltaics as inflation hedges. Energies, 18(4), 890. DOI
A5 Groza, J.M., Sadat, S.A., Hayibo, K.S. and Pearce, J.M. (2024). Autonomous peer-to-peer virtual net metering of solar PV distributed generation. Solar Energy Advances, 4, 100064. DOI
A6 Sadat, S.A., Lemieux, J.E.B. and Pearce, J.M. (2026). Shifting Subsidies: Redirecting Alberta's Oil and Gas Support to Solar Power. Energies, 19(4), 972. DOI
A7 Sadat, S.A., Hoex, B. and Pearce, J.M. (2022). A review of the effects of haze on solar PV performance. Renewable and Sustainable Energy Reviews, 167, 112796. DOI

Citation

If you use SAMA in academic work, please cite the primary paper:

@article{sadat2023sama,
  title   = {A Free and open source microgrid optimization tool: {SAMA} the solar alone Multi-Objective Advisor},
  author  = {Sadat, Seyyed Ali and Takahashi, J. and Pearce, Joshua M.},
  journal = {Energy Conversion and Management},
  volume  = {298},
  pages   = {117686},
  year    = {2023},
  doi     = {10.1016/j.enconman.2023.117686}
}

License

SAMA is released under the GNU General Public License v3.0 (GPL-3.0). You are free to use, copy, modify, and distribute SAMA. Any derivative works must also be released under GPL-3.0.


Contact

FAST Research Group, Western University, London, Ontario, Canada


Made with ☀️ by the FAST Research Group · Western University · GPL-3.0

Metadata

Release files for samapy 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for samapy 1.0.6
File Size Uploaded
samapy-1.0.6.tar.gz 2.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for samapy 1.0.6
File Interpreter ABI Platform
samapy-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 4.3 MB

Release files / samapy-1.0.6.tar.gz

Download URL samapy-1.0.6.tar.gz
Size 2.2 MB
Tags Source
SHA-256 checksum
How to use checksums
e797c3f40e498e029254adcc4dc43b446242961692df2c4ce334c316be3168a3
BLAKE2b-256 checksum
How to use checksums
608fe03964bfa3cad94ca8c931d9a305e2b7b048ee5d3af2718b7d6df37ebce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release files / samapy-1.0.6-py3-none-any.whl

Download URL samapy-1.0.6-py3-none-any.whl
Size 2.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
123b819180748422aa7ff694f99057a61ee1272b36e9774f7b42b9c958274c50
BLAKE2b-256 checksum
How to use checksums
b96a55fc436111a33e8e78a8ba777f9675279a0254dd9b75fdf38489954e8a18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page