pymoors
Overview
pymoors is the python implementation of the moo-rs project. It's an extension crate (via pyo3) exposing moors algorithms with a Pythonic API
Inspired by the amazing Python project pymoo, pymoors delivers both the speed of Rust and the ease-of-use of Python.
Installation
pip install pymoors
Quickstart
import numpy as np
from pymoors import (
Nsga2,
RandomSamplingBinary,
BitFlipMutation,
SinglePointBinaryCrossover,
ExactDuplicatesCleaner,
)
from pymoors.typing import TwoDArray
PROFITS = np.array([2, 3, 6, 1, 4])
QUALITIES = np.array([5, 2, 1, 6, 4])
WEIGHTS = np.array([2, 3, 6, 2, 3])
CAPACITY = 7
def knapsack_fitness(genes: TwoDArray) -> TwoDArray:
# Calculate total profit
profit_sum = np.sum(PROFITS * genes, axis=1, keepdims=True)
# Calculate total quality
quality_sum = np.sum(QUALITIES * genes, axis=1, keepdims=True)
# We want to maximize profit and quality,
# so in pymoors we minimize the negative values
f1 = -profit_sum
f2 = -quality_sum
return np.column_stack([f1, f2])
def knapsack_constraint(genes: TwoDArray) -> TwoDArray:
# Calculate total weight
weight_sum = np.sum(WEIGHTS * genes, axis=1, keepdims=True)
# Inequality constraint: weight_sum <= capacity
return weight_sum - CAPACITY
algorithm = Nsga2(
sampler=RandomSamplingBinary(),
crossover=SinglePointBinaryCrossover(),
mutation=BitFlipMutation(gene_mutation_rate=0.5),
fitness=knapsack_fitness,
constraints_fn=knapsack_constraint,
duplicates_cleaner=ExactDuplicatesCleaner(),
num_vars=5,
num_objectives=1,
num_constraints=1,
population_size=32,
num_offsprings=32,
num_iterations=10,
mutation_rate=0.1,
crossover_rate=0.9,
keep_infeasible=False,
)
algorithm.run()
pop = algorithm.population
# Get genes
>>> pop.genes
array([[1., 0., 0., 1., 1.],
[0., 1., 0., 0., 1.],
[1., 1., 0., 1., 0.],
...])
# Get fitness
>>> pop.fitness
array([[ -7., -15.],
[ -7., -6.],
[ -6., -13.],
...])
# Get constraints_fn evaluation
>>> pop.constraints_fn
array([[ 0.],
[-1.],
[ 0.],
...])
# Get rank
>>> pop.rank
array([0, 1, 1, 2, ...], dtype=uint64)
# Get best individuals
>>> pop.best
[<pymoors.schemas.Individual object at 0x...>]
>>> pop.best[0].genes
array([1., 0., 0., 1., 1.])
>>> pop.best[0].fitness
array([ -7., -15.])
>>> pop.best[0].constraints_fn
array([0.])
In this small example, the algorithm finds a single solution on the Pareto front: selecting the items (A, D, E), with a profit of 7 and a quality of 15. This means there is no other combination that can match or exceed both objectives without exceeding the knapsack capacity (7).
Once the algorithm finishes, it stores a population attribute that contains all the individuals evaluated during the search.
Contributing
Contributions welcome! Please read the contribution guide and open issues or PRs in the relevant crate’s repository
License
This project is licensed under the MIT License.
Metadata
Release files for pymoors 0.2.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 18.9 MB
Release files / pymoors-0.2.6-cp313-cp313-win_amd64.whl
| Download URL | pymoors-0.2.6-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 812.5 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ab1941c2210ec75bf4cd8605af7415ea1841a30bb9a2d583e7d1de720e9369a2
|
|
BLAKE2b-256 checksum How to use checksums |
21bc1bd26a6349e5d9a18ebdc038956a36014118ef1a5b92236151c714913235
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pymoors-0.2.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
1c98e0631571d79f43bfd3d0bb01aceea553f240e2a4dcf261e818596e587032
|
|
BLAKE2b-256 checksum How to use checksums |
2b8f72ffdb397b7cd5252418529399f0dd4000cfcdbb137972648929adb41d38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pymoors-0.2.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 999.2 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
307175a21c62f1fd407092e83e8e2f142de406ed4a382e9afa3b1e42c0e9bcf6
|
|
BLAKE2b-256 checksum How to use checksums |
37c4bd6e142811cfafe33ec59a1b643e0a53f883cc0a1b758d84ec0e718fd42c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | pymoors-0.2.6-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 842.5 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4124d0d5d7f7817587ee3a9b8990ed0e7eed7ffefb2e921cd356d79f18738117
|
|
BLAKE2b-256 checksum How to use checksums |
8b5e03e6b80d797fc5c5d5f50b6f962c8d518723b620ff505bc8c79017e00be4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl
| Download URL | pymoors-0.2.6-cp313-cp313-macosx_10_12_x86_64.whl |
|---|---|
| Size | 973.7 kB |
| Tags | CPython 3.13 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
171e4d689bb8ceca08daf283cadea7f4ef742761142f7b59230d8f13158d6828
|
|
BLAKE2b-256 checksum How to use checksums |
bf4efe97e727f6cd7865819a0fff58072225fdb376845ae3380bfff45db101ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp312-cp312-win_amd64.whl
| Download URL | pymoors-0.2.6-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 812.9 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
b793656e7aea939aa832b01ec512b67a371b3b819f086e9fff6c2a529dc90c1f
|
|
BLAKE2b-256 checksum How to use checksums |
11fc926969fc067db98e270c2b5e8401f7bc0530499db4227f0ea15b838c4cd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pymoors-0.2.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
34bf18812672c0ac6af3ef570d2901b16a0a80f7a8b57e24089cc3bae424735c
|
|
BLAKE2b-256 checksum How to use checksums |
b5f8bb54c27a02020ed24695381fd0e75369866085ea951872a436ffbcc8a927
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pymoors-0.2.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 999.9 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
8ec9a33fdbfb4c8ada75ef9bbf27e4dc8bd288c63dd50460e829a25a4ae3880d
|
|
BLAKE2b-256 checksum How to use checksums |
3942123115704eb8e867bfb32b7c43eb10de1c9b5b975e9668b4a70ee1e1822f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | pymoors-0.2.6-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 842.7 kB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5445893cd4f97e066c0cdcbfd92be4b002508a367b0abb6dbe1900e39f30496c
|
|
BLAKE2b-256 checksum How to use checksums |
b691ab644bb4f985cfe855e9bfbfa65e409da80d4861f0ccaca2622301d945c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp312-cp312-macosx_10_12_x86_64.whl
| Download URL | pymoors-0.2.6-cp312-cp312-macosx_10_12_x86_64.whl |
|---|---|
| Size | 974.2 kB |
| Tags | CPython 3.12 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8c3b38c4b6ebacc0086e5348b61290cf6c43bcd36c7bbdb9babd626046492d33
|
|
BLAKE2b-256 checksum How to use checksums |
0509c158bd73846c6b3184dd346dc3e8e0227e3a44c2be1f1302f80a245500ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp311-cp311-win_amd64.whl
| Download URL | pymoors-0.2.6-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 811.6 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
aa04bbd242b97ff509d20cb6e01cebe8434584fcbfd82ab7ec4fbc10441a92e2
|
|
BLAKE2b-256 checksum How to use checksums |
f1d020aea0ef7554d087f04e2fb3e42dc9440b50cf82a9a4972f85410fe38361
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pymoors-0.2.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e7e6a84e88e89b793876f5efa5cbe5ca1b9372bbde045dd238a5d4218435d397
|
|
BLAKE2b-256 checksum How to use checksums |
2cba0210840044d460e7065e74be7ac9b37602820736480849cdebef1b2f9c46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pymoors-0.2.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
1b60a968bb7d0938529f245a1c94623ec1cdcfde92667958528aaa1cd3eca52d
|
|
BLAKE2b-256 checksum How to use checksums |
5e6074d66a3fade7b2a35836bd04800aef66947c19937315ca1d9b247473f14c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | pymoors-0.2.6-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 854.6 kB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a2fac4f8f02a4502de77b21a9ab75ca7d22c020053fd857883132f574881774d
|
|
BLAKE2b-256 checksum How to use checksums |
9ca45f682961868d864087726a247faeafb33beccf3931da2e5cbca77cc99074
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp311-cp311-macosx_10_12_x86_64.whl
| Download URL | pymoors-0.2.6-cp311-cp311-macosx_10_12_x86_64.whl |
|---|---|
| Size | 978.0 kB |
| Tags | CPython 3.11 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
e2b8aed724607df86f88c6fb9cad3c8cf441aa34f89293add8b98881e15de0ae
|
|
BLAKE2b-256 checksum How to use checksums |
c30a6a0decfcd87043986ea71b43c9eb7c271fd2d82d0734add406c0f9b0cb0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp310-cp310-win_amd64.whl
| Download URL | pymoors-0.2.6-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 812.7 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
61731806fe24be5d65edcc44bc888787bd3e3c01e30069279cda83a01b1ac3db
|
|
BLAKE2b-256 checksum How to use checksums |
e717a3b93a2e3dc286afbab9d4c7dca3a96430feb9c60018be003ef43a78d7a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | pymoors-0.2.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
4fc98fe86952aaa24c49322c9a8150d5563e1176dcea206cf16262579eaf74b5
|
|
BLAKE2b-256 checksum How to use checksums |
ff00878f393a71449e5962043e6a4e448cbb74fc61e07af7bf150fb8efc0c4df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | pymoors-0.2.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
4ef5067cf9287d16cae2da20c74279c3f7f6075fb6676b937a0f521f1bc7d886
|
|
BLAKE2b-256 checksum How to use checksums |
1bf468749dcba2b60431cb869f3b6a9329ca18113155e1a7718f41adc86673f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymoors-0.2.6-cp310-cp310-macosx_11_0_arm64.whl
| Download URL | pymoors-0.2.6-cp310-cp310-macosx_11_0_arm64.whl |
|---|---|
| Size | 854.8 kB |
| Tags | CPython 3.10 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b9300f76748570e2661a10664e0f4443f3594bd65d8f020aca66d2d38e1cf79a
|
|
BLAKE2b-256 checksum How to use checksums |
b753fe116e37100f85e95e257fa55979519d6dc83fb6282dc81acb668652f7e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / pymoors-0.2.6-cp310-cp310-macosx_10_12_x86_64.whl
| Download URL | pymoors-0.2.6-cp310-cp310-macosx_10_12_x86_64.whl |
|---|---|
| Size | 978.3 kB |
| Tags | CPython 3.10 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
6a3d2ad963bb9dfdcd55f2171d522b83ff3a3764c4ed08194680c006258c3084
|
|
BLAKE2b-256 checksum How to use checksums |
adf09fa17cb1f1f695071338bdf7ee1c1c898ecb3d6de70b74785576704acda9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Security for pymoors 0.2.6
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.