Skip to content

Commit

Permalink
Update Argument Parser to use action="store_true" instead of 0/1 for …
Browse files Browse the repository at this point in the history
…boolean arguments. (#72)

I have replaced the parser.add_argument where the standard has been to
have an integer 0=False, 1=True with an action="store_true" instead.

Example:
OLD:
    parser.add_argument(
        "--restore_opt",
        type=int,
        default=0,
        help="If optimizer state should be restored with model "
        "(default: 0 (false))",
    )
NEW:
    parser.add_argument(
        "--restore_opt",
        action="store_true",
        help="If optimizer state should be restored with model "
        "(default: false)",
    )

This will save some time and characters when running the scripts from
the command line as well as being easier to understand as the parsed
variables are supposed to be booleans.
  • Loading branch information
ErikLarssonDev authored Sep 5, 2024
1 parent 4969f92 commit 68399f7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

Optional multi-core/GPU support for statistics calculation in `create_parameter_weights.py`
- Argument Parser updated to use action="store_true" instead of 0/1 for boolean arguments.
(https://github.com/mllam/neural-lam/pull/72)
@ErikLarssonDev

- Optional multi-core/GPU support for statistics calculation in `create_parameter_weights.py`
[\#22](https://github.com/mllam/neural-lam/pull/22)
@sadamov

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Run `python -m neural_lam.create_mesh` with suitable options to generate the gra
The graphs used for the different models in the [paper](https://arxiv.org/abs/2309.17370) can be created as:

* **GC-LAM**: `python -m neural_lam.create_mesh --graph multiscale`
* **Hi-LAM**: `python -m neural_lam.create_mesh --graph hierarchical --hierarchical 1` (also works for Hi-LAM-Parallel)
* **Hi-LAM**: `python -m neural_lam.create_mesh --graph hierarchical --hierarchical` (also works for Hi-LAM-Parallel)
* **L1-LAM**: `python -m neural_lam.create_mesh --graph 1level --levels 1`

The graph-related files are stored in a directory called `graphs`.
Expand Down
10 changes: 4 additions & 6 deletions neural_lam/create_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@ def main(input_args=None):
)
parser.add_argument(
"--plot",
type=int,
default=0,
action="store_true",
help="If graphs should be plotted during generation "
"(default: 0 (false))",
"(default: False)",
)
parser.add_argument(
"--levels",
Expand All @@ -182,9 +181,8 @@ def main(input_args=None):
)
parser.add_argument(
"--hierarchical",
type=int,
default=0,
help="Generate hierarchical mesh graph (default: 0, no)",
action="store_true",
help="Generate hierarchical mesh graph (default: False)",
)
args = parser.parse_args(input_args)

Expand Down
5 changes: 2 additions & 3 deletions neural_lam/create_parameter_weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,8 @@ def main():
)
parser.add_argument(
"--distributed",
type=int,
default=0,
help="Run the script in distributed mode (1) or not (0) (default: 0)",
action="store_true",
help="Run the script in distributed mode (default: False)",
)
args = parser.parse_args()
distributed = bool(args.distributed)
Expand Down
26 changes: 11 additions & 15 deletions neural_lam/train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ def main(input_args=None):
)
parser.add_argument(
"--subset_ds",
type=int,
default=0,
action="store_true",
help="Use only a small subset of the dataset, for debugging"
"(default: 0=false)",
"(default: false)",
)
parser.add_argument(
"--seed", type=int, default=42, help="random seed (default: 42)"
Expand All @@ -71,10 +70,9 @@ def main(input_args=None):
)
parser.add_argument(
"--restore_opt",
type=int,
default=0,
action="store_true",
help="If optimizer state should be restored with model "
"(default: 0 (false))",
"(default: false)",
)
parser.add_argument(
"--precision",
Expand Down Expand Up @@ -118,11 +116,10 @@ def main(input_args=None):
)
parser.add_argument(
"--output_std",
type=int,
default=0,
action="store_true",
help="If models should additionally output std.-dev. per "
"output dimensions "
"(default: 0 (no))",
"(default: False (no))",
)

# Training options
Expand All @@ -135,10 +132,9 @@ def main(input_args=None):
)
parser.add_argument(
"--control_only",
type=int,
default=0,
action="store_true",
help="Train only on control member of ensemble data "
"(default: 0 (False))",
"(default: False)",
)
parser.add_argument(
"--loss",
Expand Down Expand Up @@ -233,7 +229,7 @@ def main(input_args=None):
pred_length=args.ar_steps,
split="train",
subsample_step=args.step_length,
subset=bool(args.subset_ds),
subset=args.subset_ds,
control_only=args.control_only,
),
args.batch_size,
Expand All @@ -247,7 +243,7 @@ def main(input_args=None):
pred_length=max_pred_length,
split="val",
subsample_step=args.step_length,
subset=bool(args.subset_ds),
subset=args.subset_ds,
control_only=args.control_only,
),
args.batch_size,
Expand Down Expand Up @@ -313,7 +309,7 @@ def main(input_args=None):
pred_length=max_pred_length,
split="test",
subsample_step=args.step_length,
subset=bool(args.subset_ds),
subset=args.subset_ds,
),
args.batch_size,
shuffle=False,
Expand Down
5 changes: 2 additions & 3 deletions plot_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ def main():
)
parser.add_argument(
"--show_axis",
type=int,
default=0,
help="If the axis should be displayed (default: 0 (No))",
action="store_true",
help="If the axis should be displayed (default: False)",
)

args = parser.parse_args()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mllam_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_load_reduced_meps_dataset(meps_example_reduced_filepath):
def test_create_graph_reduced_meps_dataset():
args = [
"--graph=hierarchical",
"--hierarchical=1",
"--hierarchical",
"--data_config=data/meps_example_reduced/data_config.yaml",
"--levels=2",
]
Expand Down

0 comments on commit 68399f7

Please sign in to comment.