Skip to content

Commit 2ca2b5b

Browse files
Introduce better argument order (#213)
Fixes argument order so that liskov can be more easily integrated in to the ICON build system.
1 parent 4d354a9 commit 2ca2b5b

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

liskov/README.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,32 @@ To install the icon4py-liskov package, follow the instructions in the `README.md
88

99
## Description
1010

11-
The icon4py-liskov package includes the `icon_liskov` CLI tool which takes a fortran file as input and processes it with the ICON-Liskov DSL Preprocessor. This preprocessor adds the necessary `USE` statements and generates OpenACC `DATA CREATE` statements and declares DSL input/output fields based on directives in the input file. The preprocessor also processes stencils defined in the input file using the `START STENCIL` and `END STENCIL` directives, inserting the necessary code to run the stencils and adding nvtx profile statements if specified with the `--profile` or `-p` flag. Additionally, specifying the `--metadatagen` or `-m` flag will result in the generation of runtime metadata at the top of the generated file. Note that this requires `git` to be available in the shell from which `icon_liskov` is executed.
11+
The icon4py-liskov package includes the `icon_liskov` CLI tool which takes a fortran file as input and processes it with the ICON-Liskov DSL Preprocessor, generating code and inserting that into the target output file.
12+
13+
`icon_liskov` can either operate in **integration** or **serialisation** mode. In **integration** mode liskov generates calls to Fortran wrapper functions which enable calling icon4py DSL code inside of ICON from Fortran. In **serialisation** mode ppser serialbox statements are generated allowing the serialisation of all variables in all stencils decorated with liskov directives.
1214

1315
### Usage
1416

15-
To use the `icon_liskov` tool, run the following command:
17+
#### Integration mode
18+
19+
```bash
20+
icon_liskov integrate [--profile] [--metadatagen] <input_filepath> <output_filepath>
21+
```
22+
23+
Options:
24+
25+
- `profile`: adds nvtx profile statements to the stencils (optional).
26+
- `metadatagen`: generates a metadata header at the top of the file which includes information on icon_liskov such as the version used.
27+
28+
#### Serialisation mode
1629

1730
```bash
18-
icon_liskov <input_filepath> <output_filepath> [--profile] [--metadatagen] [--ppser]
31+
icon_liskov serialise [--multinode] <input_filepath> <output_filepath>
1932
```
2033

21-
The following are descriptions of the arguments and options:
34+
Options:
2235

23-
- input_filepath: path to the input file to be processed.
24-
- output_filepath: path to the output file.
25-
- profile flag: adds nvtx profile statements to the stencils (optional).
26-
- metadatagen flag: generates a metadata header at the top of the file which includes information on icon_liskov such as the version used.
27-
- ppser flag: activates serialisation mode and will trigger the generation of ppser serialisation statements serialising all variables at the start and end of each stencil directive.
36+
- `multinode`: ppser init contains the rank of the MPI process to facilitate writing files in a multinode context.
2837

2938
**Note**: By default the data will be saved at the default folder location of the currently run experiment and will have a prefix of `liskov-serialisation`.
3039

liskov/src/icon4py/liskov/cli.py

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,12 @@
2828

2929
@click.group(invoke_without_command=True)
3030
@click.pass_context
31-
@click.argument(
32-
"input_path",
33-
type=click.Path(
34-
exists=True, dir_okay=False, resolve_path=True, path_type=pathlib.Path
35-
),
36-
)
37-
@click.argument(
38-
"output_path",
39-
type=click.Path(dir_okay=False, resolve_path=True, path_type=pathlib.Path),
40-
)
41-
def main(ctx, input_path, output_path):
42-
"""Command line interface for interacting with the ICON-Liskov DSL Preprocessor.
43-
44-
Arguments:
45-
INPUT_PATH: Path to input file containing Liskov directives.
46-
OUTPUT_PATH: Path to new file to be generated.
47-
"""
31+
def main(ctx):
32+
"""Command line interface for interacting with the ICON-Liskov DSL Preprocessor."""
4833
if ctx.invoked_subcommand is None:
4934
click.echo(
5035
"Need to choose one of the following commands:\nintegrate\nserialise"
5136
)
52-
else:
53-
ctx.ensure_object(dict)
54-
ctx.obj["INPUT"] = input_path
55-
ctx.obj["OUTPUT"] = output_path
5637

5738

5839
@main.command()
@@ -68,17 +49,23 @@ def main(ctx, input_path, output_path):
6849
is_flag=True,
6950
help="Add metadata header with information about program.",
7051
)
71-
@click.pass_context
72-
def integrate(ctx, profile, metadatagen):
52+
@click.argument(
53+
"input_path",
54+
type=click.Path(
55+
exists=True, dir_okay=False, resolve_path=True, path_type=pathlib.Path
56+
),
57+
)
58+
@click.argument(
59+
"output_path",
60+
type=click.Path(dir_okay=False, resolve_path=True, path_type=pathlib.Path),
61+
)
62+
def integrate(input_path, output_path, profile, metadatagen):
7363
mode = "integration"
74-
inp = ctx.obj["INPUT"]
75-
out = ctx.obj["OUTPUT"]
76-
77-
iface = parse_fortran_file(inp, out, mode)
64+
iface = parse_fortran_file(input_path, output_path, mode)
7865
iface_gt4py = load_gt4py_stencils(iface)
7966
run_code_generation(
80-
inp,
81-
out,
67+
input_path,
68+
output_path,
8269
mode,
8370
iface_gt4py,
8471
profile=profile,
@@ -94,13 +81,20 @@ def integrate(ctx, profile, metadatagen):
9481
help="Specify whether it is a multinode run. Will generate mpi rank information.",
9582
default=False,
9683
)
97-
@click.pass_context
98-
def serialise(ctx, multinode):
84+
@click.argument(
85+
"input_path",
86+
type=click.Path(
87+
exists=True, dir_okay=False, resolve_path=True, path_type=pathlib.Path
88+
),
89+
)
90+
@click.argument(
91+
"output_path",
92+
type=click.Path(dir_okay=False, resolve_path=True, path_type=pathlib.Path),
93+
)
94+
def serialise(input_path, output_path, multinode):
9995
mode = "serialisation"
100-
inp = ctx.obj["INPUT"]
101-
out = ctx.obj["OUTPUT"]
102-
iface = parse_fortran_file(inp, out, mode)
103-
run_code_generation(inp, out, mode, iface, multinode=multinode)
96+
iface = parse_fortran_file(input_path, output_path, mode)
97+
run_code_generation(input_path, output_path, mode, iface, multinode=multinode)
10498

10599

106100
if __name__ == "__main__":

liskov/tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,6 @@ def outfile(tmp_path):
6464
)
6565
def test_cli(make_f90_tmpfile, cli, outfile, file_name, file_content, cmd, cmd_flags):
6666
fpath = str(make_f90_tmpfile(content=file_content))
67-
args = [fpath, outfile, cmd, *cmd_flags]
67+
args = [cmd, *cmd_flags, fpath, outfile]
6868
result = cli.invoke(main, args)
6969
assert result.exit_code == 0

0 commit comments

Comments
 (0)