Skip to main content

QuGrid

CI Python 3.10+ License: MIT Docs

Quantum computing for power system research: from a MATPOWER case to a quantum algorithm in three lines.

import qugrid as qg

result = qg.solve(qg.problems.Islanding(qg.cases.case9()), solver="qaoa", seed=0)
print(result.summary())
QuGrid result | solver=qaoa | Islanding(n=9)
  objective          27.0512
  feasible           yes
  gap vs reference   0%
  P(optimum)         0.010
  n_cut              2
  island_power_mw    (10.3, -5.0)
  islands_connected  (True, True)
  resources          wall_time_s=0.37, n_qubits=9, p=2, evaluations=1200, restarts=3, seed=0

Engineering units, the same-run classical reference, and the honest success probability — in the first screenful. QuGrid is for power system researchers who want to study quantum algorithms without leaving their field's tools, units, and standards of evidence — and for quantum researchers who want grid problems formulated the way power engineers will actually review them.

English · 中文 · Documentation · 10-min quickstart · 十分钟上手


Why this library exists

Between MATPOWER/pandapower and Qiskit/Ocean/PennyLane there is a gap where research quality goes to die: hand-rolled QUBO encodings with undocumented penalty weights, results reported as Ising energies instead of megawatts, and comparisons that quietly omit the classical solver the field actually uses. QuGrid closes that gap with three layers, each honest about what it does:

QuGrid architecture

  1. Power problems speak engineering units. UnitCommitment, Islanding, PMUPlacement, EconomicDispatchQUBO, dc_power_flow, N-1 screening_dataset, wind scenarios — built on a Network class that keeps MATPOWER column semantics, loads MATPOWER .m files directly, converts from pandapower, and bundles seven standard test cases (PJM 5-bus to IEEE 118-bus).
  2. Encodings are exact, tested algebra: QUBO ⇄ Ising with pinned conventions, a QUBOBuilder with exact squared-penalty expansion for your own formulations, LinearSystemProblem with power-of-two padding and Hermitian dilation. The test suite enforces all of it at 1e-9.
  3. Solvers run on a pure-NumPy statevector core — QAOA, VQE, HHL, VQLS, fidelity quantum kernels, a quantum Boltzmann machine — with zero quantum SDK dependencies, next to the classical baselines every claim must face: exact enumeration, seeded simulated annealing, LU, Newton–Raphson. The same problem objects export to Qiskit, D-Wave Ocean, and PennyLane when you want vendor stacks or hardware.

Every solver returns the same Result: the decoded engineering answer, feasibility of the original constraints (not the penalty proxy), the gap() to a classical reference computed in the same run, the success probability even an ideal noise-free device would face, and the resource bill.

Sixty seconds of evidence

Controlled islanding of the WSCC 9-bus system. The exact QUBO optimum opens 2 lines and leaves island imbalances of +10.3 / −5.0 MW; QAOA at depth 2 finds the same plan:

Islanding of the WSCC 9-bus system

HHL on DC power flow, with the two numbers most papers do not print together — the error and what each digit of precision costs in postselection probability:

HHL error anatomy

Numbers from the self-validating example scripts (each script asserts its own claims and exits nonzero if one stops holding):

Study Quantum result Classical reference, same run
DC power flow, HHL @ 8 clock qubits relative error 2.5e-3, max angle error 0.0067° LU solution (exact)
Unit commitment, 2 units × 2 periods exact QUBO = SA = $2,908.00; discretization gap $0.00 UC enumeration: $2,908.00
Islanding, WSCC 9-bus exact = SA = QAOA(p=2), gap 0 exact enumeration
PMU placement, 9-bus / 14-bus SA finds 3 / 4 PMUs, full observability exact minimum: 3 / 4
Quantum kernel on N-1 screening test accuracy 1.00 at tuned bandwidth, 0.50 mistuned RBF kernel: 1.00

Install

pip install qugrid          # core: NumPy, SciPy, matplotlib, pandas — no quantum SDK
pip install "qugrid[all]"   # + qiskit, dwave, pennylane, pandapower adapters
qugrid demo                 # 30-second end-to-end check

Choose your on-ramp

You are… Start here Time
a power researcher, new to quantum quickstartquantum primer written for you → notebook 01 40 min
a quantum researcher, new to grids power primer written for you → notebook 02 40 min
here to run experiments cheatsheetexample zoo now
中文读者 十分钟上手 · README 中文版 10 min

Five executed notebooks take you from zero quantum knowledge to running your own studies — notebooks/01_hello_qugrid (15 min) through 05_qml_for_screening (30 min), markdown-heavy, every term defined in power system vocabulary first. The learning paths page sequences them for each background.

The example zoo

Ten single-file studies in examples/, in the spirit of CleanRL: self-contained, seeded, finished in minutes on a laptop, self-validating, each with its classical baseline in the same file. Copy one, swap in your case file, and you have the skeleton of a paper's experiment section.

# Study # Study
01 DC power flow via HHL: error anatomy 06 QAOA depth study on islanding
02 Unit commitment via QAOA, honest success probabilities 07 Seed-swept solver benchmark → LaTeX table
03 Controlled islanding of the 9-bus system 08 Quantum kernel vs RBF on N-1 screening
04 PMU placement with slack-bit inequality encoding 09 Quantum Boltzmann machine wind scenarios
05 What discretization costs: encoding vs solver error 10 Hybrid Newton–Raphson with a variational linear solver

The honesty box

No quantum device today beats tuned classical solvers on any power system problem, and this library will never imply otherwise. DC power flow is solved by sparse LU in microseconds; national-scale unit commitment is solved by MIP nightly. What QuGrid makes easy is the research that is real in 2026: encoding costs, error anatomy, resource scaling, algorithm behavior under discretization — always with the classical baseline in the same table. The honest benchmarking guide is the six-rule version of this paragraph; the API enforces most of it by default.

Positioning

  • Qiskit Optimization, OpenQAOA, D-Wave Ocean operate on abstract optimization models with no grid semantics. QuGrid owns what happens before (credible grid formulations, documented penalty weights, discretization accounting) and after (decoding to MW, feasibility of the real constraints, field-standard baselines) — and exports to all three in one call.
  • MATPOWER and pandapower stay the source of truth for grid data and classical power flow; QuGrid consumes their formats rather than replacing them.
  • CleanRL and Tianshou inspired the shape: a small tested core plus single-file, self-validating research scripts.

Citing

If QuGrid supports your research, cite it via CITATION.cff (GitHub's "Cite this repository" button) — and cite the algorithm papers referenced in each solver's docstring; HHL, QAOA, VQLS, and the quantum power flow literature are their authors' contributions, not this library's.

Contributing

The highest-value contribution is a problem formulation from your own research: one file, one test, and every solver, benchmark, and plot in the library applies to it automatically. See CONTRIBUTING.md and the formulation proposal template.

License

MIT. Bundled test case data derives from MATPOWER test cases (BSD 3-clause).

Download files

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

Source Distribution

qugrid-0.1.0.tar.gz (88.0 kB view details)

Uploaded Source

Built Distribution

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

qugrid-0.1.0-py3-none-any.whl (92.9 kB view details)

Uploaded Python 3

File details

Details for the file qugrid-0.1.0.tar.gz.

File metadata

  • Download URL: qugrid-0.1.0.tar.gz
  • Upload date:
  • Size: 88.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.27 {"installer":{"name":"uv","version":"0.11.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qugrid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 27f726f7ccda19c9227d6da34596cfc3c63218ff285cf94151636cd1001d550f
MD5 a70761079dc880dd115ff7bd0d05f6d5
BLAKE2b-256 866cad62219dfa41f9f057a5275d40c5e6c65c1435bc6aec1b539f4e97f01477

See more details on using hashes here.

File details

Details for the file qugrid-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for qugrid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd9048ea05ea92eb75731f2d67e4b49e988b9276a99ce126bb76e99240b7b1bf
MD5 cc5166741f22c7280c89f4a9f3cb37ac
BLAKE2b-256 7b49779a462c6ea649c36c19cac571df87a0fd74664ca71caa2aada2dab84b5f

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

Supported by

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