Skip to main content

A library of methods to calibrate simulation models.

Project description


pypi License Ruff pre-commit Lint Test Publish Build Run with Docker

PyPI | Documentation | API | Changelog | Examples | Releases | Docker

A toolbox for the calibration and evaluation of simulation models.

Table of contents

Introduction

calisim is an open-source, low-code model calibration library that streamlines and standardises your workflows, while aiming to be as flexible and extensible as needed to support more complex use-cases. Using calisim will speed up your experiment cycle substantially and make you more productive.

calisim is primarily a wrapper around popular libraries and frameworks including Optuna, PyMC, scikit-learn, and emcee among many others. The design and simplicity of calisim was inspired by the scikit-learn and PyCaret libraries.

Features and Functionality

  • A standardised and streamlined interface to multiple calibration procedures and libraries.
  • A low-code library, allowing modellers to rapidly construct multiple workflows for many calibration procedures.
  • An object-oriented programming architecture, allowing users to easily extend and modify calibration workflows for their own complex modelling use-cases.
  • An unopinionated approach to working with simulation models, allowing users to calibrate both Python-based and non-Python-based models.
  • Optional integration with PyTorch for access to more sophisticated Gaussian Process and deep learning surrogate models, state-of-the-art evolutionary algorithms, and deep generative modelling for simulation-based inference.

Quickstart

import numpy as np
import pandas as pd

from calisim.data_model import (
	DistributionModel,
	ParameterDataType,
	ParameterSpecification,
)
from calisim.example_models import LotkaVolterraModel
from calisim.optimisation import OptimisationMethod, OptimisationMethodModel
from calisim.statistics import MeanSquaredError
from calisim.utils import get_examples_outdir

model = LotkaVolterraModel()
observed_data = model.get_observed_data()

parameter_spec = ParameterSpecification(
	parameters=[
		DistributionModel(
			name="alpha",
			distribution_name="uniform",
			distribution_args=[0.45, 0.55],
			data_type=ParameterDataType.CONTINUOUS,
		)
	]
)

def objective(
	parameters: dict, simulation_id: str, observed_data: np.ndarray | None, t: pd.Series
) -> float | list[float]:
	simulation_parameters = dict(
		alpha=parameters["alpha"],
		beta=0.024, h0=34.0, l0=5.9,
		t=t, gamma=0.84, delta=0.026,
	)

	simulated_data = model.simulate(simulation_parameters).lynx.values
	metric = MeanSquaredError()
	discrepancy = metric.calculate(observed_data, simulated_data)
	return discrepancy

specification = OptimisationMethodModel(
	experiment_name="optuna_optimisation",
	parameter_spec=parameter_spec,
	observed_data=observed_data.lynx.values,
	outdir=get_examples_outdir(),
	method="tpes",
	directions=["minimize"],
	n_iterations=100,
	method_kwargs=dict(n_startup_trials=50),
	calibration_func_kwargs=dict(t=observed_data.year),
)

calibrator = OptimisationMethod(
	calibration_func=objective, specification=specification, engine="optuna"
)

calibrator.specify().execute().analyze()

result_artifacts = "\n".join(calibrator.get_artifacts())
print(f"View results: \n{result_artifacts}")
print(f"Parameter estimates: {calibrator.get_parameter_estimates()}")

Installation

The easiest way to install calisim is by using pip:

pip install calisim

calisim's default installation will not include all optional dependencies. You may be interested in one or more extras:

# Install PyTorch extras
pip install calisim[torch]

# Install Hydra extras
pip install calisim[hydra]

# Install TorchX extras
pip install calisim[torchx]

# Install multiple extras
pip install calisim[torch,hydra,torchx]

Usage with Docker

You may also want to execute calisim inside of a Docker container. You can do so by running the following:

export CALISIM_VERSION=0.2.0 # Change the version as needed
wget https://raw.githubusercontent.com/Plant-Food-Research-Open/calisim/refs/heads/main/docker-compose.yaml
docker compose pull calisim
docker compose run --rm calisim python examples/optimisation/optuna_example.py

Communication

Contributions and Support

Contributions are more than welcome. For general guidelines on how to contribute to this project, take a look at CONTRIBUTING.md.

License

calisim is published under the Apache License (see LICENSE).

View all third party licenses (see third_party)

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

calisim-0.2.0.tar.gz (56.6 kB view details)

Uploaded Source

Built Distribution

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

calisim-0.2.0-py3-none-any.whl (92.8 kB view details)

Uploaded Python 3

File details

Details for the file calisim-0.2.0.tar.gz.

File metadata

  • Download URL: calisim-0.2.0.tar.gz
  • Upload date:
  • Size: 56.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.16 Linux/6.8.0-1021-azure

File hashes

Hashes for calisim-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9368ddc0a404152232eb5a7da2f12bef06e08d424cdaa8ed84f58acddf2926bf
MD5 cd25e68f8424964cf70393d68feaf56f
BLAKE2b-256 2c51807bf5de43a6b5180414eda806d219ce1100291feecf07a886aa6a5cae83

See more details on using hashes here.

File details

Details for the file calisim-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: calisim-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 92.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.16 Linux/6.8.0-1021-azure

File hashes

Hashes for calisim-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dafe648621e50c9dcebcef934afc3149222d1cbf1925c276fe9ba6d31782c807
MD5 a031af0b78a1343ddce5eb10bc0cef31
BLAKE2b-256 956c9ebad37015ec61b3625a88c74013d5438c853eb792a97db57710ad5b0610

See more details on using hashes here.

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