Skip to main content

Easily bootstrap Monaco Monte Carlo simulations with a dictionary based workflow.

Project description

PyPI Lint and Typecheck Ruff Code style: black

Monaco Dictionary Utils

A Python library for easily bootstrapping Monaco Monte Carlo simulations with a dictionary-based workflow.

See example notebook here

Overview

Monaco Dictionary Utils provides a simplified interface for creating and running Monte Carlo simulations using the Monaco framework. It streamlines the process of setting up simulations by allowing you to define model factories, input parameters, and distributions using dictionary-based configuration.

Features

  • Dictionary-based configuration: Define simulations using simple dictionary structures
  • Model factory support: Create models from factory functions with configurable parameters
  • Input variable management: Handle both probabilistic distributions and constants
  • Output conversion: Convert simulation results to easily accessible dictionary format
  • Parameter normalization: Automatic parameter name normalization for consistency

Installation

uv add monaco-dict-utils

Requirements

  • Python ≥ 3.11
  • Monaco ≥ 0.16.0

Quick Start

from monaco_dict_utils import sim_factory, outvals_to_dict

# Define your model factory
def my_model_factory(param1, param2):
    def model(x, y):
        return {"result": x * param1 + y * param2}
    return model

# Configure simulation
factory_vars = {"param1": 2, "param2": 3}
invars = {
    "x": {"dist": "uniform", "params": {"loc": 0, "scale": 1}},
    "y": {"dist": "_constant", "params": 5}
}

# Create and run simulation
sim = sim_factory(
    name="my_simulation",
    model_factory=my_model_factory,
    factory_vars=factory_vars,
    invars=invars,
    ndraws=1000
)

sim.run()

# Convert outputs to dictionary
results = outvals_to_dict(sim)

API Reference

sim_factory(name, model_factory, factory_vars, invars, ndraws, *, verbose=True, debug=False)

Create a Monte Carlo simulation from a model factory and parameters.

Parameters:

  • name (str): Name of the simulation
  • model_factory (Callable): Factory function that creates the model
  • factory_vars (dict): Dictionary of variables to pass to model factory
  • invars (dict): Dictionary mapping input names to distribution parameters
  • ndraws (int): Number of Monte Carlo draws to simulate
  • verbose (bool, optional): Whether to print simulation progress. Defaults to True.
  • debug (bool, optional): Whether to run in debug mode. Defaults to False.

Returns:

  • Sim: Configured Monaco Sim object ready to run simulations

Example:

sim = sim_factory(
    name="example_sim",
    model_factory=my_factory,
    factory_vars={"param": 10},
    invars={"x": {"dist": "normal", "params": {"loc": 0, "scale": 1}}},
    ndraws=5000
)

outvals_to_dict(sim)

Convert simulation output values to a dictionary.

Parameters:

  • sim (Sim): A Monaco Sim object that has been run

Returns:

  • dict: Dictionary mapping output variable names to numpy arrays of output values

Example:

results = outvals_to_dict(sim)
# results = {"Result": array([1.23, 4.56, ...]), "Other_Output": array([...])}

Input Variables Configuration

The invars dictionary supports two types of inputs:

1. Probabilistic Distributions

For random variables, specify a distribution and its parameters:

invars = {
    "temperature": {
        "dist": "normal",
        "params": {"loc": 20, "scale": 5}
    },
    "pressure": {
        "dist": "uniform", 
        "params": {"loc": 10, "scale": 2}
    }
}

2. Constants

For constant values, use the special _constant distribution:

invars = {
    "gravity": {
        "dist": "_constant",
        "params": 9.81
    },
    "config": {
        "dist": "_constant",
        "params": {"setting1": 100, "setting2": 200}
    }
}

Parameter Normalization

The library automatically normalizes parameter names by:

  • Converting to lowercase
  • Removing special characters
  • Replacing spaces with underscores

For example: "Air Temperature" becomes "air_temperature"

Output Formatting

Output values are automatically formatted with:

  • Title case conversion
  • Underscore preservation
  • Example: "time_savings" becomes "Time_Savings"

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

monaco_dict_utils-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

monaco_dict_utils-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file monaco_dict_utils-0.1.0.tar.gz.

File metadata

  • Download URL: monaco_dict_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for monaco_dict_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa0c997a1a5480a8487c0e047668a3caebcd7b3276d22102e332fa6b1d9db133
MD5 5c8738853ecca95635c8714d2eb6140c
BLAKE2b-256 113c1ab278bd2f3ce478a03fc2b33411a75a2850e26e0a3a266f808e42c92d63

See more details on using hashes here.

Provenance

The following attestation bundles were made for monaco_dict_utils-0.1.0.tar.gz:

Publisher: publish.yml on hbmartin/monaco-dict-utils

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

File details

Details for the file monaco_dict_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for monaco_dict_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9ae55ba34c68e5396f2f7cdcb5d338832173230bc268d094d46a991ae2605c0
MD5 deaa51efc557435db13c5e6bcafed880
BLAKE2b-256 5b49aaad78af64fef98decbed8c6d4c70785ddae20e34b7903caee6226781ce6

See more details on using hashes here.

Provenance

The following attestation bundles were made for monaco_dict_utils-0.1.0-py3-none-any.whl:

Publisher: publish.yml on hbmartin/monaco-dict-utils

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