Skip to content

Commit

Permalink
4489 Enhance hyperlinks of config syntax doc (#4490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic-Ma committed Jun 13, 2022
1 parent 0b97bb6 commit af0e0e9
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions docs/source/config_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Content:

- [A basic example](#a-basic-example)
- [Syntax examples explained](#syntax-examples-explained)
- [`@` to interpolate with Python objects](#1--to-interpolate-with-python-objects)
- [`$` to evaluate as Python expressions](#2--to-evaluate-as-python-expressions)
- [`%` to textually replace configuration elements](#3--to-textually-replace-configuration-elements)
- [`_target_` (`_disabled_` and `_requires_`) to instantiate a Python object](#4-instantiate-a-python-object)
- [`@` to reference Python objects in configurations](#to-reference-python-objects-in-configurations)
- [`$` to evaluate as Python expressions](#to-evaluate-as-python-expressions)
- [`%` to textually replace configuration elements](#to-textually-replace-configuration-elements)
- [`_target_` (`_disabled_` and `_requires_`) to instantiate a Python object](#instantiate-a-python-object)
- [The command line interface](#the-command-line-interface)
- [Recommendations](#recommendations)

Expand Down Expand Up @@ -73,22 +73,22 @@ For more details on the `ConfigParser` API, please see https://docs.monai.io/en/

A few characters and keywords are interpreted beyond the plain texts, here are examples of the syntax:

### 1. `@` to interpolate with Python objects
### To reference Python objects in configurations

```json
"@preprocessing#transforms#keys"
```

_Description:_ A reference to another configuration value defined at `preprocessing#transforms#keys`.
_Description:_ `@` character indicates a reference to another configuration value defined at `preprocessing#transforms#keys`.
where `#` indicates a sub-structure of this configuration file.

```json
"@preprocessing#1"
```

_Description:_ `1` is interpreted as an integer, which is used to index (zero-based indexing) the `preprocessing` sub-structure.
_Description:_ `1` is referencing as an integer, which is used to index (zero-based indexing) the `preprocessing` sub-structure.

### 2. `$` to evaluate as Python expressions
### To evaluate as Python expressions

```json
"$print(42)"
Expand All @@ -110,16 +110,16 @@ _Description:_ `$` followed by an import statement is handled slightly different
Python expressions. The imported module `resnet18` will be available as a global variable
to the other configuration sections. This is to simplify the use of external modules in the configuration.

### 3. `%` to textually replace configuration elements
### To textually replace configuration elements

```json
"%demo_config.json#demo_net#in_channels"
```

_Description:_ A macro to replace the current configuration element with the texts at `demo_net#in_channels` in the
_Description:_ `%` character indicates a macro to replace the current configuration element with the texts at `demo_net#in_channels` in the
`demo_config.json` file. The replacement is done before instantiating or evaluating the components.

### 4. instantiate a Python object
### Instantiate a Python object

```json
{
Expand Down Expand Up @@ -164,6 +164,7 @@ python -m monai.bundle COMMANDS
where `COMMANDS` is one of the following: `run`, `verify_metadata`, `ckpt_export`, ...
(please see `python -m monai.bundle --help` for a list of available options).

The CLI supports flexible use cases, such as overriding configs at runtime and predefining arguments in a file.
To display a usage page for a command, for example `run`:
```bash
python -m monai.bundle run -- --help
Expand All @@ -182,3 +183,5 @@ Details on the CLI argument parsing is provided in the
simple structures with sparse uses of expressions or references are preferred.
- For `$import <module>` in the configuration, please make sure there are instructions for the users to install
the `<module>` if it is not a (optional) dependency of MONAI.
- As "#" and "$" might be interpreted differently by the `shell` or `CLI` tools, may need to add escape characters
or quotes for them in the command line, like: `"\$torch.device('cuda:1')"`, `"'train_part#trainer'"`.

0 comments on commit af0e0e9

Please sign in to comment.