Skip to content

Commit

Permalink
Refactor repository: sub-crates under crates directory (#226)
Browse files Browse the repository at this point in the history
* Move sub-crates under crates directory

* Move python binding under python

* Adjust Python tools: use uv, ruff

* Adjust gitignore and remove poetry.lock

* Add uv lock

* Adjust pyproject, gitignore, pytest

* Adjust python action

* Adjust pytest action

* ruff format

* Adjust pytest action

* Fix ubuntu os name

* Adjust toml

* Use maturin action

* Adjust toml

* Import all rust symbols

* Add pre-commit

* Fix format

* DRY dependencies
  • Loading branch information
relf authored Jan 2, 2025
1 parent 67fb321 commit f6e1299
Show file tree
Hide file tree
Showing 95 changed files with 678 additions and 336 deletions.
53 changes: 35 additions & 18 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,52 @@ jobs:
- ubuntu-latest
- windows-latest
- macos-latest
env:
UV_CACHE_DIR: /tmp/.uv-cache
RUST_BACKTRACE: 1

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up uv
if: ${{ matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' }}
run: curl -LsSf https://astral.sh/uv/install.sh | sh

- name: Set up uv
if: ${{ matrix.os == 'windows-latest' }}
run: irm https://astral.sh/uv/install.ps1 | iex
shell: powershell

- name: Install Rust
uses: actions-rs/toolchain@v1
- name: Cache folder for uv
uses: actions/cache@v4
with:
toolchain: stable
default: true
path: /tmp/.uv-cache
key: uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
restore-keys: |
uv-${{ runner.os }}-${{ hashFiles('uv.lock') }}
uv-${{ runner.os }}
- name: Log active toolchain
run: rustup show
- name: Install the project
working-directory: python
run: uv sync --all-extras --dev --python ${{ matrix.python-version }}

- name: Install test dependencies
- name: Build the wrapper
uses: PyO3/maturin-action@v1
with:
working-directory: python
command: develop
args: --release
sccache: 'true'

- name: Run linter and formatter
working-directory: python
run: |
python -m pip install --upgrade pip
pip install maturin numpy pytest poetry
uv run ruff check
uv run ruff format --check
- name: Test Python
working-directory: python
run: |
poetry install
poetry run maturin develop --release
poetry run pytest
uv run pytest
shell: bash

env:
RUST_BACKTRACE: 1
5 changes: 5 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
working-directory: python
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
Expand All @@ -51,6 +52,7 @@ jobs:
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
working-directory: python
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
Expand All @@ -73,6 +75,7 @@ jobs:
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
working-directory: python
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
Expand All @@ -89,6 +92,7 @@ jobs:
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
working-directory: python
command: build
args: --sdist --out dist --release
- name: Upload sdist
Expand All @@ -111,5 +115,6 @@ jobs:
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
working-directory: python
command: upload
args: --non-interactive --skip-existing *
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ mopta08_elf64.bin
joss/paper.jats
joss/paper.pdf

# Run history
history*
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.5
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
16 changes: 0 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 26 additions & 35 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,67 +1,58 @@
[package]
name = "egobox"
[workspace]
members = ["crates/*", "python"]
resolver = "2"

[workspace.package]
license = "Apache-2.0"
edition = "2021"
readme = "README.md"
version = "0.25.0"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
homepage = "https://github.com/relf/egobox"
documentation = "https://pypi.org/project/egobox"
description = "A toolbox for efficient global optimization"
license = "Apache-2.0"
repository = "https://github.com/relf/egobox"
keywords = [
"machine-learning",
"doe",
"gaussian-process",
"mixture-of-experts",
"optimization",
"machine-learning",
"doe",
"gaussian-process",
"mixture-of-experts",
"optimization",
]
categories = ["algorithms", "mathematics", "science"]
rust-version = "1.74" # MSVR

exclude = [".github/"]

[lib]
name = "egobox"
crate-type = ["cdylib"]

[features]
default = []

nlopt = ["egobox-ego/nlopt", "egobox-gp/nlopt"]
serializable-gp = ["egobox-gp/serializable"]
persistent-moe = ["egobox-moe/persistent"]
blas = ["ndarray/blas", "egobox-gp/blas", "egobox-moe/blas", "egobox-ego/blas"]

[dependencies]
egobox-doe = { version = "0.25.0", path = "./doe" }
egobox-gp = { version = "0.25.0", path = "./gp" }
egobox-moe = { version = "0.25.0", path = "./moe", features = ["persistent"] }
egobox-ego = { version = "0.25.0", path = "./ego", features = ["persistent"] }
[workspace.metadata.release]
shared-version = true
tag-name = "{{version}}"

[workspace.dependencies]
linfa = { version = "0.7", default-features = false }

ndarray = { version = "0.15", features = ["rayon", "approx"] }
ndarray-rand = "0.14"
ndarray-stats = "0.5"
ndarray-npy = "0.8"

num-traits = "0.2"

thiserror = "1"
anyhow = "1"
rayon = "1"

rand_xoshiro = "0.6"
libm = "0.2"
finitediff = { version = "0.1.4", features = ["ndarray"] }
env_logger = "0.11"
log = "0.4"

pyo3 = { version = "0.22", features = ["extension-module"] }
pyo3-log = "0.11"
numpy = "0.22.1"

serde = "1"
serde_json = "1"

ctrlc = "3.4"

[dev-dependencies]
# dev dependencies
criterion = "0.5"
approx = "0.4"
argmin_testfunctions = "0.2"

[workspace]
members = ["doe", "gp", "moe", "ego"]
44 changes: 44 additions & 0 deletions crates/doe/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "egobox-doe"
authors.workspace = true
version.workspace = true
license.workspace = true
edition.workspace = true
homepage.workspace = true
description = "A library for design of experiments"
repository = "https://github.com/relf/egobox/crates/doe"
keywords = [
"machine-learning",
"design",
"experiments",
"lhs",
"full-factorial",
]
readme = "README.md"

[features]
default = []

serializable = ["serde", "rand_xoshiro/serde1"]

[dependencies]
linfa.workspace = true
ndarray.workspace = true
ndarray-rand.workspace = true
ndarray-stats.workspace = true
num-traits.workspace = true
rand_xoshiro.workspace = true
serde = { version = "1", optional = true }

[dev-dependencies]
criterion.workspace = true
serde_json.workspace = true
approx.workspace = true

[[bench]]
name = "lhs"
harness = false

[[bench]]
name = "lhs_classics"
harness = false
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 21 additions & 21 deletions ego/Cargo.toml → crates/ego/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "egobox-ego"
version = "0.25.0"
authors = ["Rémi Lafage <[email protected]>"]
edition = "2021"
authors.workspace = true
version.workspace = true
license.workspace = true
edition.workspace = true
homepage.workspace = true
description = "A library for efficient global optimization"
license = "Apache-2.0"
repository = "https://github.com/relf/egobox"
repository = "https://github.com/relf/egobox/crates/ego"
keywords = ["machine-learning", "bayesian", "optimization"]
categories = ["algorithms", "mathematics", "science"]

Expand All @@ -24,16 +25,16 @@ egobox-moe = { version = "0.25.0", path = "../moe", features = [
"serializable",
] }

linfa = { version = "0.7", default-features = false }
linfa.workspace = true
linfa-pls = { version = "0.7", default-features = false }
linfa-linalg = { version = "0.1", default-features = false }

ndarray = { version = "0.15", features = ["rayon", "approx"] }
ndarray.workspace = true
ndarray-linalg = { version = "0.15", optional = true }
ndarray-stats = "0.5"
ndarray-rand = "0.14"
ndarray-npy = "0.8"
rayon = "1"
ndarray-stats.workspace = true
ndarray-rand.workspace = true
ndarray-npy.workspace = true
rayon.workspace = true

cobyla = { version = "0.6" }
slsqp = { version = "0.1" }
Expand All @@ -44,25 +45,24 @@ argmin = { version = "0.10.0", features = ["serde1", "ctrlc"] }
bincode = { version = "1.3.0" }
web-time = "1.1.0"
libm = "0.2.6"
finitediff = { version = "0.1", features = ["ndarray"] }
finitediff.workspace = true
# sort-axis
rawpointer = { version = "0.2" }
log = "0.4"
env_logger = "0.11.3"
thiserror = "1"
anyhow = "1"
log.workspace = true
env_logger.workspace = true
thiserror.workspace = true
anyhow.workspace = true
clap = { version = "4", features = ["derive"] }

serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
serde_json.workspace = true
typetag = { version = "0.2" }
dyn-clonable = { version = "0.9" }


[dev-dependencies]
criterion = "0.5"
approx = "0.4"
argmin_testfunctions = "0.2"
criterion.workspace = true
approx.workspace = true
argmin_testfunctions.workspace = true
serial_test = "3.1.0"

[[bench]]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f6e1299

Please sign in to comment.