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.0-cp313-cp313-win_amd64.whl (78.1 kB view details)

Uploaded CPython 3.13Windows x86-64

gridoptim-2.0.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.0.0-cp312-cp312-win_amd64.whl (78.2 kB view details)

Uploaded CPython 3.12Windows x86-64

gridoptim-2.0.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.0.0-cp311-cp311-win_amd64.whl (77.6 kB view details)

Uploaded CPython 3.11Windows x86-64

gridoptim-2.0.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.0.0-cp310-cp310-win_amd64.whl (76.8 kB view details)

Uploaded CPython 3.10Windows x86-64

gridoptim-2.0.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.0.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: gridoptim-2.0.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c80cd11d847f169fa74b02a95f9bd5dff807cc883e064b3784ad1488c70332a1
MD5 39d8979ed562b177609987a4371c6e4c
BLAKE2b-256 76d213652bc6976379b36e162eb7fe898819ad66846b23c299e359c63e74e4e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gridoptim-2.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f758b7db5c16a5c8046dcbd60ce61e9d0400457467612d4049416f95f13bfe4
MD5 fdea6a07bf44b5177659276f4b6245d5
BLAKE2b-256 4faa859fd8e8047d90eba6639c2a983cce08c936348f7d0974f3ee45b572fbc8

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: gridoptim-2.0.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f2fe58c9b287ca14334a75c0d4787004d4dc6a224d8486f15caa4bf723d9e978
MD5 85309775f912c0ed8ed0d3d47a9b7271
BLAKE2b-256 b2ad339f6bded6f2cbd144dfa6f730eecf30bb1e5eb5f45a1289c84d964e12bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gridoptim-2.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e2bb68146659380e8a322553d08246f55918a9f41c98332dc46be374a2bed59b
MD5 9c65a4e28c682082153088b811983fa1
BLAKE2b-256 426c6a88f16a5eb9dbd17d8fd4b7d4620ed12d2b146d55cc029a1575b5094c78

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: gridoptim-2.0.0-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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 4be95423e5c019e027b6072540017d13d6f4444b24012ddef4ee9892fccb9d06
MD5 59cb87459edb4c8284c08b49f5d9d9f6
BLAKE2b-256 5a6b3ad1787b34609042010a9e2c960d738afaae11dbefd994177b36d42f8725

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gridoptim-2.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 610a6f84e938169e3dc374411a496bdd587e43c414628edb99da345b21113f61
MD5 da93cc46d1e9a057551377544c728e30
BLAKE2b-256 ccd90015892355f75b5b5c72257a64a4370da58a938d9928b7bb8434b66a124a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: gridoptim-2.0.0-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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f71d52381ae33449538d4b546a6fdba41635f8c26d62c9593b6b251b20e51079
MD5 c7ffa8bb8f334d7c93d79db4fcc50c95
BLAKE2b-256 1e49c75052fd1cdf1c49d8d91b1819e7a1a6fa4926f9c7423f64b22b2c46565d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for gridoptim-2.0.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3b57cffcfaa6046b03a52fd8098f77082dc1f934b1d42a5c76a93cbd795709d1
MD5 e849d5669e112fc803bb58155348fbf7
BLAKE2b-256 64aa5080c6e0a7cc356f67385939c5f1026d5ec2b3b022e391db831fc1aa7729

See more details on using hashes here.

Provenance

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