Skip to content

Commit

Permalink
docs: add example to jupyter notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoVoges committed May 25, 2023
1 parent 1a581cc commit 7e0ec3c
Showing 1 changed file with 111 additions and 1 deletion.
112 changes: 111 additions & 1 deletion docs/notebook/Tutorial.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -14,6 +15,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -45,6 +47,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -79,6 +82,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -112,6 +116,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -149,6 +154,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -190,6 +196,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -227,6 +234,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -265,6 +273,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -303,6 +312,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -334,6 +344,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -365,6 +376,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -396,6 +408,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -416,6 +429,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -436,6 +450,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -456,6 +471,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -487,6 +503,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -523,6 +540,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -534,6 +552,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -594,6 +613,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -627,6 +647,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -661,6 +682,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -694,6 +716,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -714,6 +737,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -771,6 +795,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -811,13 +836,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Decoding strings with interpolations"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -876,13 +903,15 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Custom interpolations"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -917,6 +946,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -946,6 +976,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1004,6 +1035,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -1112,6 +1144,84 @@
"conf.merge_with_cli()\n",
"print(OmegaConf.to_yaml(conf))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The default behavior for lists is that the list from the last config overwrites the others. \n",
"Use `OmegaConf.merge(cfg1, cfg2, extend_lists=True)` to merge the lists by extending them. \n",
"You can specify whether duplicate entries are allowed with the flag `allow_duplicates`. \n",
"This is false, by default, but is only compatible with `extend_lists` activated."
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"`example2.yaml` file:\n",
"```yaml\n",
"server:\n",
" port: 80\n",
"users:\n",
" - user1\n",
" - user2\n",
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"`example4.yaml` file:\n",
"```yaml\n",
"users:\n",
" - user3\n",
" - user2\n",
"```"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"If you load them and merge them with both attributes set to `True` you will get this:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from omegaconf import OmegaConf\n",
"\n",
"cfg_example2 = OmegaConf.load('source/example2.yaml')\n",
"cfg_example4 = OmegaConf.load('source/example4.yaml')\n",
"\n",
"conf = OmegaConf.merge(cfg_example2, cfg_example4, extend_lists=True, allow_duplicates=True)\n",
"print(OmegaConf.to_yaml(conf))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"```yaml\n",
"server:\n",
" port: 80\n",
"users:\n",
"- user1\n",
"- user2\n",
"- user3\n",
"- user2\n",
"```"
]
}
],
"metadata": {
Expand All @@ -1130,7 +1240,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
"version": "3.10.8"
},
"pycharm": {
"stem_cell": {
Expand Down

0 comments on commit 7e0ec3c

Please sign in to comment.