Anyfig Online Demo

This notebook will allow you to play around with Anyfig directly in your browser, no installation required!

For more information about Anyfig, check out our website https://anyfig.now.sh/

Defining Config Classes

In [1]:
import anyfig
from pathlib import Path
import time
anyfig.unregister_config_classes() # Needed for notebooks

@anyfig.config_class  # Registers the class with anyfig
class MyConfig():
    def __init__(self):
        # Config-parameters goes as attributes
        self.experiment_note = 'Changed stuff'
        self.save_directory = Path('output')
        self.start_time = time.time()
        
        self.inner_config = InnerConfig()
        
@anyfig.config_class        
class InnerConfig():
    def __init__(self):
        self.inception = "Yo Dawg"

Initialize the Config

Anyfig supports command line input but it doesn't work in notebooks. Luckily a dict can be used to simulate the behaviour.

In [2]:
cli_args = {} # No input parameters
config = anyfig.init_config(default_config=MyConfig, cli_args=cli_args)
print('Without command line input:', config, sep='\n')

# Input parameters of string type
cli_args = {
  'experiment_note': 'new note',
  'save_directory': 'string-becomes-path',
  'inner_config.inception': 'nested-input-support'
}
config = anyfig.init_config(default_config=MyConfig, cli_args=cli_args)
print('\nWith command line input:', config, sep='\n')
Without command line input:
MyConfig:
    experiment_note (str): Changed stuff
    save_directory (PosixPath): output
    start_time (float): 1598543535.0318332
    inner_config (InnerConfig): 
        inception (str): Yo Dawg

With command line input:
MyConfig:
    experiment_note (str): new note
    save_directory (PosixPath): string-becomes-path
    start_time (float): 1598543535.032667
    inner_config (InnerConfig): 
        inception (str): nested-input-support