Skip to content

Commit

Permalink
Merge pull request #4 from gjbex/development
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
gjbex authored Dec 3, 2019
2 parents e539abf + 8f98de4 commit 1c20045
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
Binary file modified python_for_systems_programming.pptx
Binary file not shown.
16 changes: 9 additions & 7 deletions source-code/application/my_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def generate_data(n, a=0, b=1):
return [random.randint(a, b) for _ in range(n)]

def main():
arg_parser = ArgumentParser(description='test application')
arg_parser = ArgumentParser(add_help=False)
arg_parser.add_argument('--conf',
help='configuration file to use')
arg_parser.add_argument('--verbose', action='store_true',
Expand All @@ -36,12 +36,14 @@ def main():
print('user configuration file values:', file=sys.stderr)
cfg.write(sys.stderr)
cfg_opts = dict(cfg['defaults'])
arg_parser.set_defaults(**cfg_opts)
arg_parser.add_argument('n', type=int, nargs='?',
help='number of random values to generate')
arg_parser.add_argument('--a', type=int, help='smallest value')
arg_parser.add_argument('--b', type=int, help='largest value')
arg_parser.parse_args(remaining_options, options)
arg_parser_cl = ArgumentParser(description='test application',
parents=[arg_parser])
arg_parser_cl.set_defaults(**cfg_opts)
arg_parser_cl.add_argument('n', type=int, nargs='?',
help='number of random values to generate')
arg_parser_cl.add_argument('--a', type=int, help='smallest value')
arg_parser_cl.add_argument('--b', type=int, help='largest value')
arg_parser_cl.parse_args(remaining_options, options)
if options.verbose:
print('final options:', file=sys.stderr)
print(f'n = {options.n}\na = {options.a}\nb = {options.b}', end='\n\n',
Expand Down
20 changes: 20 additions & 0 deletions source-code/hydra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,23 @@ multiruns and so on.
1. `config.yaml`: configuration file with the defaults.
1. `distr/gauss.yaml`: configuration file for the Gaussian distirubtion.
1. `distr/uniform.yaml`: configuration file for the uniform distirubtion.

## How to use it?
Run with configuratino file settings:
```bash
$ ./gen_rand.py
```
To increase the number of random values:
```bash
$ ./gen_rand.py 10
```

To use a uniform distribution:
```bash
$ ./gen_rand.py distr=uniform
```

To use a uniform distribution between -1 and 0:
```bash
$ ./gen_rand.py distr=uniform distr.a=-1.0 distr.b=0.0
```
2 changes: 1 addition & 1 deletion source-code/hydra/gen_rand.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def gen_rand(cfg):
if cfg.n <= 0:
LOG.error(f'negative number to generate {cfg.n}')
return 1
LOG.info(f'genrating {cfg.n} random numbers')
LOG.info(f'generating {cfg.n} random numbers')
LOG.info(f'using {cfg.distr.name} distribution')
if cfg.distr.name == 'gauss':
LOG.info(f'mu={cfg.distr.mu}, sigma={cfg.distr.sigma}')
Expand Down

0 comments on commit 1c20045

Please sign in to comment.