Skip to main content

gridoptim

PyPI Downloads

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:

  • x from -10 to 10 with step 1
  • y from -10 to 10 with step 1

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:

  1. Create an optimizer.
  2. Define the expression to evaluate.
  3. Define a range for each variable, then run optimise("min") or optimise("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 expression
  • min_val: lower bound
  • max_val: upper bound
  • step: step size, must be greater than 0

optimise(mode: str = "min") -> tuple[float, dict[str, float]]

Runs the grid search and returns:

  • best_value
  • best_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

Metadata

Release files for gridoptim 2.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gridoptim 2.2.0
File Size Uploaded
gridoptim-2.2.0.tar.gz 18.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for gridoptim 2.2.0
File
gridoptim-2.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details
gridoptim-2.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details
gridoptim-2.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
gridoptim-2.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details

Total release size: 5.3 MB

Release files / gridoptim-2.2.0.tar.gz

Download URL gridoptim-2.2.0.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b16d54ac1325abe923dfbde2823bb227520238ecd9f602bd2f8f422edc6d107f
BLAKE2b-256 checksum
How to use checksums
b7e15f2d4c6dd4a868f2cc286f4691b2bb028e7da55a9c991326760efd97f107
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp313-cp313-win_amd64.whl

Download URL gridoptim-2.2.0-cp313-cp313-win_amd64.whl
Size 81.8 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
aad465970a931ba85db689753860ba56e6c4bc6d9ede097ad2a1f9da7c9e3d97
BLAKE2b-256 checksum
How to use checksums
b4a6c635af247e9beab6cb9517a41892df4fdbcdb4869eae2f1e0cc7ea569ac5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gridoptim-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cad12b33a6c3ae978798c1f806f83808aa5a2d16058a32eb7bd4154cbdba5df9
BLAKE2b-256 checksum
How to use checksums
5d96cb5a1bdfe98921b1bea246cff91de07deac86de09af1c33b3ae9e1c81445
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp312-cp312-win_amd64.whl

Download URL gridoptim-2.2.0-cp312-cp312-win_amd64.whl
Size 81.7 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
a754e026fc9e2cc7c0555349d3886ca90b8f2cdbbaa676841c11ddd44a5b474b
BLAKE2b-256 checksum
How to use checksums
dd2ca9aeb1827917ea3c5101add3ead60b1f8fd821b97cd2bb90843bb333a68c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gridoptim-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0eacef4f8fb2adb4d26d60cdd79dea6fd33dfc4c82784693adf9624a85a197d7
BLAKE2b-256 checksum
How to use checksums
c3b858337eb0b2eb2f41a5fef57f4155d868ba6f135665d37dac71a247009762
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp311-cp311-win_amd64.whl

Download URL gridoptim-2.2.0-cp311-cp311-win_amd64.whl
Size 81.1 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
599cf1275ca94619d10b47121e2be076e4111858cf60b437e47dadc51b7eba2b
BLAKE2b-256 checksum
How to use checksums
9e5f9b50fd6148d3ff632b6037d6bb38b2f09c2a99fbebf98d9a06c215741546
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gridoptim-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
48ad68b98894487a2b73e441bee6ddec172d74bdbcaa06d71d97bbc701e92498
BLAKE2b-256 checksum
How to use checksums
53f81ec10933c6b4b018f4f8567fb014afe9ecd9495871b20fbfa294662f78b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp310-cp310-win_amd64.whl

Download URL gridoptim-2.2.0-cp310-cp310-win_amd64.whl
Size 80.4 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
7e96fc309c549fa602f22a10338e702ef47c19a6942e60ad398be85238b9b77b
BLAKE2b-256 checksum
How to use checksums
26802c215a9dfbd646f37809c3d5b01c30bccdb57d86b8c1466920335cb75b11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release files / gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL gridoptim-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
8e3f365b2b7e244b3f228a421c509cd98f68e382c3267c8711efcae0189acc15
BLAKE2b-256 checksum
How to use checksums
6620e3c5e646abcf46ee7291732e1b4fb1ded29c94825546738e124ec23abbf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.2.0 This release

9 release files

2.1.1

9 release files

2.1.0

9 release files

2.0.1

8 release files

2.0.0

8 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page