Skip to main content

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

MIT licence.

Metadata

Release files for ocs-rs 0.3.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 ocs-rs 0.3.0
File Size Uploaded
ocs_rs-0.3.0.tar.gz 813.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for ocs-rs 0.3.0
File
ocs_rs-0.3.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
ocs_rs-0.3.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.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details
ocs_rs-0.3.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details
ocs_rs-0.3.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.3.0.tar.gz

Download URL ocs_rs-0.3.0.tar.gz
Size 813.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7e911a325aad044557e94c4915d7d59615d272654c031a06a91391fa5ffb5e7e
BLAKE2b-256 checksum
How to use checksums
7e47f2216c6e4fd8dfd8e421953583b3cabb5186e661ea3803ad6048f5ce62dc
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 Jul 30, 2026.

Transparency log

Release files / ocs_rs-0.3.0-cp39-abi3-win_amd64.whl

Download URL ocs_rs-0.3.0-cp39-abi3-win_amd64.whl
Size 742.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d1dba76ac65684a1fb5877bdba949d42ef8088bb4ddd9e3046d76ba1a26211c4
BLAKE2b-256 checksum
How to use checksums
b784c29d529ff9eb359c7fe9baec1c304914c6028f4e9c0860f202d4c50446e9
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 Jul 30, 2026.

Transparency log

Release files / ocs_rs-0.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL ocs_rs-0.3.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
f95f1c3b6fc4ae8339d2ecde5d1dae60473800cc0f0bf166fcac6199313733ef
BLAKE2b-256 checksum
How to use checksums
6c164e4650d8376e67bc75d64db4cbc061a5ceaccfed8cb659de40d254924388
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 Jul 30, 2026.

Transparency log

Release files / ocs_rs-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL ocs_rs-0.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 611.5 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a013f0604fa27ba3518c0e608d975b4eddbbcaba8212bb2d16e81e254a2a3e5c
BLAKE2b-256 checksum
How to use checksums
60968150274ac24d0c6ba12306c933caa7e05aebe97c73fdbb74c435874b582c
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 Jul 30, 2026.

Transparency log

Release files / ocs_rs-0.3.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL ocs_rs-0.3.0-cp39-abi3-macosx_11_0_arm64.whl
Size 511.9 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6ca8fabcbbb79db52f42531e22f738987a4c321ffc6c9f164f431da68300729c
BLAKE2b-256 checksum
How to use checksums
c0dce17264679d8ec250e798957049eca87c6c521ae05b0cfb33b3dfa44edc7b
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 Jul 30, 2026.

Transparency log

Release files / ocs_rs-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL ocs_rs-0.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 822.3 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a0d261dfbefa94be13072258f2301ebf7512945fd67cb60f624b220a975e26a3
BLAKE2b-256 checksum
How to use checksums
2a25b35cdabd2fa21b5817cb039dda64b28dae7f7b4902024ea5f22f46f620a8
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 Jul 30, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

6 release files

0.3.1

6 release files

This release

0.3.0 This release

6 release files

0.2.0

6 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