Skip to main content

Python framework for running reproducible experiments using OpenTTD

Project description

OpenTTDLab • PyPI package Test suite Code coverage

Python framework for running reproducible experiments using OpenTTD. An experiment in OpenTTDLab terms is the combination of:

  • Exact version of OpenTTD, any AIs used, and OpenTTDLab itself
  • Ranges of values for OpenTTD config settings, command line arguments and random seed
  • Granularity of output

This can be configured/extracted for each experiment in either machine or human readable forms, for use in code or publishing respectively.

OpenTTDLab is based on TrueBrain's OpenTTD Savegame Reader, but it is not affiliated with OpenTTD.

[!NOTE] Work in progress. This README serves as a rough design spec.

Installation

python -m pip install OpenTTDLab

OpenTTDLab itself depends on 7-zip, but this is not installed automatically.

To install 7-zip on macOS, first install Homebrew, and then use Homebrew to install the p7zip package that contains 7-zip.

brew install p7zip

On Linux, you can usually install 7-zip from your distribution's package repository. For example, for apt-based distributions:

sudo apt update
sudo apt install -y p7zip-full

or for dnf-based distrubtions

sudo dnf install p7zip

Running an experiment

The core function of OpenTTD is the setup_experiment function.

from openttdlab import setup_experiment, save_config

# If necessary, this will download the latest OpenTTD
run_experiment, get_config = setup_experiment()

# Run the experiment and get results. This may take time
results = run_experiment()
print(results)

# The information needed to reproduce the experiment
config = get_config()
print(config)

# Which can be saved to a file and then shared
save_config('my-config.yml', config)

Reproducing an experiment

If you have the config from a previous experiment, you can pass it into setup_experiment to exactly reproduce

from openttdlab import setup_experiment, load_config

# Load the config from file
config = load_config('my-config.yml')

# allow_platform_difference=True will allow experiments from a platform other than the one
# the original experiments were performed on. Otherwise, setup_experiment may error because
# the exact same OpenTTD will not be able to be run on this platform
run_experiment, get_config = setup_experiment(config=config, allow_platform_difference=True)

# Run the experiment and get results
results = run_experiment()
print(results)

API design considerations

  • Mutability is avoided
  • Impure functions are avoided
  • In terms of the user-facing API, keeping it mostly OOP-free, and deliberately focused on key behaviour
  • Designed so if type checking were in place and passes, API misuse should be close to impossible

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

openttdlab-0.0.6.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

openttdlab-0.0.6-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file openttdlab-0.0.6.tar.gz.

File metadata

  • Download URL: openttdlab-0.0.6.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for openttdlab-0.0.6.tar.gz
Algorithm Hash digest
SHA256 64c2f27d2ad9e3991571b126b7b8dc0dc8b4547ea4f4d5b9fe1ba48fcdac775a
MD5 77dff344f3fdd53401306928ee3d3f31
BLAKE2b-256 59d15f6e21b79c11e6114c8e1172e39b226358c7b9f94583094541cb4354771a

See more details on using hashes here.

Provenance

File details

Details for the file openttdlab-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: openttdlab-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for openttdlab-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7b2f1c48dc75dc521c593b4bb8a71477fe817a04faebaf640dd797759cfe4c16
MD5 782488b97814b488ab907039a3178350
BLAKE2b-256 fd5d1bb332a9293d8e6fe032a5181784e91f07d728c2b94012e2ad798c2b17ba

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page