ins-pricing 0.4.5__py3-none-any.whl → 0.5.1__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.
Files changed (93) hide show
  1. ins_pricing/README.md +48 -22
  2. ins_pricing/__init__.py +142 -90
  3. ins_pricing/cli/BayesOpt_entry.py +58 -46
  4. ins_pricing/cli/BayesOpt_incremental.py +77 -110
  5. ins_pricing/cli/Explain_Run.py +42 -23
  6. ins_pricing/cli/Explain_entry.py +551 -577
  7. ins_pricing/cli/Pricing_Run.py +42 -23
  8. ins_pricing/cli/bayesopt_entry_runner.py +51 -16
  9. ins_pricing/cli/utils/bootstrap.py +23 -0
  10. ins_pricing/cli/utils/cli_common.py +256 -256
  11. ins_pricing/cli/utils/cli_config.py +379 -360
  12. ins_pricing/cli/utils/import_resolver.py +375 -358
  13. ins_pricing/cli/utils/notebook_utils.py +256 -242
  14. ins_pricing/cli/watchdog_run.py +216 -198
  15. ins_pricing/frontend/__init__.py +10 -10
  16. ins_pricing/frontend/app.py +132 -61
  17. ins_pricing/frontend/config_builder.py +33 -0
  18. ins_pricing/frontend/example_config.json +11 -0
  19. ins_pricing/frontend/example_workflows.py +1 -1
  20. ins_pricing/frontend/runner.py +340 -388
  21. ins_pricing/governance/__init__.py +20 -20
  22. ins_pricing/governance/release.py +159 -159
  23. ins_pricing/modelling/README.md +1 -1
  24. ins_pricing/modelling/__init__.py +147 -92
  25. ins_pricing/modelling/{core/bayesopt → bayesopt}/README.md +31 -13
  26. ins_pricing/modelling/{core/bayesopt → bayesopt}/__init__.py +64 -102
  27. ins_pricing/modelling/{core/bayesopt → bayesopt}/config_components.py +12 -0
  28. ins_pricing/modelling/{core/bayesopt → bayesopt}/config_preprocess.py +589 -552
  29. ins_pricing/modelling/{core/bayesopt → bayesopt}/core.py +987 -958
  30. ins_pricing/modelling/{core/bayesopt → bayesopt}/model_explain_mixin.py +296 -296
  31. ins_pricing/modelling/{core/bayesopt → bayesopt}/model_plotting_mixin.py +488 -548
  32. ins_pricing/modelling/{core/bayesopt → bayesopt}/models/__init__.py +27 -27
  33. ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_ft_components.py +349 -342
  34. ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_ft_trainer.py +921 -913
  35. ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_gnn.py +794 -785
  36. ins_pricing/modelling/{core/bayesopt → bayesopt}/models/model_resn.py +454 -446
  37. ins_pricing/modelling/bayesopt/trainers/__init__.py +19 -0
  38. ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_base.py +1294 -1282
  39. ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_ft.py +64 -56
  40. ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_glm.py +203 -198
  41. ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_gnn.py +333 -325
  42. ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_resn.py +279 -267
  43. ins_pricing/modelling/{core/bayesopt → bayesopt}/trainers/trainer_xgb.py +515 -313
  44. ins_pricing/modelling/bayesopt/utils/__init__.py +67 -0
  45. ins_pricing/modelling/bayesopt/utils/constants.py +21 -0
  46. ins_pricing/modelling/{core/bayesopt → bayesopt}/utils/distributed_utils.py +193 -186
  47. ins_pricing/modelling/bayesopt/utils/io_utils.py +7 -0
  48. ins_pricing/modelling/bayesopt/utils/losses.py +27 -0
  49. ins_pricing/modelling/bayesopt/utils/metrics_and_devices.py +17 -0
  50. ins_pricing/modelling/{core/bayesopt → bayesopt}/utils/torch_trainer_mixin.py +636 -623
  51. ins_pricing/modelling/{core/evaluation.py → evaluation.py} +113 -104
  52. ins_pricing/modelling/explain/__init__.py +55 -55
  53. ins_pricing/modelling/explain/metrics.py +27 -174
  54. ins_pricing/modelling/explain/permutation.py +237 -237
  55. ins_pricing/modelling/plotting/__init__.py +40 -36
  56. ins_pricing/modelling/plotting/compat.py +228 -0
  57. ins_pricing/modelling/plotting/curves.py +572 -572
  58. ins_pricing/modelling/plotting/diagnostics.py +163 -163
  59. ins_pricing/modelling/plotting/geo.py +362 -362
  60. ins_pricing/modelling/plotting/importance.py +121 -121
  61. ins_pricing/pricing/__init__.py +27 -27
  62. ins_pricing/pricing/factors.py +67 -56
  63. ins_pricing/production/__init__.py +35 -25
  64. ins_pricing/production/{predict.py → inference.py} +140 -57
  65. ins_pricing/production/monitoring.py +8 -21
  66. ins_pricing/reporting/__init__.py +11 -11
  67. ins_pricing/setup.py +1 -1
  68. ins_pricing/tests/production/test_inference.py +90 -0
  69. ins_pricing/utils/__init__.py +112 -78
  70. ins_pricing/utils/device.py +258 -237
  71. ins_pricing/utils/features.py +53 -0
  72. ins_pricing/utils/io.py +72 -0
  73. ins_pricing/utils/logging.py +34 -1
  74. ins_pricing/{modelling/core/bayesopt/utils → utils}/losses.py +125 -129
  75. ins_pricing/utils/metrics.py +158 -24
  76. ins_pricing/utils/numerics.py +76 -0
  77. ins_pricing/utils/paths.py +9 -1
  78. ins_pricing/utils/profiling.py +8 -4
  79. {ins_pricing-0.4.5.dist-info → ins_pricing-0.5.1.dist-info}/METADATA +1 -1
  80. ins_pricing-0.5.1.dist-info/RECORD +132 -0
  81. ins_pricing/modelling/core/BayesOpt.py +0 -146
  82. ins_pricing/modelling/core/__init__.py +0 -1
  83. ins_pricing/modelling/core/bayesopt/trainers/__init__.py +0 -19
  84. ins_pricing/modelling/core/bayesopt/utils/__init__.py +0 -86
  85. ins_pricing/modelling/core/bayesopt/utils/constants.py +0 -183
  86. ins_pricing/modelling/core/bayesopt/utils/io_utils.py +0 -126
  87. ins_pricing/modelling/core/bayesopt/utils/metrics_and_devices.py +0 -555
  88. ins_pricing/modelling/core/bayesopt/utils.py +0 -105
  89. ins_pricing/modelling/core/bayesopt/utils_backup.py +0 -1503
  90. ins_pricing/tests/production/test_predict.py +0 -233
  91. ins_pricing-0.4.5.dist-info/RECORD +0 -130
  92. {ins_pricing-0.4.5.dist-info → ins_pricing-0.5.1.dist-info}/WHEEL +0 -0
  93. {ins_pricing-0.4.5.dist-info → ins_pricing-0.5.1.dist-info}/top_level.txt +0 -0
@@ -1,25 +1,44 @@
1
- from __future__ import annotations
2
-
1
+ from __future__ import annotations
2
+
3
3
  from pathlib import Path
4
4
  from typing import Optional
5
-
6
- try:
7
- from .utils.notebook_utils import run_from_config, run_from_config_cli # type: ignore
8
- except Exception: # pragma: no cover
9
- from utils.notebook_utils import run_from_config, run_from_config_cli # type: ignore
10
-
11
-
12
- def run(config_json: str | Path) -> None:
13
- """Unified entry point: run entry/incremental/watchdog/DDP based on config.json runner."""
14
- run_from_config(config_json)
15
-
16
-
17
- def main(argv: Optional[list[str]] = None) -> None:
18
- run_from_config_cli(
19
- "Pricing_Run: run BayesOpt by config.json (entry/incremental/watchdog/DDP).",
20
- argv,
21
- )
22
-
23
-
24
- if __name__ == "__main__":
25
- main()
5
+ import importlib.util
6
+ import sys
7
+
8
+
9
+ def _ensure_repo_root() -> None:
10
+ if __package__ not in {None, ""}:
11
+ return
12
+ if importlib.util.find_spec("ins_pricing") is not None:
13
+ return
14
+ bootstrap_path = Path(__file__).resolve().parents[1] / "utils" / "bootstrap.py"
15
+ spec = importlib.util.spec_from_file_location("ins_pricing.cli.utils.bootstrap", bootstrap_path)
16
+ if spec is None or spec.loader is None:
17
+ return
18
+ module = importlib.util.module_from_spec(spec)
19
+ spec.loader.exec_module(module)
20
+ module.ensure_repo_root()
21
+
22
+
23
+ _ensure_repo_root()
24
+
25
+ try:
26
+ from ins_pricing.cli.utils.notebook_utils import run_from_config, run_from_config_cli # type: ignore
27
+ except Exception: # pragma: no cover
28
+ from utils.notebook_utils import run_from_config, run_from_config_cli # type: ignore
29
+
30
+
31
+ def run(config_json: str | Path) -> None:
32
+ """Unified entry point: run entry/incremental/watchdog/DDP based on config.json runner."""
33
+ run_from_config(config_json)
34
+
35
+
36
+ def main(argv: Optional[list[str]] = None) -> None:
37
+ run_from_config_cli(
38
+ "Pricing_Run: run BayesOpt by config.json (entry/incremental/watchdog/DDP).",
39
+ argv,
40
+ )
41
+
42
+
43
+ if __name__ == "__main__":
44
+ main()
@@ -11,13 +11,26 @@ Example:
11
11
 
12
12
  from __future__ import annotations
13
13
 
14
- from pathlib import Path
15
- import sys
16
-
17
- if __package__ in {None, ""}:
18
- repo_root = Path(__file__).resolve().parents[2]
19
- if str(repo_root) not in sys.path:
20
- sys.path.insert(0, str(repo_root))
14
+ from pathlib import Path
15
+ import importlib.util
16
+ import sys
17
+
18
+
19
+ def _ensure_repo_root() -> None:
20
+ if __package__ not in {None, ""}:
21
+ return
22
+ if importlib.util.find_spec("ins_pricing") is not None:
23
+ return
24
+ bootstrap_path = Path(__file__).resolve().parents[1] / "utils" / "bootstrap.py"
25
+ spec = importlib.util.spec_from_file_location("ins_pricing.cli.utils.bootstrap", bootstrap_path)
26
+ if spec is None or spec.loader is None:
27
+ return
28
+ module = importlib.util.module_from_spec(spec)
29
+ spec.loader.exec_module(module)
30
+ module.ensure_repo_root()
31
+
32
+
33
+ _ensure_repo_root()
21
34
 
22
35
  import argparse
23
36
  import hashlib
@@ -30,8 +43,8 @@ import numpy as np
30
43
  import pandas as pd
31
44
 
32
45
  # Use unified import resolver to eliminate nested try/except chains
33
- from .utils.import_resolver import resolve_imports, setup_sys_path
34
- from .utils.evaluation_context import (
46
+ from ins_pricing.cli.utils.import_resolver import resolve_imports, setup_sys_path
47
+ from ins_pricing.cli.utils.evaluation_context import (
35
48
  EvaluationContext,
36
49
  TrainingContext,
37
50
  ModelIdentity,
@@ -1112,10 +1125,21 @@ def train_from_config(args: argparse.Namespace) -> None:
1112
1125
  output_override=args.output_dir,
1113
1126
  )
1114
1127
  output_dir = output_cfg["output_dir"]
1115
- reuse_best_params = bool(
1116
- args.reuse_best_params or runtime_cfg["reuse_best_params"])
1117
- xgb_max_depth_max = runtime_cfg["xgb_max_depth_max"]
1118
- xgb_n_estimators_max = runtime_cfg["xgb_n_estimators_max"]
1128
+ reuse_best_params = bool(
1129
+ args.reuse_best_params or runtime_cfg["reuse_best_params"])
1130
+ xgb_max_depth_max = runtime_cfg["xgb_max_depth_max"]
1131
+ xgb_n_estimators_max = runtime_cfg["xgb_n_estimators_max"]
1132
+ xgb_gpu_id = runtime_cfg["xgb_gpu_id"]
1133
+ xgb_cleanup_per_fold = runtime_cfg["xgb_cleanup_per_fold"]
1134
+ xgb_cleanup_synchronize = runtime_cfg["xgb_cleanup_synchronize"]
1135
+ xgb_use_dmatrix = runtime_cfg["xgb_use_dmatrix"]
1136
+ ft_cleanup_per_fold = runtime_cfg["ft_cleanup_per_fold"]
1137
+ ft_cleanup_synchronize = runtime_cfg["ft_cleanup_synchronize"]
1138
+ resn_cleanup_per_fold = runtime_cfg["resn_cleanup_per_fold"]
1139
+ resn_cleanup_synchronize = runtime_cfg["resn_cleanup_synchronize"]
1140
+ gnn_cleanup_per_fold = runtime_cfg["gnn_cleanup_per_fold"]
1141
+ gnn_cleanup_synchronize = runtime_cfg["gnn_cleanup_synchronize"]
1142
+ optuna_cleanup_synchronize = runtime_cfg["optuna_cleanup_synchronize"]
1119
1143
  optuna_storage = runtime_cfg["optuna_storage"]
1120
1144
  optuna_study_prefix = runtime_cfg["optuna_study_prefix"]
1121
1145
  best_params_files = runtime_cfg["best_params_files"]
@@ -1247,9 +1271,20 @@ def train_from_config(args: argparse.Namespace) -> None:
1247
1271
  "use_ft_ddp": use_ft_ddp,
1248
1272
  "use_gnn_ddp": use_gnn_ddp,
1249
1273
  "output_dir": output_dir,
1250
- "xgb_max_depth_max": xgb_max_depth_max,
1251
- "xgb_n_estimators_max": xgb_n_estimators_max,
1252
- "resn_weight_decay": cfg.get("resn_weight_decay"),
1274
+ "xgb_max_depth_max": xgb_max_depth_max,
1275
+ "xgb_n_estimators_max": xgb_n_estimators_max,
1276
+ "xgb_gpu_id": xgb_gpu_id,
1277
+ "xgb_cleanup_per_fold": xgb_cleanup_per_fold,
1278
+ "xgb_cleanup_synchronize": xgb_cleanup_synchronize,
1279
+ "xgb_use_dmatrix": xgb_use_dmatrix,
1280
+ "ft_cleanup_per_fold": ft_cleanup_per_fold,
1281
+ "ft_cleanup_synchronize": ft_cleanup_synchronize,
1282
+ "resn_cleanup_per_fold": resn_cleanup_per_fold,
1283
+ "resn_cleanup_synchronize": resn_cleanup_synchronize,
1284
+ "gnn_cleanup_per_fold": gnn_cleanup_per_fold,
1285
+ "gnn_cleanup_synchronize": gnn_cleanup_synchronize,
1286
+ "optuna_cleanup_synchronize": optuna_cleanup_synchronize,
1287
+ "resn_weight_decay": cfg.get("resn_weight_decay"),
1253
1288
  "final_ensemble": bool(cfg.get("final_ensemble", False)),
1254
1289
  "final_ensemble_k": int(cfg.get("final_ensemble_k", 3)),
1255
1290
  "final_refit": bool(cfg.get("final_refit", True)),
@@ -0,0 +1,23 @@
1
+ """Bootstrap helpers for running CLI modules as scripts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from pathlib import Path
7
+ from typing import Optional
8
+
9
+
10
+ def _find_repo_root(start: Optional[Path] = None) -> Path:
11
+ anchor = (start or Path(__file__)).resolve()
12
+ for parent in [anchor] + list(anchor.parents):
13
+ if (parent / "ins_pricing").is_dir():
14
+ return parent
15
+ return anchor.parent
16
+
17
+
18
+ def ensure_repo_root(repo_root: Optional[Path] = None) -> Path:
19
+ """Ensure the repository root (parent of ins_pricing/) is on sys.path."""
20
+ root = _find_repo_root(repo_root)
21
+ if str(root) not in sys.path:
22
+ sys.path.insert(0, str(root))
23
+ return root