Custom Penalty Solver
This is an implementation of solving constrained binary quadratic programs with custom penalties using the variational quantum eigensolver (VQE). The original work is available at arXiv:2604.20088.
Getting started
We recommend using uv (installation guide).
uv venv --python 3.12
uv pip install custom-penalty
Or you can go with the traditional:
python3.12 -m venv .venv
source .venv/bin/activate
pip install custom-penalty
Usage
It is easier to define the problem with docplex, then convert it into a QuadraticProgram:
mdl = Model()
# define variables
x = mdl.binary_var_list(2, name='x')
# define objectives
mdl.maximize(x[0] + x[1] - x[0]*x[1])
# add constraints
mdl.add_constraint(x[0] + x[1] <= 1)
mdl.add_constraint(2*x[0] + 3*x[1] == 2)
mdl.add_constraint(5*x[0] + 6*x[1] >= 5)
# convert to quadratic program
qp = from_docplex_mp(mdl)
Then, you can solve it using
cps = CustomPenaltySolver(qp)
result = cps.solve()
print(result)
For customization and more detailed guide, refer example.ipynb.
Metadata
Release files for custom-penalty 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| custom_penalty-0.2.0.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| custom_penalty-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.9 kB
Release files / custom_penalty-0.2.0.tar.gz
| Download URL | custom_penalty-0.2.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a82860a4ff4f4f290f1ed36160d38bf59e6234d8b22d98b4ce8941f69af0264b
|
|
BLAKE2b-256 checksum How to use checksums |
0fde7fa4e44b6d7afdb4db848d940450036f4cf8fa90834cf0d319305e3490a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / custom_penalty-0.2.0-py3-none-any.whl
| Download URL | custom_penalty-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7733869d91e414c4ff01221c75c3a4eed59fa15844874739cda7e3f65254f1e6
|
|
BLAKE2b-256 checksum How to use checksums |
2583f3bcd4d435d143a3dab613a0b94ea9febc9752c4a94b2354dcc9da00a5a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|