Fast multivariate grid search optimizer with C++ core
Project description
gridoptim
gridoptim is a deterministic multivariate grid-search optimizer for Python with a compiled C++ backend.
It evaluates a mathematical expression across every point in a user-defined parameter grid and returns the best result for either minimization or maximization.
Features
- Deterministic brute-force optimization
- Fast native C++ core exposed through Python
- Simple string-based expression interface
- Support for multi-variable parameter sweeps
- Reproducible results across runs
- Small public API with minimal setup
Installation
Install from PyPI:
pip install gridoptim
Requirements:
- Python 3.10+
- A supported build environment if installing from source
Quick Start
from gridoptim import GridSearchOptimiser
opt = GridSearchOptimiser()
value, params = (
opt
.function("x^2 + y^2")
.set_range("x", -10, 10, 0.5)
.set_range("y", -10, 10, 0.5)
.optimise("min")
)
print("Best value:", value)
print("Best parameters:", params)
Expected output:
Best value: 0.0
Best parameters: {'x': 0.0, 'y': 0.0}
How It Works
gridoptim performs an exhaustive search over all combinations of values produced by the ranges you define.
For example, if you search:
xfrom-10to10with step1yfrom-10to10with step1
the optimizer evaluates 21 x 21 = 441 points.
This guarantees the best result within the grid you specified, unlike probabilistic or heuristic optimizers that may trade certainty for speed.
Basic Usage
Optimization follows three steps:
- Create an optimizer.
- Define the expression to evaluate.
- Define a range for each variable, then run
optimise("min")oroptimise("max").
from gridoptim import GridSearchOptimiser
opt = GridSearchOptimiser()
opt.function("sin(x) + cos(y) + x^2")
opt.set_range("x", -3.14, 3.14, 0.1)
opt.set_range("y", -3.14, 3.14, 0.1)
value, params = opt.optimise("min")
API
GridSearchOptimiser
Main optimization class.
GridSearchOptimiser(expr: str | None = None)
Creates a new optimizer. You may optionally provide the expression at construction time.
function(expr: str) -> GridSearchOptimiser
Sets the mathematical expression to optimize.
opt.function("x^2 + y^2")
set_range(var: str, min_val: float, max_val: float, step: float) -> GridSearchOptimiser
Defines the search range for a variable.
opt.set_range("x", -10, 10, 0.1)
Arguments:
var: variable name used in the expressionmin_val: lower boundmax_val: upper boundstep: step size, must be greater than0
optimise(mode: str = "min") -> tuple[float, dict[str, float]]
Runs the grid search and returns:
best_valuebest_parameter_dict
value, params = opt.optimise("max")
Valid modes:
"min"for minimization"max"for maximization
Expression Syntax
Expressions are passed as strings and evaluated by the native backend using a lightweight mathematical expression parser.
Supported operators include:
+-*/^
Common mathematical functions such as sin, cos, tan, log, sqrt, exp, and abs are supported.
Example:
opt.function("sin(x) * cos(y) + x^2")
Examples
Minimize a quadratic
from gridoptim import GridSearchOptimiser
opt = GridSearchOptimiser()
value, params = (
opt
.function("x^2 + y^2")
.set_range("x", -5, 5, 0.1)
.set_range("y", -5, 5, 0.1)
.optimise("min")
)
print(value)
print(params)
Maximize a trigonometric expression
from gridoptim import GridSearchOptimiser
opt = GridSearchOptimiser()
value, params = (
opt
.function("sin(x) * cos(y)")
.set_range("x", -3.14, 3.14, 0.01)
.set_range("y", -3.14, 3.14, 0.01)
.optimise("max")
)
print(value)
print(params)
Search across three variables
from gridoptim import GridSearchOptimiser
opt = GridSearchOptimiser()
value, params = (
opt
.function("x^2 + y^2 + z^2")
.set_range("x", -10, 10, 1)
.set_range("y", -10, 10, 1)
.set_range("z", -10, 10, 1)
.optimise("min")
)
print(value)
print(params)
Performance Notes
Grid search grows exponentially with the number of variables and the number of steps per variable.
For example:
- 3 variables
- 100 steps per variable
results in 100 x 100 x 100 = 1,000,000 evaluations.
Because the heavy computation is performed in C++, gridoptim can handle much larger search spaces than a pure Python implementation, but exhaustive search still becomes expensive as the grid grows.
Benchmark
Benchmark problem: 4D grid search optimization.
| Optimizer | Time |
|---|---|
| gridoptim | 0.821 s |
| scipy.brute | 89.167 s |
Result:
- Same optimum value
- Same optimum point
- ~108× speedup
Hardware:
- CPU: Intel i5-12500H
- Python 3.14
License
See the LICENSE file included in this repository for licensing terms.
Author
Akhil Shimna Kumar
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gridoptim-2.2.0.tar.gz.
File metadata
- Download URL: gridoptim-2.2.0.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b16d54ac1325abe923dfbde2823bb227520238ecd9f602bd2f8f422edc6d107f
|
|
| MD5 |
62ad055de9a052c8fae8c93575e699b9
|
|
| BLAKE2b-256 |
b7e15f2d4c6dd4a868f2cc286f4691b2bb028e7da55a9c991326760efd97f107
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0.tar.gz:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0.tar.gz -
Subject digest:
b16d54ac1325abe923dfbde2823bb227520238ecd9f602bd2f8f422edc6d107f - Sigstore transparency entry: 1229159309
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 81.8 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aad465970a931ba85db689753860ba56e6c4bc6d9ede097ad2a1f9da7c9e3d97
|
|
| MD5 |
7fe6ec00bd05b815d06f44bbcd0449c3
|
|
| BLAKE2b-256 |
b4a6c635af247e9beab6cb9517a41892df4fdbcdb4869eae2f1e0cc7ea569ac5
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp313-cp313-win_amd64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp313-cp313-win_amd64.whl -
Subject digest:
aad465970a931ba85db689753860ba56e6c4bc6d9ede097ad2a1f9da7c9e3d97 - Sigstore transparency entry: 1229159622
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cad12b33a6c3ae978798c1f806f83808aa5a2d16058a32eb7bd4154cbdba5df9
|
|
| MD5 |
896653ce98a21ac6593e56c8307b9a4d
|
|
| BLAKE2b-256 |
5d96cb5a1bdfe98921b1bea246cff91de07deac86de09af1c33b3ae9e1c81445
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
cad12b33a6c3ae978798c1f806f83808aa5a2d16058a32eb7bd4154cbdba5df9 - Sigstore transparency entry: 1229159665
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 81.7 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a754e026fc9e2cc7c0555349d3886ca90b8f2cdbbaa676841c11ddd44a5b474b
|
|
| MD5 |
ffa617f7d8f37950c29a6cf1abbe6324
|
|
| BLAKE2b-256 |
dd2ca9aeb1827917ea3c5101add3ead60b1f8fd821b97cd2bb90843bb333a68c
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp312-cp312-win_amd64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp312-cp312-win_amd64.whl -
Subject digest:
a754e026fc9e2cc7c0555349d3886ca90b8f2cdbbaa676841c11ddd44a5b474b - Sigstore transparency entry: 1229159358
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eacef4f8fb2adb4d26d60cdd79dea6fd33dfc4c82784693adf9624a85a197d7
|
|
| MD5 |
698e54940df55a02059ee82d1b34577d
|
|
| BLAKE2b-256 |
c3b858337eb0b2eb2f41a5fef57f4155d868ba6f135665d37dac71a247009762
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
0eacef4f8fb2adb4d26d60cdd79dea6fd33dfc4c82784693adf9624a85a197d7 - Sigstore transparency entry: 1229159564
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 81.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
599cf1275ca94619d10b47121e2be076e4111858cf60b437e47dadc51b7eba2b
|
|
| MD5 |
800e75cdf9917a20a89dc35de482e315
|
|
| BLAKE2b-256 |
9e5f9b50fd6148d3ff632b6037d6bb38b2f09c2a99fbebf98d9a06c215741546
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp311-cp311-win_amd64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp311-cp311-win_amd64.whl -
Subject digest:
599cf1275ca94619d10b47121e2be076e4111858cf60b437e47dadc51b7eba2b - Sigstore transparency entry: 1229159731
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48ad68b98894487a2b73e441bee6ddec172d74bdbcaa06d71d97bbc701e92498
|
|
| MD5 |
a7b1e5c54e56b29dd441ab085551ada7
|
|
| BLAKE2b-256 |
53f81ec10933c6b4b018f4f8567fb014afe9ecd9495871b20fbfa294662f78b6
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
48ad68b98894487a2b73e441bee6ddec172d74bdbcaa06d71d97bbc701e92498 - Sigstore transparency entry: 1229159425
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 80.4 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e96fc309c549fa602f22a10338e702ef47c19a6942e60ad398be85238b9b77b
|
|
| MD5 |
abc4057816b5b6bbe03fb740842bf553
|
|
| BLAKE2b-256 |
26802c215a9dfbd646f37809c3d5b01c30bccdb57d86b8c1466920335cb75b11
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp310-cp310-win_amd64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp310-cp310-win_amd64.whl -
Subject digest:
7e96fc309c549fa602f22a10338e702ef47c19a6942e60ad398be85238b9b77b - Sigstore transparency entry: 1229159474
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e3f365b2b7e244b3f228a421c509cd98f68e382c3267c8711efcae0189acc15
|
|
| MD5 |
addc6099cc6e8d672eacadc1c3a8493c
|
|
| BLAKE2b-256 |
6620e3c5e646abcf46ee7291732e1b4fb1ded29c94825546738e124ec23abbf5
|
Provenance
The following attestation bundles were made for gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on Halfblood-Prince/gridoptim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
8e3f365b2b7e244b3f228a421c509cd98f68e382c3267c8711efcae0189acc15 - Sigstore transparency entry: 1229159524
- Sigstore integration time:
-
Permalink:
Halfblood-Prince/gridoptim@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Halfblood-Prince
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2d7f63e79b47a954eef1c24b8f5ed7a39b384333 -
Trigger Event:
workflow_dispatch
-
Statement type: