Skip to main content

ncpolopt

Sparse SDP relaxations of polynomial optimization problems with noncommuting variables — the NPA hierarchy and its relatives. ncpolopt is a modern rewrite of the GPL-3 ncpol2sdpa package: the same hierarchies and the same four solver backends, behind a fresh, typed API built on dataclasses and lazy solver discovery.

  • NPA hierarchy for noncommutative operators, plus the Moroder (PPT), steering, and RDM (reduced density matrix) hierarchies.
  • Lasserre-style hierarchies for commuting variables, with an optional chordal sparsity extension (SparsePOP-style) that splits the relaxation into independent moment blocks per clique.
  • Four solver backends: cvxpy, MOSEK, PICOS/cvxopt, and the external SDPA binary — selected by name or auto-detected.
  • Moment expressions (MomentEntry) instead of a string DSL for writing conditions on the moment matrix directly.

Installation

Requires Python 3.13+. The core package needs only numpy, scipy, and sympy; install a solver extra to actually solve:

uv pip install ncpolopt[cvxpy]        # or: pip install ncpolopt[cvxpy]

Available extras: cvxpy, mosek, cvxopt (PICOS + cvxopt), chordal (chompack, only needed for the chompack completion method), and all. With no solver installed the package still imports and builds relaxations; only solving raises a SolverError telling you which extra to install.

Quickstart

A tiny noncommutative problem: two Hermitian operators x0, x1, minimize the anticommutator x0*x1 + x1*x0 under the constraint x1 - x1² + ½ ≥ 0 and the projection x0² = x0:

import ncpolopt as nc

X = nc.generate_operators("x", 2, hermitian=True)
problem = nc.Problem(
    X,
    objective=X[0] * X[1] + X[1] * X[0],
    inequalities=[-X[1] ** 2 + X[1] + 0.5],
    substitutions={X[0] ** 2: X[0]},
)
solution = problem.solve(level=2)
print(solution.primal)   # -0.75

Object model

Work flows through three layers, each a frozen dataclass:

  1. Problem — the symbolic model: variables (a list of lists for multipartite problems), objective, polynomial and moment constraints, substitution rules. Reusable; building a relaxation never mutates it.
  2. NpaRelaxation — the SDP at a hierarchy level, built by problem.relaxation(level) or subclass hierarchies MoroderHierarchy, SteeringHierarchy, RdmHierarchy. The assembled SDP data (relaxation.sdp) is a frozen blockwise COO representation.
  3. Solution — the immutable solve result (primal, dual, status, x_mat, y_mat) with extraction helpers: monomial_value(), dual_value(), dual_block(), sos_decomposition(), solution_ranks().

Command line

ncpolopt                # version, platform, detected solvers
ncpolopt --version

Development

uv sync --group dev
uv run pytest
uv run ruff check .

License

GPL-3.0-only. This package is derived from ncpol2sdpa, which is Copyright (C) 2012-2016 Peter Wittek and contributors.

Metadata

Release files for ncpolopt 0.1.0

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

Source distribution (sdist)

Source distribution for ncpolopt 0.1.0
File Size Uploaded
ncpolopt-0.1.0.tar.gz 61.4 kB Details

Built distribution (wheel)

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

Total release size: 140.4 kB

Release files / ncpolopt-0.1.0.tar.gz

Download URL ncpolopt-0.1.0.tar.gz
Size 61.4 kB
Tags Source
SHA-256 checksum
How to use checksums
72905df7518f651fc479763af1fab411d97150b1831069663ed53f2d45c200c3
BLAKE2b-256 checksum
How to use checksums
f0e68c18307431d19af4c1fdddebb278bed4947a5563ebb9d4300cdf6a1faa43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / ncpolopt-0.1.0-py3-none-any.whl

Download URL ncpolopt-0.1.0-py3-none-any.whl
Size 79.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec9b50db59bfa7b80c57e1b9c83459bba8a3b9ae7fd585a79fe90b2dc1bbb1bd
BLAKE2b-256 checksum
How to use checksums
bc2f101fab6f5e6fc12775576e5402910bb23b200142039a84a0fbf6514aec27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.0 This release

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