Skip to main content

Fast multivariate grid search optimizer with C++ core

Project description

gridoptim

Fast multivariate grid search optimizer for Python with a C++ backend.

gridoptim performs deterministic brute-force optimization of mathematical expressions across multi-dimensional parameter spaces.

The optimizer evaluates every point in a parameter grid and returns the best result according to the chosen optimization mode.

It is designed for:

  • mathematical optimization
  • parameter sweeps
  • research experiments
  • simulation calibration
  • deterministic hyperparameter exploration

The computation is executed in a compiled C++ core for performance while providing a clean Python API.

Table of Contents

  • Overview
  • Features
  • Installation
  • Quick Start
  • Basic Usage
  • Expression Syntax
  • Optimization Modes
  • Examples
  • API Reference
  • How It Works
  • Performance
  • Use Cases
  • Project Structure
  • Development
  • FAQ
  • Keywords
  • Citation
  • Author
  • License

Overview

gridoptim is a deterministic optimization library that evaluates a mathematical expression across a grid of parameter values.

The optimizer searches the parameter space by evaluating every possible combination of variable values defined by user-provided ranges.

Unlike probabilistic optimizers, gridoptim guarantees that the global optimum within the defined grid will be found.

Features

  • fast C++ optimization engine
  • deterministic brute-force search
  • simple Python API
  • string-based mathematical expressions
  • multi-variable support
  • minimal dependencies
  • reproducible results

Installation

Install using pip:

pip install gridoptim

Requirements: Python 3.10+

Quick Start

Example optimization problem.

Find the minimum of:

x^2 + y^2

from gridoptim import GridSearchOptimiser

opt = GridSearchOptimiser()

opt.function("x^2 + y^2")
opt.set_range("x", -10, 10, 0.5)
opt.set_range("y", -10, 10, 0.5)
value, params = opt.optimise("min")

print("Best value:", value)
print("Best parameters:", params)

Example output:

Best value: 0.0 Best parameters: {'x': 0.0, 'y': 0.0} Basic Usage

Optimization in gridoptim follows three steps.

  1. Create optimizer from gridoptim import GridSearchOptimiser

opt = GridSearchOptimiser() 2. Define function

Functions are defined as string expressions.

opt.function("x^2 + y^2") 3. Define parameter ranges

Each variable requires:

minimum value

maximum value

step size

opt.set_range("x", -10, 10, 0.5) opt.set_range("y", -10, 10, 0.5) 4. Run optimization value, params = opt.optimise("min")

or

value, params = opt.optimise("max") Expression Syntax

Expressions are parsed by the embedded tinyexpr mathematical parser.

Supported operations include:

      • / ^

Supported functions include common math operations such as:

sin cos tan log sqrt exp abs

Example:

sin(x) + cos(y) + x^2 Optimization Modes

gridoptim supports two optimization modes.

Minimize optimise("min")

Finds the smallest value of the expression.

Maximize optimise("max")

Finds the largest value of the expression.

Examples Example 1 — Quadratic Minimum 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) Example 2 — Maximum of a Function 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) Example 3 — 3-Variable Optimization 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) API Reference GridSearchOptimiser

Main optimization class.

Create optimizer opt = GridSearchOptimiser() function(expr)

Sets the mathematical expression to optimize.

Parameters:

expr : str

Example:

opt.function("x^2 + y^2") set_range(var, min_val, max_val, step)

Defines the search range for a variable.

Parameters:

var : variable name min_val : minimum value max_val : maximum value step : step size

Example:

opt.set_range("x", -10, 10, 0.1) optimise(mode)

Runs the grid search.

Parameters:

mode : "min" or "max"

Returns:

(best_value, best_parameter_dict)

Example:

value, params = opt.optimise("min") How It Works

gridoptim evaluates the expression at every point in the grid defined by parameter ranges.

Example grid:

x: -10 → 10 step 1 y: -10 → 10 step 1

Total evaluations:

21 × 21 = 441

The C++ backend performs the iteration and expression evaluation.

This significantly reduces Python overhead.

Performance

Grid search complexity grows exponentially with variables.

Example:

3 variables 100 steps each

Total evaluations:

100 × 100 × 100 = 1,000,000

Because the heavy computation runs in C++, gridoptim can handle large evaluation counts efficiently.

Use Cases

gridoptim can be used for:

mathematical optimization

parameter sweeps

research experiments

simulation calibration

brute-force optimization

algorithm benchmarking

Project Structure gridoptim/ init.py gridoptim.py

cpp/ gridoptim_core.cpp tinyexpr.c tinyexpr.h

pyproject.toml setup.py Development

Clone repository:

git clone https://github.com/Halfblood-Prince/gridoptim.git

Install locally:

pip install -e .


FAQ

What is gridoptim?

gridoptim is a Python library for deterministic grid search optimization of mathematical expressions.

Does gridoptim support multiple variables?

Yes. You can define ranges for any number of variables.

Can it maximize functions?

Yes. Use:

optimise("max") Does gridoptim support arbitrary Python functions?

No. It evaluates string expressions using a mathematical expression parser.

Why use string expressions?

String expressions allow the C++ backend to evaluate functions directly without Python overhead.

Keywords

grid search optimization python grid search library mathematical optimization python parameter sweep python deterministic optimization multivariate grid search scientific parameter optimization

Citation

If you use gridoptim in research please cite:

gridoptim: Fast multivariate grid search optimizer https://github.com/Halfblood-Prince/gridoptim


Author

Akhil Shimna Kumar


License

See LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

gridoptim-2.0.1-cp313-cp313-win_amd64.whl (78.1 kB view details)

Uploaded CPython 3.13Windows x86-64

gridoptim-2.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

gridoptim-2.0.1-cp312-cp312-win_amd64.whl (78.2 kB view details)

Uploaded CPython 3.12Windows x86-64

gridoptim-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

gridoptim-2.0.1-cp311-cp311-win_amd64.whl (77.6 kB view details)

Uploaded CPython 3.11Windows x86-64

gridoptim-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

gridoptim-2.0.1-cp310-cp310-win_amd64.whl (76.8 kB view details)

Uploaded CPython 3.10Windows x86-64

gridoptim-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

File details

Details for the file gridoptim-2.0.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.0.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 78.1 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

Hashes for gridoptim-2.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 334ab7ae5771d1c73ce70f417d6553c28caaf4d9ef71d449f7e1e0fc4bb7ca39
MD5 abe33fd8026484e719675e140c6f2b45
BLAKE2b-256 862607f730925577f666560b68eed2a633a5a5feb57009feeada2803a38d7747

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp313-cp313-win_amd64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d19a3fffb9beb4ffa85617cfe59c82b1f380cb01d8cbc85f7805384c6632f902
MD5 42b97720ac657b52a204cb568b8a7995
BLAKE2b-256 f25be27a75455c60902cd34757d7277cbea8c89b8f62d64f6ac63eab32b92505

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.0.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 78.2 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

Hashes for gridoptim-2.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3d22afc15e3916c1d130120d67b78a3158fb83d24a6ce72607c4f776aaa4ee00
MD5 c680e6c073fbbadf81d63a6e029b541c
BLAKE2b-256 7dc968b91df87081826afa4fa5235e20cfac6510d0daf28867f233c840f679be

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da331173eb4dc3b3763a8b2d40b9a31e032e2d628b8e810bd8f78588ccf40453
MD5 30f9ec795c3b4b547be81c7fc444d00d
BLAKE2b-256 5b8f340092ef427935280bc81570ee229de26beb7f69b437d19ef30ba6c66bf6

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 77.6 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

Hashes for gridoptim-2.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bd101e17ea8faad41113d5a28da3be460d6f127a9b9ae37f92069d331d16be0d
MD5 5a6d0dc94309d9f1214585fac0f152ce
BLAKE2b-256 cf54963e46144033efa61c06cba52256ac5549dae9d486321016a9e8efed3457

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b30b82b2fbdbd47992eabd55fc30c33381d1e80b6d9dc600662fdaa43098658e
MD5 0bc3cc6daeae33f598a7ac0b407de332
BLAKE2b-256 982f045eb833c2c04b4abb1414091af429084252d3ced70ccbbd785b8a4b2dba

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 76.8 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

Hashes for gridoptim-2.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 96451d4627071dee26241ade23201c09cf548a9e8fdd05af850cd416e83c3ec8
MD5 5c52be1093ab2fee78d020d477ee4e0e
BLAKE2b-256 e33d9a3a35effd09a0a8573e6e723a3b7126f137b04691ed1724ce9d80cd0c65

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gridoptim-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 22c647dbf223caad161a9a9c47fcab2ecbebbf92ed290baaf9572bf11afa0bce
MD5 9d9cd76dbf9a03da1c555c2bd31ca007
BLAKE2b-256 d51c6d9591bc9c1a55c704934c20e167d859987edfca6e5954689ce19eb20f09

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on Halfblood-Prince/gridoptim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page