From 3e3bd0be28308fb108e9f7699668e50386c1f1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Gro=C3=9F?= Date: Mon, 15 Jul 2024 11:33:30 +0200 Subject: [PATCH 1/5] Add tqdm to vis_loop --- pyvisgen/simulation/visibility.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pyvisgen/simulation/visibility.py b/pyvisgen/simulation/visibility.py index 0e720eb..24bb96e 100644 --- a/pyvisgen/simulation/visibility.py +++ b/pyvisgen/simulation/visibility.py @@ -4,6 +4,8 @@ import pyvisgen.simulation.scan as scan +from tqdm import tqdm + @dataclass class Visibilities: @@ -37,7 +39,7 @@ def add(self, visibilities): ] -def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full"): +def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100): torch.set_num_threads(num_threads) torch._dynamo.config.suppress_errors = True @@ -93,7 +95,7 @@ def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full"): else: raise ValueError("Unsupported mode!") - for p in torch.arange(bas[:].shape[1]).split(1000): + for p in tqdm(torch.arange(bas[:].shape[1]).split(batch_size)): bas_p = bas[:][:, p] int_values = torch.cat( @@ -163,4 +165,4 @@ def generate_noise(shape, obs, SEFD): noise = torch.normal(mean=0, std=std, size=shape, device=obs.device) noise = noise + 1.0j * torch.normal(mean=0, std=std, size=shape, device=obs.device) - return noise + return noise \ No newline at end of file From 2be7d2e470cb35883b3626128e5710674fc00115 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Gro=C3=9F?= Date: Mon, 15 Jul 2024 11:45:47 +0200 Subject: [PATCH 2/5] Add changelog --- docs/changes/33.feature.rst | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/changes/33.feature.rst diff --git a/docs/changes/33.feature.rst b/docs/changes/33.feature.rst new file mode 100644 index 0000000..2864257 --- /dev/null +++ b/docs/changes/33.feature.rst @@ -0,0 +1,3 @@ +Changes to `vis_loop` function in `visibility.py`: +- add a tqdm progress bar to get a visual confirmation the calculation is still running +- add optional `batch_size` parameter to control memory consumption From 0babea92ce3e3f9cb4515934baaf7ae1758b8cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Gro=C3=9F?= Date: Mon, 15 Jul 2024 13:29:26 +0200 Subject: [PATCH 3/5] Change tqdm for vis_loop to optional --- pyvisgen/simulation/visibility.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyvisgen/simulation/visibility.py b/pyvisgen/simulation/visibility.py index 24bb96e..4c4d754 100644 --- a/pyvisgen/simulation/visibility.py +++ b/pyvisgen/simulation/visibility.py @@ -39,7 +39,7 @@ def add(self, visibilities): ] -def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100): +def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100, use_tqdm=False): torch.set_num_threads(num_threads) torch._dynamo.config.suppress_errors = True @@ -95,7 +95,12 @@ def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100): else: raise ValueError("Unsupported mode!") - for p in tqdm(torch.arange(bas[:].shape[1]).split(batch_size)): + batches = torch.arange(bas[:].shape[1]).split(batch_size) + + if use_tqdm: + batches = tqdm(batches) + + for p in batches: bas_p = bas[:][:, p] int_values = torch.cat( From d69b898f6dadb2e05a0aff6153dcdde08dbb8cec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Gro=C3=9F?= Date: Mon, 15 Jul 2024 13:38:40 +0200 Subject: [PATCH 4/5] Update changelog --- docs/changes/33.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changes/33.feature.rst b/docs/changes/33.feature.rst index 2864257..cc83a98 100644 --- a/docs/changes/33.feature.rst +++ b/docs/changes/33.feature.rst @@ -1,3 +1,3 @@ Changes to `vis_loop` function in `visibility.py`: -- add a tqdm progress bar to get a visual confirmation the calculation is still running +- add a an optional tqdm progress bar to get a visual confirmation the calculation is still running - add optional `batch_size` parameter to control memory consumption From 79ddd58b58536bff8b3430fb441fbd23c4141654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Gro=C3=9F?= Date: Thu, 18 Jul 2024 15:57:48 +0200 Subject: [PATCH 5/5] Update visibility.py Change `use_tqdm` variable name to `show_progress` --- pyvisgen/simulation/visibility.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyvisgen/simulation/visibility.py b/pyvisgen/simulation/visibility.py index 4c4d754..492c9ae 100644 --- a/pyvisgen/simulation/visibility.py +++ b/pyvisgen/simulation/visibility.py @@ -39,7 +39,7 @@ def add(self, visibilities): ] -def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100, use_tqdm=False): +def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100, show_progress=False): torch.set_num_threads(num_threads) torch._dynamo.config.suppress_errors = True @@ -97,7 +97,7 @@ def vis_loop(obs, SI, num_threads=10, noisy=True, mode="full", batch_size=100, u batches = torch.arange(bas[:].shape[1]).split(batch_size) - if use_tqdm: + if show_progress: batches = tqdm(batches) for p in batches: @@ -170,4 +170,4 @@ def generate_noise(shape, obs, SEFD): noise = torch.normal(mean=0, std=std, size=shape, device=obs.device) noise = noise + 1.0j * torch.normal(mean=0, std=std, size=shape, device=obs.device) - return noise \ No newline at end of file + return noise