logo

... gin.


Gin is a system for configuring python code that is still very much in early phases, but very powerful.


Episode Notes

Sometimes you'd like a setting to be manditory but other times you'd prefer the exact opposite. Blacklists are the way to prevent settings being passed from the config.gin file.

config.gin

simulate.random_func = @random_triangle

random_triangle.minval = 0
random_triangle.maxval = 100

simulate.py

import gin
import random

@gin.configurable
def random_uniform(minval=0, maxval=1):
    return random.uniform(minval, maxval)

@gin.configurable
def random_triangle(minval=0, maxval=1):
    middle = (maxval - minval)/2
    return random.triangular(minval, maxval, middle)

@gin.configurable(blacklist=["n_samples"])
def simulate(random_func, n_samples):
    return sum(random_func() for i in range(n_samples))

if __name__ == "__main__":
    gin.parse_config_file('config.gin')
    print(simulate())

Feedback? See an issue? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.