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 90–2280× faster.

Install

pip install maturin
maturin develop --release        # from bindings/python/ in the repository

(A PyPI release will follow; for now build from source.)

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.2.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.2.0
File Size Uploaded
ocs_rs-0.2.0.tar.gz 459.1 kB Details

Built distributions (wheels)

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

Total release size: 4.1 MB

Release files / ocs_rs-0.2.0.tar.gz

Download URL ocs_rs-0.2.0.tar.gz
Size 459.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2afb4ea2a8bc94615e6476298fe08369cd62007b998d0c9b6f875eaed6b8f4e5
BLAKE2b-256 checksum
How to use checksums
93f1bad104357d01b4b47d653a574cf18a6bd0978cf496c6bb887e3f9a98300a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 28, 2026.

Transparency log

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

Download URL ocs_rs-0.2.0-cp39-abi3-win_amd64.whl
Size 741.7 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6e7525cf4fd94b5a4e47e969f95370066f5223f817a1b2aa1cd5a5e694f70ee9
BLAKE2b-256 checksum
How to use checksums
b8164cdb7dcbb449ad95301bd5b7e564edf3dadee56ede67eba56b5e7dca103a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 28, 2026.

Transparency log

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

Download URL ocs_rs-0.2.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
f4d6bac8d4d28f3bd6fe09125058efaec7e5db54c1fb10079c3970a865e328ab
BLAKE2b-256 checksum
How to use checksums
759a95dd11ffb1d40f6d78745b687120ef099ef082867e07f07d7e79fea8fc46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 28, 2026.

Transparency log

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

Download URL ocs_rs-0.2.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 611.3 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
0d46db06d4447718ea585a1c2c3a9180bee59d29a2e90435d0f186df8a07e9d5
BLAKE2b-256 checksum
How to use checksums
1eca8e24d0912a23dbdc9ad95a035f80f22abef2f50c2dda3928e17de2edf2c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 28, 2026.

Transparency log

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

Download URL ocs_rs-0.2.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
e2a22237a21d553ab5009b1d715f6f47ff68fe6ac0e9fca873ea6925fc70b2a1
BLAKE2b-256 checksum
How to use checksums
ca04012ff5957f1bbb9ad2da1e32174b5d111935e5159e359d21b15134807e87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 28, 2026.

Transparency log

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

Download URL ocs_rs-0.2.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
5342dcffd2b66423602a213712dde6cc3e124fbc61ce081b848aa006b0819e98
BLAKE2b-256 checksum
How to use checksums
ed71d10fc8f54183b6972d3f2e5026a210ad509267e97c4a9dd7a8c2a3d0826f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.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 28, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

6 release files

0.3.1

6 release files

0.3.0

6 release files

This release

0.2.0 This release

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