ocs-rs — exact, matrix-free optimum contribution selection
Python bindings for the Rust support-first OCS solver.
Optimum contribution selection (OCS) chooses how much each candidate contributes to the next generation: maximise genetic gain bᵀc subject to a cap on the mean coancestry of the offspring, cᵀGc ≤ k, with non-negative contributions summing to one — or, in the sexed form, to one half per sex.
Exact, not heuristic. The solver returns the global optimum of the (convex) OCS program, certified by the KKT conditions at termination — verified against optiSel, a conic interior-point solver (agreement 1e-8) and an independent numerical reference (1.5e-14). Scope: continuous contributions under a single coancestry constraint; it does not do integer mate allocation.
Matrix-free. It never forms the dense n×n relationship matrix: the kinship
products come straight from the genotype matrix as Gc = εc + Z(Zᵀc)/s. That is what
lets it solve instances whose dense matrix (≈12 GiB at n = 40 000) will not fit in
memory, and why the cost follows the (tiny) active support and the marker count
rather than n².
On real marker panels it reaches the same optimum as optiSel. Given the relationship matrix, the active set is 12–132× faster than optiSel's interior-point solve at breeder-relevant coancestry caps (ΔF 0.5–2 %); and because it never forms the dense matrix, it runs at population sizes where that matrix cannot be built at all. The matrix-free path costs O(nm) per iteration, so it is the enabler at scale rather than a universal speed-up.
Install
pip install ocs-rs
Wheels ship for Linux (x86_64, aarch64), macOS (Intel, Apple silicon) and Windows,
abi3 for Python 3.9+. To build from a checkout instead: pip install maturin then
maturin develop --release from bindings/python/.
Quickstart
import numpy as np
import ocs_rs
# Z : (n, m) genotypes centred by twice the allele frequencies
# s : VanRaden scale 2 Σ p(1-p) — ocs_rs.vanraden_scale(p) computes it
res = ocs_rs.solve(Z, b, k=0.03, s=s, male=male)
print(res) # OcsResult(status='Solved', |support|=17, gain=..., ...)
print(res.support) # the handful of selected candidates
print(res.c[res.support]) # their contributions
API
solve(Z, b, k, *, s, ridge=1e-5, male=None, caps=None, max_iter=10_000, tol=1e-9)
| argument | meaning |
|---|---|
Z |
(n, m) centred genotype matrix — G = ZZᵀ/s + ridge·I, never formed |
b |
(n,) breeding values (the selection criterion) |
k |
coancestry cap: cᵀGc ≤ k |
s |
VanRaden scale 2 Σ p(1-p) |
male |
(n,) bool — give it for the sexed form (Σ_males = Σ_females = ½) |
caps |
(n,) per-candidate upper bounds c ≤ caps |
Returns an OcsResult with c, support, gain, quad, iterations, products
and status ("Solved" means KKT-optimal; only then are c/gain usable).
Links
- Source, manuscript and reproduction scripts: https://github.com/Adelagric/ocs-rs
- Archived release: https://doi.org/10.5281/zenodo.20746987
MIT licence.
Metadata
Release files for ocs-rs 0.4.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 | |
|---|---|---|---|
| ocs_rs-0.4.0.tar.gz | 781.3 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| ocs_rs-0.4.0-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| ocs_rs-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| ocs_rs-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| ocs_rs-0.4.0-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| ocs_rs-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 4.5 MB
Release files / ocs_rs-0.4.0.tar.gz
| Download URL | ocs_rs-0.4.0.tar.gz |
|---|---|
| Size | 781.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52e2b5c71f737ba4780517243addb877eae483d01acb5e28adacaec1188d8a14
|
|
BLAKE2b-256 checksum How to use checksums |
66c566145747ac80b1de3acfe1dc23cc342ae43e39ede0e55a2eb5c939ece9ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / ocs_rs-0.4.0-cp39-abi3-win_amd64.whl
| Download URL | ocs_rs-0.4.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 743.7 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f01522bf507c332d8e5088592b6c659389163ae3a045a9f8b06933c6fa627af5
|
|
BLAKE2b-256 checksum How to use checksums |
b8c02ceaf8eef47d4a0e7200ca31cdd6c0674c490332ce0c1583d09bb6f65cb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / ocs_rs-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | ocs_rs-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
edc3c9f7ac98148114a572dda261dae7554465fa0d9274a2c35b9e537d8b8607
|
|
BLAKE2b-256 checksum How to use checksums |
829d45cef113d1e1d4f018658614a126ded174826b177dc323effcd83bfe9764
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / ocs_rs-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | ocs_rs-0.4.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 610.8 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
cd844a8840223e6cb0989de72349316a6f7c7536ddccf9a2e637681d1b655d02
|
|
BLAKE2b-256 checksum How to use checksums |
e4e9bf2e0a192daa80b56181825493d77d2cef42440b23aece4ce1ad5617a5a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / ocs_rs-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | ocs_rs-0.4.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 505.9 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7d9d4e5b93ba07098a656cfe949ea8762e2976e19ccdad16d3acf12d1ac10e93
|
|
BLAKE2b-256 checksum How to use checksums |
8aad78541db2ba7ad7126017ebbd7d6dd53b21142650234be9da9b792972f589
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency logRelease files / ocs_rs-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | ocs_rs-0.4.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 815.8 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ec4c233c5f9cc7bbe545acabc7c1797c140716d1f26e3bfd6911babfcee196c9
|
|
BLAKE2b-256 checksum How to use checksums |
bd130fad19849a8824be7e5f7157b81883b554424676f8271d6b0a9da7862876
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 30, 2026.
Transparency log