Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
- name: Test Python
working-directory: python
run: |
uv run pytest
uv run pytest tests
shell: bash

6 changes: 3 additions & 3 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ on:
- crates/gp/examples/**
- website/**
- notebooks/**
- python/egobox/examples/*.py
- python/egobox/tests/test_examples.py
- python/examples/*.py
- python/tests/test_examples.py
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:

- name: Verify website examples
working-directory: python
run: uv run pytest egobox/tests/test_examples.py
run: uv run pytest tests/test_examples.py

- name: Install Zola
uses: taiki-e/install-action@v2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ plt.show()

See also [this example written in Rust](crates/gp/examples/kriging.rs)

See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/notebooks/README.md) and [examples folder](https://github.com/relf/egobox/tree/d9db0248199558f23d966796737d7ffa8f5de589/python/egobox/examples) for more information on the usage of the optimizer and mixture of Gaussian processes surrogate model.
See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/notebooks/README.md) and [examples folder](https://github.com/relf/egobox/tree/master/python/examples) for more information on the usage of the optimizer and mixture of Gaussian processes surrogate model.

## The Rust libraries

Expand Down
2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "README.md"
publish = false

[lib]
name = "egobox"
name = "_rust"
crate-type = ["cdylib", "rlib"]
doctest = false # do not doctest as doc uses Python style for Python API doc

Expand Down
2 changes: 1 addition & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ plt.plot(xtrain, ytrain, "o")
plt.show()
```

See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/notebooks/README.md) and [examples folder](https://github.com/relf/egobox/tree/d9db0248199558f23d966796737d7ffa8f5de589/python/egobox/examples) for more information on the usage of the optimizer and mixture of Gaussian processes surrogate model.
See the [tutorial notebooks](https://github.com/relf/egobox/tree/master/notebooks/README.md) and [examples folder](https://github.com/relf/egobox/tree/master/python/examples) for more information on the usage of the optimizer and mixture of Gaussian processes surrogate model.
37 changes: 36 additions & 1 deletion python/egobox/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
from .egobox import * # noqa
# Public API - re-export all symbols from the Rust extension
# ruff: noqa: F405
from ._rust import * # noqa

__all__ = [
"ConstraintStrategy",
"CorrelationSpec",
"CstrSpec",
"Egor",
"EgorOptim",
"ExitStatus",
"FailsafeStrategy",
"FeasibleInfillStrategy",
"GpConfig",
"GpMix",
"Gpx",
"InfillOptimizer",
"InfillStrategy",
"OptimResult",
"QEiConfig",
"QEiStrategy",
"Recombination",
"RegressionSpec",
"RunInfo",
"RunStatus",
"Sampling",
"SparseGpMix",
"SparseGpx",
"SparseMethod",
"TregoConfig",
"Verbose",
"XSpec",
"XType",
"lhs",
"sampling",
] # noqa
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import egobox as egx
import warnings

warnings.filterwarnings("ignore", category=UserWarning)

# Comment out the following line to display the plot in a window
matplotlib.use("Agg")

import egobox as egx

xt = np.array([[0.0, 1.0, 1.5, 2.0, 3.0, 4.0]]).T
yt = np.array([[0.0, 1.0, 1.7, 1.5, 0.9, 1.0]]).T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import egobox as egx
import matplotlib.pyplot as plt

import warnings

warnings.filterwarnings("ignore", category=UserWarning)

# Comment out the following line to display the plot in a window
matplotlib.use("Agg")

Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ dev = [
]

[tool.maturin]
module-name = "egobox"
python-source = "."
module-name = "egobox._rust"
features = ["pyo3/extension-module"]
# Optional usage of BLAS backend
# cargo-extra-args = "--features linfa/intel-mkl-static"
Expand Down
11 changes: 10 additions & 1 deletion python/src/bin/stub_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ use pyo3_stub_gen::Result;

fn main() -> Result<()> {
env_logger::Builder::from_env(env_logger::Env::default().filter_or("RUST_LOG", "info")).init();
let stub = egobox::stub_info()?;
let stub = _rust::stub_info()?;
stub.generate()?;

// The Rust stub generator generates a stub file in the python/egobox/_rust directory,
// As Python API is the same as core Rust API, we move the stub file to python/egobox/egobox.pyi
log::info!("Moving stub file to egobox/egobox.pyi");
let from = std::path::Path::new("python/egobox/_rust/__init__.pyi");
let to = std::path::Path::new("python/egobox/egobox.pyi");
std::fs::rename(from, to).expect(
"Should move stub file to egobox/egobox.pyi. Ensure to run this command from the root of the repository, and that the stub file exists.",
);
Ok(())
}
2 changes: 1 addition & 1 deletion python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn _run_gpx_cli(args: Vec<String>) -> i32 {

#[doc(hidden)]
#[pymodule]
fn egobox(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
fn _rust(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
// egobox version
m.add("__version__", env!("CARGO_PKG_VERSION"))?;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from egobox import egobox as native
import egobox as egx


def test_gpx_help_exit_code_zero(capfd):
code = native._run_gpx_cli(["--help"])
code = egx._rust._run_gpx_cli(["--help"])

assert code == 0
out, err = capfd.readouterr()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions website/content/examples/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ weight = 20

# Examples

The Python snippets below are included directly from source files under [`python/egobox/examples`](https://github.com/relf/EGObox/tree/master/python/egobox/examples/).
The Python snippets below are included directly from source files under [`python/examples`](https://github.com/relf/EGObox/tree/master/python/examples/).
Here you can just copy-paste the code to run it locally, or click on the links to open the source files in a new tab.

## Optimization with _Egor_

### Unconstrained optimization: [Rastrigin](https://github.com/relf/EGObox/blob/master/python/egobox/examples/rastrigin.py)
### Unconstrained optimization: [Rastrigin](https://github.com/relf/EGObox/blob/master/python/examples/rastrigin.py)

{{ include_code(
url="https://raw.githubusercontent.com/relf/EGObox/master/python/egobox/examples/rastrigin.py",
url="https://raw.githubusercontent.com/relf/EGObox/master/python/examples/rastrigin.py",
lang="python")
}}

Expand All @@ -27,10 +27,10 @@ Best point (x*): [ 0.00415341 -0.00058284]

![Rastrigin function optimization](img/rastrigin.png)

### Constrained optimization: [G24](https://github.com/relf/EGObox/blob/master/python/egobox/examples/g24.py)
### Constrained optimization: [G24](https://github.com/relf/EGObox/blob/master/python/examples/g24.py)

{{ include_code(
url="https://raw.githubusercontent.com/relf/EGObox/master/python/egobox/examples/g24.py",
url="https://raw.githubusercontent.com/relf/EGObox/master/python/examples/g24.py",
lang="python")
}}

Expand All @@ -40,10 +40,10 @@ Optimization f=[-5.50853583e+00 8.65985077e-04 3.83913510e-04] at [2.32948272

## Surrogate modeling with _Gpx_

### Simple surrogate model: [Kriging](https://github.com/relf/EGObox/blob/master/python/egobox/examples/kriging.py)
### Simple surrogate model: [Kriging](https://github.com/relf/EGObox/blob/master/python/examples/kriging.py)

{{ include_code(
url="https://raw.githubusercontent.com/relf/EGObox/master/python/egobox/examples/kriging.py",
url="https://raw.githubusercontent.com/relf/EGObox/master/python/examples/kriging.py",
lang="python")
}}

Expand Down
2 changes: 1 addition & 1 deletion website/content/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ weight = 60

- [Github repository](https://github.com/relf/EGObox)
- [Notebook index](https://github.com/relf/EGObox/blob/master/notebooks/README.md)
- [Python examples directory](https://github.com/relf/EGObox/tree/master/python/egobox/examples)
- [Python examples directory](https://github.com/relf/EGObox/tree/master/python/examples)
- [Rust crate directory](https://github.com/relf/EGObox/tree/master/crates)
Loading