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).

MIT licence.

Metadata

Release files for ocs-rs 0.3.1

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.1
File Size Uploaded
ocs_rs-0.3.1.tar.gz 827.3 kB Details

Built distributions (wheels)

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

Download URL ocs_rs-0.3.1.tar.gz
Size 827.3 kB
Tags Source
SHA-256 checksum
How to use checksums
02b4a45d116dbe199c4cd0bfc3ad712c70b573af322c380321d67da523fd82de
BLAKE2b-256 checksum
How to use checksums
414044f8d0755daf5487111754f3ea5968ba6d52b6d6eb3782dc659b694d854f
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 20, 2026.

Transparency log

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

Download URL ocs_rs-0.3.1-cp39-abi3-win_amd64.whl
Size 743.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3f6c32c620cac570e0d089b722380acd0e4753a27fb385df43f276af2136bb35
BLAKE2b-256 checksum
How to use checksums
7bd7bd97b2a1b9b5f746bd563ee5d50de198bd4143d1c843148751e1909beab2
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 20, 2026.

Transparency log

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

Download URL ocs_rs-0.3.1-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
7e47467bf355ebdb522b4c20322437bb24926ed26d3303a5425c6b7593abd566
BLAKE2b-256 checksum
How to use checksums
652ea244f1f4492840e13550152ef588895762602172b52809c79295b612d5b3
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 20, 2026.

Transparency log

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

Download URL ocs_rs-0.3.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 610.0 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
2e81aaaa1d210c8bda82244ec22de470dddd9faf8df53d84477d5df454dba561
BLAKE2b-256 checksum
How to use checksums
9e6042e7d277db3c5bbdad6f59ad6b324cf58a19c9cd834a1f76b33b61df9656
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 20, 2026.

Transparency log

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

Download URL ocs_rs-0.3.1-cp39-abi3-macosx_11_0_arm64.whl
Size 505.7 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1b2629ca42a0dc5587da068bc5a65bbd6c22c40a8563c35236849206954ba0b1
BLAKE2b-256 checksum
How to use checksums
efc46075610c16b081fea4d1f272270bfdf272da414ddfd6e330acc04af50d1e
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 20, 2026.

Transparency log

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

Download URL ocs_rs-0.3.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 816.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
17010566bda6f80a94630c36dea77cea83aeefd973a3d9abd93c027027922c71
BLAKE2b-256 checksum
How to use checksums
c9ca32a8430316c7a7d25f27eef174df8e5470d4c3a111b89b7e850100551985
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 20, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

6 release files

This release

0.3.1 This release

6 release files

0.3.0

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