halib 0.2.4__tar.gz → 0.2.6__tar.gz

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.
Files changed (55) hide show
  1. {halib-0.2.4 → halib-0.2.6}/PKG-INFO +2 -2
  2. {halib-0.2.4 → halib-0.2.6}/README.md +1 -1
  3. {halib-0.2.4 → halib-0.2.6}/halib/exp/core/base_exp.py +22 -32
  4. {halib-0.2.4 → halib-0.2.6}/halib/filetype/yamlfile.py +6 -14
  5. {halib-0.2.4 → halib-0.2.6}/halib/system/path.py +32 -11
  6. {halib-0.2.4 → halib-0.2.6}/halib.egg-info/PKG-INFO +2 -2
  7. {halib-0.2.4 → halib-0.2.6}/setup.py +1 -1
  8. {halib-0.2.4 → halib-0.2.6}/.gitignore +0 -0
  9. {halib-0.2.4 → halib-0.2.6}/GDriveFolder.txt +0 -0
  10. {halib-0.2.4 → halib-0.2.6}/LICENSE.txt +0 -0
  11. {halib-0.2.4 → halib-0.2.6}/MANIFEST.in +0 -0
  12. {halib-0.2.4 → halib-0.2.6}/halib/__init__.py +0 -0
  13. {halib-0.2.4 → halib-0.2.6}/halib/common/__init__.py +0 -0
  14. {halib-0.2.4 → halib-0.2.6}/halib/common/common.py +0 -0
  15. {halib-0.2.4 → halib-0.2.6}/halib/common/rich_color.py +0 -0
  16. {halib-0.2.4 → halib-0.2.6}/halib/exp/__init__.py +0 -0
  17. {halib-0.2.4 → halib-0.2.6}/halib/exp/core/__init__.py +0 -0
  18. {halib-0.2.4 → halib-0.2.6}/halib/exp/core/base_config.py +0 -0
  19. {halib-0.2.4 → halib-0.2.6}/halib/exp/core/param_gen.py +0 -0
  20. {halib-0.2.4 → halib-0.2.6}/halib/exp/core/wandb_op.py +0 -0
  21. {halib-0.2.4 → halib-0.2.6}/halib/exp/data/__init__.py +0 -0
  22. {halib-0.2.4 → halib-0.2.6}/halib/exp/data/dataclass_util.py +0 -0
  23. {halib-0.2.4 → halib-0.2.6}/halib/exp/data/dataset.py +0 -0
  24. {halib-0.2.4 → halib-0.2.6}/halib/exp/data/torchloader.py +0 -0
  25. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/__init__.py +0 -0
  26. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/flop_calc.py +0 -0
  27. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/gpu_mon.py +0 -0
  28. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/perfcalc.py +0 -0
  29. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/perfmetrics.py +0 -0
  30. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/perftb.py +0 -0
  31. {halib-0.2.4 → halib-0.2.6}/halib/exp/perf/profiler.py +0 -0
  32. {halib-0.2.4 → halib-0.2.6}/halib/exp/viz/__init__.py +0 -0
  33. {halib-0.2.4 → halib-0.2.6}/halib/exp/viz/plot.py +0 -0
  34. {halib-0.2.4 → halib-0.2.6}/halib/filetype/__init__.py +0 -0
  35. {halib-0.2.4 → halib-0.2.6}/halib/filetype/csvfile.py +0 -0
  36. {halib-0.2.4 → halib-0.2.6}/halib/filetype/ipynb.py +0 -0
  37. {halib-0.2.4 → halib-0.2.6}/halib/filetype/jsonfile.py +0 -0
  38. {halib-0.2.4 → halib-0.2.6}/halib/filetype/textfile.py +0 -0
  39. {halib-0.2.4 → halib-0.2.6}/halib/filetype/videofile.py +0 -0
  40. {halib-0.2.4 → halib-0.2.6}/halib/online/__init__.py +0 -0
  41. {halib-0.2.4 → halib-0.2.6}/halib/online/gdrive.py +0 -0
  42. {halib-0.2.4 → halib-0.2.6}/halib/online/gdrive_mkdir.py +0 -0
  43. {halib-0.2.4 → halib-0.2.6}/halib/online/projectmake.py +0 -0
  44. {halib-0.2.4 → halib-0.2.6}/halib/online/tele_noti.py +0 -0
  45. {halib-0.2.4 → halib-0.2.6}/halib/system/__init__.py +0 -0
  46. {halib-0.2.4 → halib-0.2.6}/halib/system/cmd.py +0 -0
  47. {halib-0.2.4 → halib-0.2.6}/halib/system/filesys.py +0 -0
  48. {halib-0.2.4 → halib-0.2.6}/halib/utils/__init__.py +0 -0
  49. {halib-0.2.4 → halib-0.2.6}/halib/utils/dict.py +0 -0
  50. {halib-0.2.4 → halib-0.2.6}/halib/utils/list.py +0 -0
  51. {halib-0.2.4 → halib-0.2.6}/halib.egg-info/SOURCES.txt +0 -0
  52. {halib-0.2.4 → halib-0.2.6}/halib.egg-info/dependency_links.txt +0 -0
  53. {halib-0.2.4 → halib-0.2.6}/halib.egg-info/requires.txt +0 -0
  54. {halib-0.2.4 → halib-0.2.6}/halib.egg-info/top_level.txt +0 -0
  55. {halib-0.2.4 → halib-0.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: halib
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -53,7 +53,7 @@ Dynamic: summary
53
53
 
54
54
  # Helper package for coding and automation
55
55
 
56
- **Version 0.2.4**
56
+ **Version 0.2.6**
57
57
  + reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
58
58
 
59
59
  **Version 0.2.1**
@@ -1,6 +1,6 @@
1
1
  # Helper package for coding and automation
2
2
 
3
- **Version 0.2.4**
3
+ **Version 0.2.6**
4
4
  + reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
5
5
 
6
6
  **Version 0.2.1**
@@ -1,9 +1,16 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from typing import Tuple, Any, Optional
3
- from base_config import ExpBaseCfg
3
+ from .base_config import ExpBaseCfg
4
4
  from ..perf.perfcalc import PerfCalc
5
5
  from ..perf.perfmetrics import MetricsBackend
6
6
 
7
+
8
+ class ExpHook:
9
+ """Base interface for all experiment hooks."""
10
+ def on_before_run(self, exp): pass
11
+ def on_after_run(self, exp, results): pass
12
+
13
+
7
14
  # ! SEE https://github.com/hahv/base_exp for sample usage
8
15
  class BaseExp(PerfCalc, ABC):
9
16
  """
@@ -16,6 +23,16 @@ class BaseExp(PerfCalc, ABC):
16
23
  self.metric_backend = None
17
24
  # Flag to track if init_general/prepare_dataset has run
18
25
  self._is_env_ready = False
26
+ self.hooks = []
27
+
28
+ def register_hook(self, hook: ExpHook):
29
+ self.hooks.append(hook)
30
+
31
+ def _trigger_hooks(self, method_name: str, *args, **kwargs):
32
+ for hook in self.hooks:
33
+ method = getattr(hook, method_name, None)
34
+ if callable(method):
35
+ method(*args, **kwargs)
19
36
 
20
37
  # -----------------------
21
38
  # PerfCalc Required Methods
@@ -52,11 +69,6 @@ class BaseExp(PerfCalc, ABC):
52
69
  """
53
70
  pass
54
71
 
55
- @abstractmethod
56
- def before_exec_exp_once(self, *args, **kwargs):
57
- """Optional: any setup before exec_exp. Note this is called once per run_exp."""
58
- pass
59
-
60
72
  @abstractmethod
61
73
  def exec_exp(self, *args, **kwargs) -> Optional[Tuple[Any, Any]]:
62
74
  """Run experiment process, e.g.: training/evaluation loop.
@@ -64,13 +76,6 @@ class BaseExp(PerfCalc, ABC):
64
76
  """
65
77
  pass
66
78
 
67
- @abstractmethod
68
- def exec_eval(self, *args, **kwargs) -> Optional[Tuple[Any, Any]]:
69
- """Run evaluation process.
70
- Return: either `None` or a tuple of (raw_metrics_data, extra_data) for calc_and_save_exp_perfs
71
- """
72
- pass
73
-
74
79
  # -----------------------
75
80
  # Internal Helpers
76
81
  # -----------------------
@@ -121,8 +126,8 @@ class BaseExp(PerfCalc, ABC):
121
126
  """
122
127
  self._prepare_environment(force_reload=reload_env)
123
128
 
124
- # Any pre-exec setup (loading models, etc)
125
- self.before_exec_exp_once(*args, **kwargs)
129
+ self._trigger_hooks("before_run", self)
130
+
126
131
  # Save config before running
127
132
  self.config.save_to_outdir()
128
133
 
@@ -135,23 +140,8 @@ class BaseExp(PerfCalc, ABC):
135
140
  perf_results = self.calc_perfs(
136
141
  raw_metrics_data=metrics_data, extra_data=extra_data, *args, **kwargs
137
142
  )
143
+ self._trigger_hooks("after_run", self, perf_results)
138
144
  return perf_results
139
145
  else:
146
+ self._trigger_hooks("after_run", self, results)
140
147
  return results
141
-
142
- # -----------------------
143
- # Main Experiment Evaluator
144
- # -----------------------
145
- def eval_exp(self, reload_env=False, *args, **kwargs):
146
- """
147
- Run evaluation only.
148
- :param reload_env: If True, forces dataset/general init to run again.
149
- """
150
- self._prepare_environment(force_reload=reload_env)
151
- results = self.exec_eval(*args, **kwargs)
152
- if results is not None:
153
- metrics_data, extra_data = self._validate_and_unpack(results)
154
- return self.calc_perfs(
155
- raw_metrics_data=metrics_data, extra_data=extra_data, *args, **kwargs
156
- )
157
- return None
@@ -11,6 +11,7 @@ from ..system.path import *
11
11
 
12
12
  console = Console()
13
13
 
14
+
14
15
  def _load_yaml_recursively(
15
16
  yaml_file, yaml_files=[], share_nx_graph=nx.DiGraph(), log_info=False
16
17
  ):
@@ -53,25 +54,16 @@ def load_yaml(yaml_file, to_dict=False, log_info=False):
53
54
  else:
54
55
  return omgconf
55
56
 
57
+
56
58
  def load_yaml_with_PC_abbr(
57
- yaml_file, pc_abbr_to_working_disk=DEFAULT_ABBR_WORKING_DISK
59
+ yaml_file, abbr_disk_map=ABBR_DISK_MAP
58
60
  ):
59
- # current PC abbreviation
60
- pc_abbr = get_PC_abbr_name()
61
-
62
- # current plaftform: windows or linux
63
- current_platform = platform.system().lower()
64
-
65
- assert pc_abbr in pc_abbr_to_working_disk, f"The is no mapping for {pc_abbr} to <working_disk>"
66
-
67
- # working disk
68
- working_disk = pc_abbr_to_working_disk.get(pc_abbr)
69
-
70
61
  # load yaml file
71
62
  data_dict = load_yaml(yaml_file=yaml_file, to_dict=True)
72
-
73
63
  # Normalize paths in the loaded data
74
- data_dict = normalize_paths(data_dict, working_disk, current_platform)
64
+ data_dict = normalize_paths(
65
+ data_dict, get_working_disk(abbr_disk_map), get_os_platform()
66
+ )
75
67
  return data_dict
76
68
 
77
69
 
@@ -2,9 +2,9 @@ from ..common.common import *
2
2
  from ..filetype import csvfile
3
3
  import pandas as pd
4
4
  import platform
5
+ import re # <--- [FIX 1] Added missing import
5
6
 
6
-
7
- PC_NAME_TO_ABBR = {
7
+ PC_TO_ABBR = {
8
8
  "DESKTOP-JQD9K01": "MainPC",
9
9
  "DESKTOP-5IRHU87": "MSI_Laptop",
10
10
  "DESKTOP-96HQCNO": "4090_SV",
@@ -12,17 +12,16 @@ PC_NAME_TO_ABBR = {
12
12
  "DESKTOP-QNS3DNF": "1GPU_SV",
13
13
  }
14
14
 
15
- DEFAULT_ABBR_WORKING_DISK = {
15
+ ABBR_DISK_MAP = {
16
16
  "MainPC": "E:",
17
17
  "MSI_Laptop": "D:",
18
18
  "4090_SV": "E:",
19
19
  "4GPU_SV": "D:",
20
20
  }
21
21
 
22
+
22
23
  def list_PCs(show=True):
23
- df = pd.DataFrame(
24
- list(PC_NAME_TO_ABBR.items()), columns=["PC Name", "Abbreviation"]
25
- )
24
+ df = pd.DataFrame(list(PC_TO_ABBR.items()), columns=["PC Name", "Abbreviation"])
26
25
  if show:
27
26
  csvfile.fn_display_df(df)
28
27
  return df
@@ -34,13 +33,32 @@ def get_PC_name():
34
33
 
35
34
  def get_PC_abbr_name():
36
35
  pc_name = get_PC_name()
37
- return PC_NAME_TO_ABBR.get(pc_name, "Unknown")
36
+ return PC_TO_ABBR.get(pc_name, "Unknown")
37
+
38
+
39
+ def get_os_platform():
40
+ return platform.system().lower()
41
+
42
+
43
+ def get_working_disk(abbr_disk_map=ABBR_DISK_MAP):
44
+ pc_abbr = get_PC_abbr_name()
45
+ return abbr_disk_map.get(pc_abbr, None)
38
46
 
39
47
 
40
48
  # ! This funcction search for full paths in the obj and normalize them according to the current platform and working disk
41
49
  # ! E.g: "E:/zdataset/DFire", but working_disk: "D:", current_platform: "windows" => "D:/zdataset/DFire"
42
50
  # ! E.g: "E:/zdataset/DFire", but working_disk: "D:", current_platform: "linux" => "/mnt/d/zdataset/DFire"
43
- def normalize_paths(obj, working_disk, current_platform):
51
+ def normalize_paths(obj, working_disk=None, current_platform=None):
52
+ # [FIX 3] Resolve defaults inside function to be safer/cleaner
53
+ if working_disk is None:
54
+ working_disk = get_working_disk()
55
+ if current_platform is None:
56
+ current_platform = get_os_platform()
57
+
58
+ # [FIX 2] If PC is unknown, working_disk is None. Return early to avoid crash.
59
+ if working_disk is None:
60
+ return obj
61
+
44
62
  if isinstance(obj, dict):
45
63
  for key, value in obj.items():
46
64
  obj[key] = normalize_paths(value, working_disk, current_platform)
@@ -52,22 +70,25 @@ def normalize_paths(obj, working_disk, current_platform):
52
70
  elif isinstance(obj, str):
53
71
  # Normalize backslashes to forward slashes for consistency
54
72
  obj = obj.replace("\\", "/")
73
+
55
74
  # Regex for Windows-style path: e.g., "E:/zdataset/DFire"
56
75
  win_match = re.match(r"^([A-Z]):/(.*)$", obj)
57
76
  # Regex for Linux-style path: e.g., "/mnt/e/zdataset/DFire"
58
77
  lin_match = re.match(r"^/mnt/([a-z])/(.*)$", obj)
78
+
59
79
  if win_match or lin_match:
60
80
  rest = win_match.group(2) if win_match else lin_match.group(2)
81
+
61
82
  if current_platform == "windows":
62
83
  # working_disk is like "D:", so "D:/" + rest
63
- new_path = working_disk + "/" + rest
84
+ new_path = f"{working_disk}/{rest}"
64
85
  elif current_platform == "linux":
65
86
  # Extract drive letter from working_disk (e.g., "D:" -> "d")
66
87
  drive_letter = working_disk[0].lower()
67
- new_path = "/mnt/" + drive_letter + "/" + rest
88
+ new_path = f"/mnt/{drive_letter}/{rest}"
68
89
  else:
69
- # Unknown platform, return original
70
90
  return obj
71
91
  return new_path
92
+
72
93
  # For non-strings or non-path strings, return as is
73
94
  return obj
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: halib
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -53,7 +53,7 @@ Dynamic: summary
53
53
 
54
54
  # Helper package for coding and automation
55
55
 
56
- **Version 0.2.4**
56
+ **Version 0.2.6**
57
57
  + reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
58
58
 
59
59
  **Version 0.2.1**
@@ -8,7 +8,7 @@ with open("requirements.txt") as f:
8
8
 
9
9
  setuptools.setup(
10
10
  name="halib",
11
- version="0.2.4",
11
+ version="0.2.6",
12
12
  author="Hoang Van Ha",
13
13
  author_email="hoangvanhauit@gmail.com",
14
14
  description="Small library for common tasks",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes