pyibis-ami 7.2.3__py3-none-any.whl → 7.2.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,144 +1,144 @@
1
- #! /usr/bin/env python
2
-
3
- """
4
- Run an IBIS-AMI model through a Jupyter notebook, generating an HTML report.
5
-
6
- Original Author: David Banas
7
-
8
- Original Date: January 31, 2025
9
-
10
- Copyright (c) 2025 David Banas; all rights reserved World wide.
11
- """
12
-
13
- import os
14
- from pathlib import Path
15
- import subprocess
16
- from time import time
17
- from typing import Any, Optional
18
-
19
- import click
20
-
21
- NOTEBOOK = Path(__file__).parent.parent.joinpath("IBIS_AMI_Tester.ipynb")
22
-
23
-
24
- def run_notebook(
25
- ibis_file: Path,
26
- notebook: Path,
27
- out_dir: Optional[Path] = None,
28
- notebook_params: Optional[dict[str, Any]] = None,
29
- ) -> None:
30
- """
31
- Run a Jupyter notebook on the target IBIS-AMI model.
32
-
33
- Args:
34
- ibis_file: The ``*.ibs`` file to test.
35
- (Presumably, an IBIS-AMI model.)
36
- notebook: The *Jupyter* notebook to use for testing the model.
37
-
38
- Keyword Args:
39
- out_dir: The directory into which to place the resultant HTML file.
40
- Default: None (Use the directory containing the ``*.ibs`` file.)
41
- notebook_params: An optional dictionary of parameter overrides for the notebook.
42
- Default: None
43
- """
44
-
45
- start_time = time()
46
-
47
- # Validate input.
48
- if not ibis_file.exists():
49
- raise RuntimeError(f"Can't find IBIS-AMI model file, {ibis_file}!")
50
- if not notebook.exists():
51
- raise RuntimeError(f"Can't find notebook file, {notebook}!")
52
-
53
- # Define temp. (i.e. - parameterized) notebook and output file locations.
54
- tmp_dir = (
55
- os.environ.get("TMP") or os.environ.get("TEMP") or # noqa: W504
56
- (Path(os.environ.get("HOME")).joinpath("tmp") # type: ignore
57
- if os.environ.get("HOME")
58
- else "/tmp")
59
- )
60
- tmp_dir = Path(tmp_dir)
61
- tmp_dir.mkdir(exist_ok=True)
62
- tmp_notebook = tmp_dir.joinpath(notebook.stem + "_papermill").with_suffix(".ipynb")
63
- out_dir = out_dir or ibis_file.resolve().parent
64
- out_dir.mkdir(exist_ok=True)
65
- html_file = Path(out_dir.joinpath(ibis_file.name)).with_suffix(".html")
66
-
67
- # Run the notebook.
68
- print(f"Testing IBIS-AMI model: {ibis_file},")
69
- print(f"using notebook: {notebook},")
70
- print(f"sending HTML output to: {html_file}...")
71
-
72
- try:
73
- extra_args = []
74
- if notebook_params:
75
- extra_args = [tok for item in notebook_params.items()
76
- for tok in ['-p', f'{item[0]}', f'{item[1]}']] # noqa: E127
77
- subprocess.run(['papermill', str(notebook), str(tmp_notebook)] + extra_args, check=True)
78
- except Exception:
79
- print(f"notebook: {notebook}")
80
- print(f"tmp_notebook: {tmp_notebook}")
81
- raise
82
- subprocess.run(
83
- ['jupyter', 'nbconvert', '--to', 'html', '--no-input', '--output', html_file, tmp_notebook],
84
- check=True)
85
-
86
- run_time = int(time() - start_time) # integer seconds
87
- hours, rem_secs = divmod(run_time, 3600)
88
- minutes, seconds = divmod(rem_secs, 60)
89
- print(f"Done after {hours} hrs., {minutes} min., {seconds} sec.")
90
-
91
-
92
- @click.command(context_settings={"ignore_unknown_options": False,
93
- "help_option_names": ["-h", "--help"]})
94
- @click.option(
95
- "--notebook", "-n", default=NOTEBOOK, type=click.Path(exists=True),
96
- help="Override the default notebook file name."
97
- )
98
- @click.option(
99
- "--out-dir", "-o", default=None, type=click.Path(),
100
- help="Override the name of the directory in which to place the results."
101
- )
102
- @click.option(
103
- "--params", "-p",
104
- default='',
105
- help='Directory (or, file) containing configuration sweeps.',
106
- )
107
- @click.option("--debug", is_flag=True, help="Provide extra debugging information.")
108
- @click.option("--is_tx", is_flag=True, help="Flags a Tx model.")
109
- @click.option("--nspui", default=32, show_default=True, help="Number of samples per unit interval.")
110
- @click.option("--nbits", default=200, show_default=True, help="Number of bits to run in simulations.")
111
- @click.option("--plot-t-max", default=0.5e-9, show_default=True, help="Maximum time value for plots (s).")
112
- @click.option("--f-max", default=40e9, show_default=True, help="Maximum frequency for transfer functions (Hz).")
113
- @click.option("--f-step", default=10e6, show_default=True, help="Frequency step for transfer functions (Hz).")
114
- @click.option("--fig-x", default=10, show_default=True, help="x-dimmension for plot figures (in).")
115
- @click.option("--fig-y", default=3, show_default=True, help="y-dimmension for plot figures (in).")
116
- @click.argument("ibis_file", type=click.Path(exists=True))
117
- @click.argument("bit_rate", type=float)
118
- @click.version_option(package_name="PyIBIS-AMI")
119
- # pylint: disable=too-many-arguments,too-many-positional-arguments
120
- def main(notebook, out_dir, params, ibis_file, bit_rate, debug, is_tx, nspui, nbits,
121
- plot_t_max, f_max, f_step, fig_x, fig_y):
122
- "Run a *Jupyter* notebook on an IBIS-AMI model file."
123
- run_notebook(
124
- Path(ibis_file).resolve(), Path(notebook).resolve(),
125
- out_dir=out_dir,
126
- notebook_params={
127
- 'ibis_dir': ".",
128
- 'ibis_file': ibis_file,
129
- 'debug': debug,
130
- 'is_tx': is_tx,
131
- 'nspui': nspui,
132
- 'nbits': nbits,
133
- 'plot_t_max': plot_t_max,
134
- 'f_max': f_max,
135
- 'f_step': f_step,
136
- 'fig_x': fig_x,
137
- 'fig_y': fig_y,
138
- 'bit_rate': bit_rate,
139
- 'params': params,
140
- })
141
-
142
-
143
- if __name__ == "__main__":
144
- main() # pylint: disable=no-value-for-parameter
1
+ #! /usr/bin/env python
2
+
3
+ """
4
+ Run an IBIS-AMI model through a Jupyter notebook, generating an HTML report.
5
+
6
+ Original Author: David Banas
7
+
8
+ Original Date: January 31, 2025
9
+
10
+ Copyright (c) 2025 David Banas; all rights reserved World wide.
11
+ """
12
+
13
+ import os
14
+ from pathlib import Path
15
+ import subprocess
16
+ from time import time
17
+ from typing import Any, Optional
18
+
19
+ import click
20
+
21
+ NOTEBOOK = Path(__file__).parent.parent.joinpath("IBIS_AMI_Tester.ipynb")
22
+
23
+
24
+ def run_notebook(
25
+ ibis_file: Path,
26
+ notebook: Path,
27
+ out_dir: Optional[Path] = None,
28
+ notebook_params: Optional[dict[str, Any]] = None,
29
+ ) -> None:
30
+ """
31
+ Run a Jupyter notebook on the target IBIS-AMI model.
32
+
33
+ Args:
34
+ ibis_file: The ``*.ibs`` file to test.
35
+ (Presumably, an IBIS-AMI model.)
36
+ notebook: The *Jupyter* notebook to use for testing the model.
37
+
38
+ Keyword Args:
39
+ out_dir: The directory into which to place the resultant HTML file.
40
+ Default: None (Use the directory containing the ``*.ibs`` file.)
41
+ notebook_params: An optional dictionary of parameter overrides for the notebook.
42
+ Default: None
43
+ """
44
+
45
+ start_time = time()
46
+
47
+ # Validate input.
48
+ if not ibis_file.exists():
49
+ raise RuntimeError(f"Can't find IBIS-AMI model file, {ibis_file}!")
50
+ if not notebook.exists():
51
+ raise RuntimeError(f"Can't find notebook file, {notebook}!")
52
+
53
+ # Define temp. (i.e. - parameterized) notebook and output file locations.
54
+ tmp_dir = (
55
+ os.environ.get("TMP") or os.environ.get("TEMP") or # noqa: W504
56
+ (Path(os.environ.get("HOME")).joinpath("tmp") # type: ignore
57
+ if os.environ.get("HOME")
58
+ else "/tmp")
59
+ )
60
+ tmp_dir = Path(tmp_dir)
61
+ tmp_dir.mkdir(exist_ok=True)
62
+ tmp_notebook = tmp_dir.joinpath(notebook.stem + "_papermill").with_suffix(".ipynb")
63
+ out_dir = out_dir or ibis_file.resolve().parent
64
+ out_dir.mkdir(exist_ok=True)
65
+ html_file = Path(out_dir.joinpath(ibis_file.name)).with_suffix(".html")
66
+
67
+ # Run the notebook.
68
+ print(f"Testing IBIS-AMI model: {ibis_file},")
69
+ print(f"using notebook: {notebook},")
70
+ print(f"sending HTML output to: {html_file}...")
71
+
72
+ try:
73
+ extra_args = []
74
+ if notebook_params:
75
+ extra_args = [tok for item in notebook_params.items()
76
+ for tok in ['-p', f'{item[0]}', f'{item[1]}']] # noqa: E127
77
+ subprocess.run(['papermill', str(notebook), str(tmp_notebook)] + extra_args, check=True)
78
+ except Exception:
79
+ print(f"notebook: {notebook}")
80
+ print(f"tmp_notebook: {tmp_notebook}")
81
+ raise
82
+ subprocess.run(
83
+ ['jupyter', 'nbconvert', '--to', 'html', '--no-input', '--output', html_file, tmp_notebook],
84
+ check=True)
85
+
86
+ run_time = int(time() - start_time) # integer seconds
87
+ hours, rem_secs = divmod(run_time, 3600)
88
+ minutes, seconds = divmod(rem_secs, 60)
89
+ print(f"Done after {hours} hrs., {minutes} min., {seconds} sec.")
90
+
91
+
92
+ @click.command(context_settings={"ignore_unknown_options": False,
93
+ "help_option_names": ["-h", "--help"]})
94
+ @click.option(
95
+ "--notebook", "-n", default=NOTEBOOK, type=click.Path(exists=True),
96
+ help="Override the default notebook file name."
97
+ )
98
+ @click.option(
99
+ "--out-dir", "-o", default=None, type=click.Path(),
100
+ help="Override the name of the directory in which to place the results."
101
+ )
102
+ @click.option(
103
+ "--params", "-p",
104
+ default='',
105
+ help='Directory (or, file) containing configuration sweeps.',
106
+ )
107
+ @click.option("--debug", is_flag=True, help="Provide extra debugging information.")
108
+ @click.option("--is_tx", is_flag=True, help="Flags a Tx model.")
109
+ @click.option("--nspui", default=32, show_default=True, help="Number of samples per unit interval.")
110
+ @click.option("--nbits", default=200, show_default=True, help="Number of bits to run in simulations.")
111
+ @click.option("--plot-t-max", default=0.5e-9, show_default=True, help="Maximum time value for plots (s).")
112
+ @click.option("--f-max", default=40e9, show_default=True, help="Maximum frequency for transfer functions (Hz).")
113
+ @click.option("--f-step", default=10e6, show_default=True, help="Frequency step for transfer functions (Hz).")
114
+ @click.option("--fig-x", default=10, show_default=True, help="x-dimmension for plot figures (in).")
115
+ @click.option("--fig-y", default=3, show_default=True, help="y-dimmension for plot figures (in).")
116
+ @click.argument("ibis_file", type=click.Path(exists=True))
117
+ @click.argument("bit_rate", type=float)
118
+ @click.version_option(package_name="PyIBIS-AMI")
119
+ # pylint: disable=too-many-arguments,too-many-positional-arguments
120
+ def main(notebook, out_dir, params, ibis_file, bit_rate, debug, is_tx, nspui, nbits,
121
+ plot_t_max, f_max, f_step, fig_x, fig_y):
122
+ "Run a *Jupyter* notebook on an IBIS-AMI model file."
123
+ run_notebook(
124
+ Path(ibis_file).resolve(), Path(notebook).resolve(),
125
+ out_dir=out_dir,
126
+ notebook_params={
127
+ 'ibis_dir': ".",
128
+ 'ibis_file': ibis_file,
129
+ 'debug': debug,
130
+ 'is_tx': is_tx,
131
+ 'nspui': nspui,
132
+ 'nbits': nbits,
133
+ 'plot_t_max': plot_t_max,
134
+ 'f_max': f_max,
135
+ 'f_step': f_step,
136
+ 'fig_x': fig_x,
137
+ 'fig_y': fig_y,
138
+ 'bit_rate': bit_rate,
139
+ 'params': params,
140
+ })
141
+
142
+
143
+ if __name__ == "__main__":
144
+ main() # pylint: disable=no-value-for-parameter