Skip to main content

Python configuration file parser for evolutionary algorithms

Project description

snake_eyes

Python configuration file parser for evolutionary algorithms

Wrapper for the Python config parser to read an ini config file and return a dictionary of typed parameters. For documentation of Python configparser and ini use, see https://docs.python.org/3.8/library/configparser.html

ini sections are stored as sub-dictionaries in the return dict. Filenames support arbitrary extensions (like .cfg). Parameter names are case-sensitive.

The primary function you'll want is readConfig() which requires a valid filepath to your config file as the first parameter. You may also pass optional globalVars and localVars as optional second and third parameters, respectively, for use with expression evaluation. This enables the use of constants and imported/defined functions during the expression evaluation portion of parsing.

Example use:

# ...
from snakeeyes import readConfig
# ...
config = readConfig(myConfigPath, globals(), locals())

Parameter type precedence is as follows: Int Float Boolean Expression (returns result from evaluation) String

Example ini:

[DEFAULT]
# parameters in DEFAULT are inherited by all other sections
opponents = 5

[EXPERIMENT]
render = False
logpath = logs/comparison
runs = 5
evaluations = 3000

[POPULATION]
mu = 200
lambda = 100
parent = k tournament # evaluates to 'k tournament' despite inline comment
survival = truncation

[FEATURES]
floatTest = 1E3 # scientific notation supported for floats
mathTest = ${floatTest}+1 # allows references to other local params and basic python expressions
exprTest = max(${floatTest}, ${mathTest})
farRef = ${EXPERIMENT:evaluations} # allows references to params in other sections too

[QUIRKS]
float = 5.0 # this is evaluated as an int
bool = 1 # this is also evaluated as an int
error = random.random() # unknown libraries or syntax errors are silently treated as strings
functions = max # this returns a function object for max() builtin
string = 'max' # this returns a string

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

snake_eyes_parser-0.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

snake_eyes_parser-0.1.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snake_eyes_parser-0.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/4.4.0-22621-Microsoft

File hashes

Hashes for snake_eyes_parser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 556aedf7113b2c9ad0fe03f47c75223c11260308b4c30e1d7a3cbd9e2f747a49
MD5 85897312cf8415c2268429bea54e4332
BLAKE2b-256 7474d0527ebe402f5e3ba8b382d481165275860cb0133c564fd28d28223a5fb4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: snake_eyes_parser-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/4.4.0-22621-Microsoft

File hashes

Hashes for snake_eyes_parser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7e30e11a9e96bb5f2c7408ec0cbcfccfe7729e6f90b1651848dc1a5e9dde362
MD5 45a4b26cb73c0def098d7fad1459936c
BLAKE2b-256 56cee19cae3262a61c89c5855bf20ae814976179faef3b87940a4884dbfcd50b

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