Skip to main content

gds-psuu

PyPI Python License

Parameter space search under uncertainty — explore, evaluate, and optimize simulation parameters with Monte Carlo awareness.

Built on top of gds-sim, gds-psuu provides a search engine for intelligently exploring simulation parameter spaces to optimize KPIs.

Install

uv add gds-psuu
# or: pip install gds-psuu

# For Bayesian optimization (optional):
uv add "gds-psuu[bayesian]"

Quick Start

from gds_sim import Model, StateUpdateBlock
from gds_psuu import (
    KPI, Continuous, GridSearchOptimizer,
    ParameterSpace, Sweep, final_value, mean_agg,
)

# Define a gds-sim model
model = Model(
    initial_state={"population": 100.0},
    state_update_blocks=[
        StateUpdateBlock(
            policies={"growth": lambda s, p, **kw: {"delta": s["population"] * p["growth_rate"]}},
            variables={"population": lambda s, p, signal=None, **kw: ("population", s["population"] + signal["delta"])},
        )
    ],
)

# Define what to search and what to measure
sweep = Sweep(
    model=model,
    space=ParameterSpace(params={"growth_rate": Continuous(min_val=0.01, max_val=0.2)}),
    kpis=[KPI(name="avg_pop", metric=final_value("population"), aggregation=mean_agg)],
    optimizer=GridSearchOptimizer(n_steps=5),
    timesteps=10,
    runs=3,
)
results = sweep.run()

best = results.best("avg_pop")
print(f"Best growth_rate: {best.params['growth_rate']:.3f}")

Features

Composable KPIs

Metric (per-run scalar) + Aggregation (cross-run reducer) = KPI:

from gds_psuu import (
    KPI, final_value, trajectory_mean, max_value, min_value,
    mean_agg, std_agg, percentile_agg, probability_above, probability_below,
)

# Mean of final population across Monte Carlo runs
KPI(name="avg_pop", metric=final_value("population"), aggregation=mean_agg)

# 95th percentile of trajectory means
KPI(name="p95", metric=trajectory_mean("x"), aggregation=percentile_agg(95))

# Probability that max value exceeds a threshold
KPI(name="risk", metric=max_value("x"), aggregation=probability_above(500.0))

Per-run distributions are tracked in EvaluationResult.distributions for downstream analysis.

Parameter Spaces

Three dimension types with validation:

from gds_psuu import Continuous, Integer, Discrete, ParameterSpace

space = ParameterSpace(params={
    "learning_rate": Continuous(min_val=0.001, max_val=0.1),
    "layers": Integer(min_val=1, max_val=5),
    "activation": Discrete(values=("relu", "tanh")),
})

Parameter Constraints

Define feasible regions with linear or functional constraints:

from gds_psuu import LinearConstraint, FunctionalConstraint

# x + y <= 1.0
LinearConstraint(coefficients={"x": 1.0, "y": 1.0}, bound=1.0)

# Custom constraint function
FunctionalConstraint(fn=lambda p: p["x"] ** 2 + p["y"] ** 2 <= 1.0)

Grid search filters infeasible points; random search uses rejection sampling.

Search Strategies

Optimizer Strategy When to use
GridSearchOptimizer(n_steps) Exhaustive grid 1-2 dimensions, full coverage
RandomSearchOptimizer(n_samples, seed) Uniform random Higher dimensions, exploration
BayesianOptimizer(n_calls, target_kpi) Gaussian process (optuna) Expensive sims, optimization

Composable Objectives

Multi-KPI optimization:

from gds_psuu import SingleKPI, WeightedSum

# Single KPI (maximize or minimize)
obj = SingleKPI(name="avg_pop", maximize=True)

# Weighted combination of multiple KPIs
obj = WeightedSum(weights={"profit": 1.0, "risk": -0.5})

results.best_by_objective(obj)

Sensitivity Analysis

Screen parameter importance before running expensive sweeps:

from gds_psuu import OATAnalyzer, MorrisAnalyzer

# One-at-a-time: vary each parameter independently
oat = OATAnalyzer(n_steps=5)
result = oat.analyze(evaluator, space)

# Morris method: elementary effects (mu_star = influence, sigma = nonlinearity)
morris = MorrisAnalyzer(r=10, levels=4)
result = morris.analyze(evaluator, space)

result.ranking("my_kpi")  # parameters sorted by importance

Architecture

Parameter Point  ->  Simulation  ->  Results  ->  Metric  ->  Aggregation  ->  KPI
                                                                                 |
Optimizer.suggest()  -->  Evaluator.evaluate(params)  -->  Optimizer.observe(scores)
       ^                          |                              |
       |                   gds-sim Simulation                    |
       +------------------------ repeat --------------------------+

Documentation

Full docs at blockscience.github.io/gds-core.

License

Apache-2.0 — BlockScience

Metadata

Release files for gds-psuu 0.99.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 gds-psuu 0.99.0
File Size Uploaded Provenance Actions
gds_psuu-0.99.0.tar.gz 14.1 kB Without provenance Details for gds_psuu-0.99.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gds-psuu 0.99.0
File Interpreter ABI Platform Actions
gds_psuu-0.99.0-py3-none-any.whl Python 3 none any Details for gds_psuu-0.99.0-py3-none-any.whl

Total release size: 18.3 kB

Release files / gds_psuu-0.99.0.tar.gz

Download URL gds_psuu-0.99.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7b17975edb568468c71e7b76a0fabc7c187e1069dfe14260af07c0dbb32a3aa1
BLAKE2b-256 checksum
How to use checksums
8b0a28af83b0be5d2c2019c857d960155b94a35f83c951bc03489950e8cc9d24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / gds_psuu-0.99.0-py3-none-any.whl

Download URL gds_psuu-0.99.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
50cbf7837be0b5ad5a8b638ffac6b44fb4b18fdd9c484cb21d001d8d10f9ba8b
BLAKE2b-256 checksum
How to use checksums
cf5caca5e353f085812847128487e57a26901157b582e6cea7b302a6b5adde27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for gds-psuu 0.99.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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