{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Anyfig Online Demo\n", "\n", "This notebook will allow you to play around with Anyfig directly in your browser, no installation required!\n", "\n", "For more information about Anyfig, check out our website [https://anyfig.now.sh/](https://anyfig.now.sh/)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Defining Config Classes" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import anyfig\n", "from pathlib import Path\n", "import time\n", "anyfig.unregister_config_classes() # Needed for notebooks\n", "\n", "@anyfig.config_class # Registers the class with anyfig\n", "class MyConfig():\n", " def __init__(self):\n", " # Config-parameters goes as attributes\n", " self.experiment_note = 'Changed stuff'\n", " self.save_directory = Path('output')\n", " self.start_time = time.time()\n", " \n", " self.inner_config = InnerConfig()\n", " \n", "@anyfig.config_class \n", "class InnerConfig():\n", " def __init__(self):\n", " self.inception = \"Yo Dawg\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Initialize the Config\n", "Anyfig supports command line input but it doesn't work in notebooks. Luckily a dict can be used to simulate the behaviour." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": "Without command line input:\nMyConfig:\n experiment_note (str): Changed stuff\n save_directory (PosixPath): output\n start_time (float): 1598543535.0318332\n inner_config (InnerConfig): \n inception (str): Yo Dawg\n\nWith command line input:\nMyConfig:\n experiment_note (str): new note\n save_directory (PosixPath): string-becomes-path\n start_time (float): 1598543535.032667\n inner_config (InnerConfig): \n inception (str): nested-input-support\n" } ], "source": [ "cli_args = {} # No input parameters\n", "config = anyfig.init_config(default_config=MyConfig, cli_args=cli_args)\n", "print('Without command line input:', config, sep='\\n')\n", "\n", "# Input parameters of string type\n", "cli_args = {\n", " 'experiment_note': 'new note',\n", " 'save_directory': 'string-becomes-path',\n", " 'inner_config.inception': 'nested-input-support'\n", "}\n", "config = anyfig.init_config(default_config=MyConfig, cli_args=cli_args)\n", "print('\\nWith command line input:', config, sep='\\n')" ] } ], "metadata": { "kernelspec": { "display_name": "anyfig", "language": "python", "name": "anyfig" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.3" } }, "nbformat": 4, "nbformat_minor": 2 }