Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

XQCP -- X-Quadratic Constraint Programmer

A constraint-programming DSL that compiles a problem description into three XQVM assembly programs: an encoder, a verifier, and a decoder. See Three Programs for what those three are and why there are three.

Install

pip install xqcp

A complete example

Max-Cut for three nodes -- the same graph Quadratic Models derives by hand -- built with Problem and compiled to .xqasm:

from xqcp import Problem, Types
from xqvm_py import XQMXDomain

problem = Problem("Triangle")
n = problem.input("n", type=Types.Int)
edges = problem.input("edges", type=Types.Vec)
problem.define_model(size=n, domain=XQMXDomain.BINARY)

edge_count = problem.stow("edge_count", edges.veclen() // 3)
with problem.range(0, edge_count) as e:
    offset = e * 3
    i = problem.stow("i", edges.get(offset))
    j = problem.stow("j", edges.get(offset + 1))
    w = problem.stow("w", edges.get(offset + 2))
    problem.model.linear[i].add(-w)
    problem.model.linear[j].add(-w)
    problem.model.quadratic[i, j].add(w * 2)

partition = problem.output("partition", type=Types.Vec)
with problem.range(0, n) as node:
    partition.append(problem.sample.getline(node))

programs = problem.compile()
print(programs.encoder.count("\n"), "lines in the compiled encoder")
# 57 lines in the compiled encoder

programs.encoder builds the model; programs.verifier checks a sample against it and computes its energy; programs.decoder reads a sample back into a partition. Each is a standalone .xqasm string, runnable through any XQVM interpreter.

How it works

Problem records every DSL call (input, define_model, range, stow, model.linear[i].add(w), and the rest) as an Action. Nothing is assembled until compile() runs: it walks the recorded actions once per program and emits assembly with automatic register allocation and loop nesting.

DSL reference

The full DSL -- inputs, expressions, objectives, constraints, control flow, outputs, and what compile() produces -- is Modelling, eight chapters built around this exact package. The normative reference is spec/xqcp/SPEC.md; this package follows it, and any divergence here is a bug.

Examples

Fourteen complete problems built with this DSL, from Max-Cut to Travelling Salesman, are listed in the example gallery.

Also see

  • xqvm_py -- pure-Python reference VM that runs the compiled programs.
  • xqffi -- pyo3 FFI bindings to the Rust runtime.
  • xqsa -- solver adapters for the models this package builds.
  • xquad -- umbrella meta-package.

License

AGPL-3.0-or-later.

Release files for xqcp 0.4.0rc2

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

Source distribution (sdist)

Source distribution for xqcp 0.4.0rc2
File Size Uploaded
xqcp-0.4.0rc2.tar.gz 39.4 kB Details

Built distribution (wheel)

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

Total release size: 68.7 kB

Release files / xqcp-0.4.0rc2.tar.gz

Download URL xqcp-0.4.0rc2.tar.gz
Size 39.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ace36cbbd1210b8c0ccd97f7984f06135b496a72f6c0967fd891d48820d0363b
BLAKE2b-256 checksum
How to use checksums
81ac2e3c915474c1ffb299e70b2cef120509e173c53c1869f94a4ea5bc1155b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / xqcp-0.4.0rc2-py3-none-any.whl

Download URL xqcp-0.4.0rc2-py3-none-any.whl
Size 29.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b412d8433e707862c767e69da063eddbfec143d39d6d1a6daf0b80b1f10f5f3e
BLAKE2b-256 checksum
How to use checksums
e6f831df32fde5aebff4b815a068f1f3ce76fb17e4c567906d995a0276f1ab91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.5
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