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 src/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 Distribution

gridoptim-2.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distributions

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

gridoptim-2.1.0-cp313-cp313-win_amd64.whl (78.4 kB view details)

Uploaded CPython 3.13Windows x86-64

gridoptim-2.1.0-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.1.0-cp312-cp312-win_amd64.whl (78.4 kB view details)

Uploaded CPython 3.12Windows x86-64

gridoptim-2.1.0-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.1.0-cp311-cp311-win_amd64.whl (77.7 kB view details)

Uploaded CPython 3.11Windows x86-64

gridoptim-2.1.0-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.1.0-cp310-cp310-win_amd64.whl (76.9 kB view details)

Uploaded CPython 3.10Windows x86-64

gridoptim-2.1.0-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.1.0.tar.gz.

File metadata

  • Download URL: gridoptim-2.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gridoptim-2.1.0.tar.gz
Algorithm Hash digest
SHA256 a3c49b321129655e3ad7f4ebea5381730a2b0064a5d2db0e90851201d70ce786
MD5 d23069219714a0fbcf72018e568d9f65
BLAKE2b-256 7f501e423f762e45c39b18d7bae7585a88630cd56c6e967b6bb70cd9f076a3c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0.tar.gz:

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.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 78.4 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.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e6ecb83efde03645b389391c6c7d9a241c65ebbbf061f6a7f6219ce8a9b404c1
MD5 daa591f43d64b97182c9872de3c3c685
BLAKE2b-256 af3fa71164b465990ca93062dc7332b1c3ee9f5cadde708e303a6c426401ac08

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75eb5932b97492624cc4f3642c2c4bce79cbd6b0ffe1a57d35854a64632d4916
MD5 291eaebf88308f318bfb8a0eea084d1a
BLAKE2b-256 9a9530838e832b51c314bd94791e5608817843eae73dbf3fb0cf9294ddc5e255

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 78.4 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.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8296a04945c3dd7d65cb0af2721a3c21a2ec4c091fef425e54a9a383b9eab452
MD5 d6fb52f637d23a490c4990ce651267f0
BLAKE2b-256 0f4e1666129bdbcaf0d49e41ebbc994258065f6143dc2566af177c146261ac54

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee01ccdf663ba103e316a07c0acf27c50c8ea081ce6ccb93866e46f98261bd7c
MD5 2c6a17616a1eadaeccb6a9c4f3e8f473
BLAKE2b-256 e35dfb025f757b35fec7ec6c6d0e00d6180f2f8a2aa7f398639ca65304cd25bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 77.7 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.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0ea1edffbeaceb36b562543b1adeff24a7f2b343dc7a8f3237870104da6d677f
MD5 fc58ea0308cbbd834ca5ec7b8fa1434c
BLAKE2b-256 8191c43aa14bbecc878808ab0826a554795d341c9f6b4717f5ffca319744905e

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 26152acb62673205fbebfc852ce2abcd5f72b913fb57f704ce202d91e5514fc6
MD5 c4ae2bf8189b2d6aac1e5e1fc1be9084
BLAKE2b-256 8b198cde8a14a40a0447160ea9f8a25bf2984b116253e3b99c680c840bb113a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 76.9 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.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8709b35cea210710a08fbffe39d55de73908cdbe0dff8d69ea93356462d0c3ec
MD5 36dbc4e7a17befa7a3cb6d34d11fff4e
BLAKE2b-256 7f76d4cad8fbeaf9736e30766ab7503a877f75ff4bbb4e060e0aeecf7fec611f

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for gridoptim-2.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da3aff2ddbb7b53c35b23a428ed352fd30220a8762953b01e08e6a2535638776
MD5 6e43ccea221acf534a6403c1cc7d706b
BLAKE2b-256 b8102d8a036547f8adaedfeb3a95f883bdcac4941304d4dfecc1ee02fb178bab

See more details on using hashes here.

Provenance

The following attestation bundles were made for gridoptim-2.1.0-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