tributo-algorithms 0.1.0__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 (110) hide show
  1. tributo_algorithms-0.1.0.dist-info/METADATA +328 -0
  2. tributo_algorithms-0.1.0.dist-info/RECORD +110 -0
  3. tributo_algorithms-0.1.0.dist-info/WHEEL +4 -0
  4. tributo_algorithms-0.1.0.dist-info/entry_points.txt +57 -0
  5. tributo_algorithms-0.1.0.dist-info/licenses/LICENSE +202 -0
  6. tributo_algorithms_boosting/__init__.py +42 -0
  7. tributo_algorithms_boosting/algorithm.py +825 -0
  8. tributo_algorithms_boosting/checkpointing.py +441 -0
  9. tributo_algorithms_boosting/contracts.py +232 -0
  10. tributo_algorithms_boosting/data_config.py +59 -0
  11. tributo_algorithms_boosting/descriptor.py +124 -0
  12. tributo_algorithms_boosting/lightgbm.py +511 -0
  13. tributo_algorithms_boosting/lightgbm_contracts.py +186 -0
  14. tributo_algorithms_boosting/lightgbm_descriptor.py +112 -0
  15. tributo_algorithms_boosting/native.py +557 -0
  16. tributo_algorithms_boosting/stages.py +150 -0
  17. tributo_algorithms_catboost/__init__.py +5 -0
  18. tributo_algorithms_catboost/algorithm.py +379 -0
  19. tributo_algorithms_catboost/contracts.py +145 -0
  20. tributo_algorithms_catboost/descriptor.py +121 -0
  21. tributo_algorithms_catboost/exporter.py +106 -0
  22. tributo_algorithms_catboost/flavor.py +191 -0
  23. tributo_algorithms_causal_core/__init__.py +41 -0
  24. tributo_algorithms_causal_core/algorithm.py +1193 -0
  25. tributo_algorithms_causal_core/contracts.py +136 -0
  26. tributo_algorithms_causal_core/descriptor.py +270 -0
  27. tributo_algorithms_causal_core/exporter.py +52 -0
  28. tributo_algorithms_causal_discovery/__init__.py +23 -0
  29. tributo_algorithms_causal_discovery/algorithm.py +526 -0
  30. tributo_algorithms_causal_discovery/contracts.py +97 -0
  31. tributo_algorithms_causal_discovery/descriptor.py +130 -0
  32. tributo_algorithms_causal_discovery/exporter.py +43 -0
  33. tributo_algorithms_causal_dowhy/__init__.py +38 -0
  34. tributo_algorithms_causal_dowhy/algorithm.py +325 -0
  35. tributo_algorithms_causal_dowhy/contracts.py +209 -0
  36. tributo_algorithms_causal_dowhy/descriptor.py +106 -0
  37. tributo_algorithms_causal_dowhy/exporter.py +43 -0
  38. tributo_algorithms_causal_dowhy/gcm.py +634 -0
  39. tributo_algorithms_causal_dowhy/gcm_descriptor.py +110 -0
  40. tributo_algorithms_causal_dr/__init__.py +22 -0
  41. tributo_algorithms_causal_dr/algorithm.py +446 -0
  42. tributo_algorithms_causal_dr/contracts.py +94 -0
  43. tributo_algorithms_causal_dr/descriptor.py +104 -0
  44. tributo_algorithms_causal_xlearner/__init__.py +29 -0
  45. tributo_algorithms_causal_xlearner/algorithm.py +448 -0
  46. tributo_algorithms_causal_xlearner/contracts.py +97 -0
  47. tributo_algorithms_causal_xlearner/descriptor.py +120 -0
  48. tributo_algorithms_causal_xlearner/exporter.py +432 -0
  49. tributo_algorithms_causal_xlearner/flavor.py +120 -0
  50. tributo_algorithms_causal_xlearner/model.py +116 -0
  51. tributo_algorithms_classical/__init__.py +41 -0
  52. tributo_algorithms_classical/contracts.py +139 -0
  53. tributo_algorithms_classical/descriptors.py +370 -0
  54. tributo_algorithms_classical/exporter.py +166 -0
  55. tributo_algorithms_classical/isolation_forest.py +172 -0
  56. tributo_algorithms_classical/isolation_forest_descriptor.py +122 -0
  57. tributo_algorithms_classical/kmeans.py +315 -0
  58. tributo_algorithms_classical/kmeans_descriptor.py +147 -0
  59. tributo_algorithms_classical/linear_regression.py +206 -0
  60. tributo_algorithms_classical/logistic_regression.py +238 -0
  61. tributo_algorithms_classical/models.py +28 -0
  62. tributo_algorithms_classical/multinomial_nb.py +643 -0
  63. tributo_algorithms_classical/multinomial_nb_descriptor.py +183 -0
  64. tributo_algorithms_classical/pca.py +187 -0
  65. tributo_algorithms_classical/pca_descriptor.py +111 -0
  66. tributo_algorithms_classical/random_forest.py +304 -0
  67. tributo_algorithms_classical/sgd.py +331 -0
  68. tributo_algorithms_classical/sgd_contracts.py +121 -0
  69. tributo_algorithms_classical/sgd_descriptor.py +143 -0
  70. tributo_algorithms_classical/unsupervised_contracts.py +198 -0
  71. tributo_algorithms_classical/unsupervised_exporter.py +427 -0
  72. tributo_algorithms_classical/unsupervised_models.py +90 -0
  73. tributo_algorithms_graph_pyg/__init__.py +37 -0
  74. tributo_algorithms_graph_pyg/algorithm.py +883 -0
  75. tributo_algorithms_graph_pyg/contracts.py +260 -0
  76. tributo_algorithms_graph_pyg/descriptor.py +201 -0
  77. tributo_algorithms_multistage_torch/__init__.py +40 -0
  78. tributo_algorithms_multistage_torch/algorithm.py +532 -0
  79. tributo_algorithms_multistage_torch/contracts.py +220 -0
  80. tributo_algorithms_multistage_torch/descriptor.py +146 -0
  81. tributo_algorithms_multistage_torch/pretrain.py +570 -0
  82. tributo_algorithms_multistage_torch/pretrain_descriptor.py +153 -0
  83. tributo_algorithms_recsys_torch/__init__.py +35 -0
  84. tributo_algorithms_recsys_torch/contracts.py +295 -0
  85. tributo_algorithms_recsys_torch/descriptor.py +136 -0
  86. tributo_algorithms_recsys_torch/jagged.py +707 -0
  87. tributo_algorithms_recsys_torch/jagged_descriptor.py +130 -0
  88. tributo_algorithms_recsys_torch/recipe.py +192 -0
  89. tributo_algorithms_representation/__init__.py +20 -0
  90. tributo_algorithms_representation/contracts.py +117 -0
  91. tributo_algorithms_representation/descriptor.py +137 -0
  92. tributo_algorithms_representation/recipe.py +162 -0
  93. tributo_algorithms_tabular_torch/__init__.py +46 -0
  94. tributo_algorithms_tabular_torch/contracts.py +228 -0
  95. tributo_algorithms_tabular_torch/descriptor.py +223 -0
  96. tributo_algorithms_tabular_torch/priors.py +216 -0
  97. tributo_algorithms_tabular_torch/pu_metrics.py +269 -0
  98. tributo_algorithms_tabular_torch/pu_reducer.py +129 -0
  99. tributo_algorithms_tabular_torch/recipe.py +294 -0
  100. tributo_algorithms_timeseries/__init__.py +36 -0
  101. tributo_algorithms_timeseries/contracts.py +120 -0
  102. tributo_algorithms_timeseries/descriptor.py +137 -0
  103. tributo_algorithms_timeseries/recipe.py +195 -0
  104. tributo_algorithms_timeseries/rnn_contracts.py +170 -0
  105. tributo_algorithms_timeseries/rnn_descriptor.py +167 -0
  106. tributo_algorithms_timeseries/rnn_recipe.py +223 -0
  107. tributo_algorithms_transformers_nlp/__init__.py +20 -0
  108. tributo_algorithms_transformers_nlp/contracts.py +109 -0
  109. tributo_algorithms_transformers_nlp/descriptor.py +137 -0
  110. tributo_algorithms_transformers_nlp/recipe.py +235 -0
@@ -0,0 +1,209 @@
1
+ """Executable contracts for distributed DoWhy adapters."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from typing import Any
7
+
8
+
9
+ class DoWhyConfigValidator:
10
+ api_version = 1
11
+ schema_digest = "e" * 64
12
+
13
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
14
+ allowed = {"data", "output", "refutation", "runtime"}
15
+ if unknown := sorted(set(value) - allowed):
16
+ raise ValueError(f"unknown DoWhy config keys: {unknown}")
17
+ for name in allowed:
18
+ if not isinstance(value.get(name), Mapping):
19
+ raise ValueError(f"{name} config is required")
20
+ data = value["data"]
21
+ for name in ("common_causes", "treatment_col", "outcome_col"):
22
+ if not data.get(name):
23
+ raise ValueError(f"data.{name} is required")
24
+ if not value["output"].get("bundle_uri"):
25
+ raise ValueError("output.bundle_uri is required")
26
+ return dict(value)
27
+
28
+
29
+ class DoWhyInputValidator:
30
+ api_version = 1
31
+ schema_digest = "f" * 64
32
+
33
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
34
+ bindings = value.get("bindings")
35
+ if not isinstance(bindings, list) or len(bindings) != 1:
36
+ raise ValueError("DoWhy requires one train binding")
37
+ binding = bindings[0]
38
+ if (
39
+ not isinstance(binding, Mapping)
40
+ or len(binding.get("feature_names", ())) < 2
41
+ or not binding.get("label_name")
42
+ ):
43
+ raise ValueError("DoWhy input requires confounders, treatment, and outcome")
44
+ return value
45
+
46
+
47
+ class DoWhyOutputValidator:
48
+ api_version = 1
49
+ schema_digest = "0" * 64
50
+
51
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
52
+ outputs = value.get("outputs")
53
+ if value.get("status") != "succeeded" or not isinstance(outputs, Mapping):
54
+ raise ValueError("DoWhy execution failed")
55
+ if not outputs.get("bundle_uri") or not outputs.get("composition_digest"):
56
+ raise ValueError("DoWhy output requires Bundle and composition digest")
57
+ return value
58
+
59
+
60
+ class DoWhyCoverageValidator:
61
+ api_version = 1
62
+ schema_digest = "1" * 64
63
+
64
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
65
+ if (
66
+ value.get("input_complete") is not True
67
+ or value.get("distributed") is not True
68
+ ):
69
+ raise ValueError("DoWhy coverage is incomplete")
70
+ state = value.get("state")
71
+ details = state.get("details") if isinstance(state, Mapping) else None
72
+ if (
73
+ not isinstance(details, Mapping)
74
+ or details.get("component_stages") != "estimate,refute"
75
+ ):
76
+ raise ValueError("DoWhy estimate/refute stage evidence is missing")
77
+ return value
78
+
79
+
80
+ class GCMConfigValidator:
81
+ api_version = 1
82
+ schema_digest = "2" * 64
83
+
84
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
85
+ allowed = {"data", "gcm", "output", "runtime"}
86
+ if unknown := sorted(set(value) - allowed):
87
+ raise ValueError(f"unknown GCM config keys: {unknown}")
88
+ for name in allowed:
89
+ if not isinstance(value.get(name), Mapping):
90
+ raise ValueError(f"{name} config is required")
91
+ data = value["data"]
92
+ nodes = data.get("nodes")
93
+ edges = data.get("edges")
94
+ target = data.get("target_node")
95
+ if (
96
+ not isinstance(nodes, list)
97
+ or len(nodes) < 2
98
+ or len(set(nodes)) != len(nodes)
99
+ or any(not isinstance(name, str) or not name for name in nodes)
100
+ ):
101
+ raise ValueError("data.nodes requires unique node names")
102
+ if not isinstance(edges, list) or not edges:
103
+ raise ValueError("data.edges requires a non-empty edge list")
104
+ for edge in edges:
105
+ if (
106
+ not isinstance(edge, list)
107
+ or len(edge) != 2
108
+ or any(name not in nodes for name in edge)
109
+ or edge[0] == edge[1]
110
+ ):
111
+ raise ValueError("data.edges must reference two distinct nodes")
112
+ if target not in nodes:
113
+ raise ValueError("data.target_node must reference a declared node")
114
+ interventions = data.get("interventions", {})
115
+ if not isinstance(interventions, Mapping) or any(
116
+ name not in nodes
117
+ or not isinstance(number, (int, float))
118
+ or isinstance(number, bool)
119
+ for name, number in interventions.items()
120
+ ):
121
+ raise ValueError("data.interventions must map declared nodes to numbers")
122
+ gcm = value["gcm"]
123
+ if gcm.get("quality", "good") not in {"good", "better", "best"}:
124
+ raise ValueError("gcm.quality must be good, better, or best")
125
+ for name in ("distribution_samples", "shapley_permutations"):
126
+ item = gcm.get(name, 1)
127
+ if not isinstance(item, int) or isinstance(item, bool) or item < 1:
128
+ raise ValueError(f"gcm.{name} must be positive")
129
+ if not value["output"].get("bundle_uri"):
130
+ raise ValueError("output.bundle_uri is required")
131
+ return dict(value)
132
+
133
+
134
+ class GCMInputValidator:
135
+ api_version = 1
136
+ schema_digest = "3" * 64
137
+
138
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
139
+ bindings = value.get("bindings")
140
+ if not isinstance(bindings, list) or len(bindings) != 2:
141
+ raise ValueError("GCM requires train and anomaly bindings")
142
+ if value.get("primary_role") != "train":
143
+ raise ValueError("GCM train binding must be primary")
144
+ roles = {
145
+ binding.get("name") for binding in bindings if isinstance(binding, Mapping)
146
+ }
147
+ if roles != {"train", "anomaly"}:
148
+ raise ValueError("GCM input roles must be train and anomaly")
149
+ for binding in bindings:
150
+ if (
151
+ not isinstance(binding, Mapping)
152
+ or len(binding.get("feature_names", ())) < 2
153
+ or binding.get("label_name") is not None
154
+ ):
155
+ raise ValueError("GCM roles require unlabeled causal variables")
156
+ return value
157
+
158
+
159
+ class GCMOutputValidator:
160
+ api_version = 1
161
+ schema_digest = "4" * 64
162
+
163
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
164
+ outputs = value.get("outputs")
165
+ if value.get("status") != "succeeded" or not isinstance(outputs, Mapping):
166
+ raise ValueError("GCM execution failed")
167
+ if not outputs.get("bundle_uri") or not outputs.get("composition_digest"):
168
+ raise ValueError("GCM output requires Bundle and composition digest")
169
+ return value
170
+
171
+
172
+ class GCMCoverageValidator:
173
+ api_version = 1
174
+ schema_digest = "5" * 64
175
+
176
+ def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
177
+ if (
178
+ value.get("input_complete") is not True
179
+ or value.get("distributed") is not True
180
+ ):
181
+ raise ValueError("GCM coverage is incomplete")
182
+ workers = value.get("workers")
183
+ if not isinstance(workers, list) or any(
184
+ not isinstance(worker, Mapping)
185
+ or not isinstance(worker.get("input_rows"), Mapping)
186
+ or int(worker["input_rows"].get("coverage.anomaly", 0)) < 1
187
+ for worker in workers
188
+ ):
189
+ raise ValueError("GCM anomaly coverage is missing")
190
+ state = value.get("state")
191
+ details = state.get("details") if isinstance(state, Mapping) else None
192
+ if (
193
+ not isinstance(details, Mapping)
194
+ or details.get("component_stages") != "fit_gcm,attribute_root_cause"
195
+ ):
196
+ raise ValueError("GCM fit and root-cause stage evidence is missing")
197
+ return value
198
+
199
+
200
+ __all__ = [
201
+ "DoWhyConfigValidator",
202
+ "DoWhyCoverageValidator",
203
+ "DoWhyInputValidator",
204
+ "DoWhyOutputValidator",
205
+ "GCMConfigValidator",
206
+ "GCMCoverageValidator",
207
+ "GCMInputValidator",
208
+ "GCMOutputValidator",
209
+ ]
@@ -0,0 +1,106 @@
1
+ """Descriptor for distributed DoWhy estimate and refutation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from tributo.algorithms import AlgorithmBuilder
6
+ from tributo.algorithms.api import (
7
+ ContractBinding,
8
+ ContractBindingSet,
9
+ DistributionStrategy,
10
+ EnvironmentSpec,
11
+ ExecutionMode,
12
+ ExecutionProfile,
13
+ FrameworkNativePolicy,
14
+ QualifiedReference,
15
+ WorkerRange,
16
+ WorkerResources,
17
+ )
18
+ from tributo.training.algorithm_spec import AlgorithmSpec, Capability, ProblemType
19
+
20
+ STAGES = ("estimate", "refute")
21
+
22
+ _PACKAGE = "tributo-algorithms"
23
+ _VERSION = "0.1.0"
24
+
25
+
26
+ def _binding(contract_id: str, digest: str, validator: str) -> ContractBinding:
27
+ return ContractBinding(
28
+ contract_id=contract_id,
29
+ schema_version=1,
30
+ schema_digest=digest * 64,
31
+ validator_ref=QualifiedReference.parse(
32
+ f"tributo_algorithms_causal_dowhy.contracts:{validator}"
33
+ ),
34
+ )
35
+
36
+
37
+ _SPEC = AlgorithmSpec(
38
+ name="dowhy_linear_refutation",
39
+ trainer_cls=None,
40
+ version="1.0.0",
41
+ default_config={},
42
+ supported_tasks=("fit",),
43
+ operations=("fit",),
44
+ problem_types=(ProblemType.CAUSAL_EFFECT_ESTIMATION,),
45
+ capabilities=(Capability.DISTRIBUTED, Capability.EXPORTABLE, Capability.TUNABLE),
46
+ learning_paradigm="causal_inference",
47
+ model_family="dowhy_linear_refutation_ensemble",
48
+ data_modalities=("tabular",),
49
+ lifecycle_kind="identify_estimate_refute_policy",
50
+ allowed_execution_modes=(ExecutionMode.FRAMEWORK_NATIVE.value,),
51
+ config_contract_ref="tributo.official.causal.dowhy.config.v1",
52
+ input_contract_ref="tributo.official.causal.binary-treatment.v1",
53
+ output_contract_ref="tributo.official.causal.report-bundle.v1",
54
+ )
55
+
56
+ DOWHY_DESCRIPTOR = AlgorithmBuilder.from_distributed_algorithm(
57
+ spec=_SPEC,
58
+ implementation_id="tributo.official.causal_dowhy.linear_refutation",
59
+ implementation_version="1.0.0",
60
+ implementation=(
61
+ "tributo_algorithms_causal_dowhy.algorithm:DistributedDoWhyRefutation"
62
+ ),
63
+ executable_factory="tributo_algorithms_causal_dowhy.algorithm:create_algorithm",
64
+ distribution=_PACKAGE,
65
+ framework="dowhy",
66
+ environment=EnvironmentSpec(
67
+ environment_id="tributo.official.causal-dowhy.v1",
68
+ dependencies=(
69
+ "dowhy>=0.14,<0.15",
70
+ "tributo>=1.1",
71
+ f"tributo-algorithms[causal-dowhy]=={_VERSION}",
72
+ ),
73
+ ),
74
+ allowed_config_keys=("data", "output", "refutation", "runtime"),
75
+ strategy=DistributionStrategy.FRAMEWORK_NATIVE,
76
+ supported_worker_range=WorkerRange(2, 64),
77
+ supported_execution_profiles=(ExecutionProfile.LOCAL, ExecutionProfile.CLUSTER),
78
+ resources_per_worker=WorkerResources(num_cpus=1),
79
+ policy=FrameworkNativePolicy(
80
+ framework="dowhy-shard-ensemble",
81
+ evidence_collector_ref=(
82
+ "tributo_algorithms_causal_dowhy.algorithm:"
83
+ "DistributedDoWhyRefutation.collect_evidence"
84
+ ),
85
+ component_stages=STAGES,
86
+ ),
87
+ package_name=_PACKAGE,
88
+ package_version=_VERSION,
89
+ tributo_version_spec=">=1.1",
90
+ exporter="tributo_algorithms_causal_dowhy.algorithm:export_result",
91
+ flavor_id="onnx-runtime-v1",
92
+ contract_bindings=ContractBindingSet(
93
+ config=_binding(_SPEC.config_contract_ref or "", "e", "DoWhyConfigValidator"),
94
+ input=_binding(_SPEC.input_contract_ref or "", "f", "DoWhyInputValidator"),
95
+ output=_binding(_SPEC.output_contract_ref or "", "0", "DoWhyOutputValidator"),
96
+ coverage=_binding(
97
+ "tributo.official.causal.dowhy-stage-coverage.v1",
98
+ "1",
99
+ "DoWhyCoverageValidator",
100
+ ),
101
+ ),
102
+ descriptor_api_version=2,
103
+ is_default=True,
104
+ )
105
+
106
+ __all__ = ["DOWHY_DESCRIPTOR"]
@@ -0,0 +1,43 @@
1
+ """DoWhy GCM report exporter."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, ClassVar
6
+
7
+ from pydantic import BaseModel, ConfigDict
8
+ from tributo.exporting.models import SupportRequest, SupportResult, ValidatorBinding
9
+ from tributo.training.exporters.causal_report import CausalReportExporter
10
+
11
+
12
+ class GCMReportOptions(BaseModel):
13
+ model_config = ConfigDict(extra="forbid")
14
+
15
+
16
+ class GCMReportExporter(CausalReportExporter):
17
+ api_version: ClassVar[int] = 2
18
+ exporter_id: ClassVar[str] = "official-causal-gcm-report-v1"
19
+ output_format: ClassVar[str] = "json"
20
+ output_flavor_id: ClassVar[str] = "report"
21
+ artifact_kind: ClassVar[str] = "report"
22
+ priority: ClassVar[int] = 90
23
+ source_kinds: ClassVar[tuple[str, ...]] = ("causal_gcm", "prebuilt_onnx")
24
+ options_model: ClassVar[type[BaseModel]] = GCMReportOptions
25
+ validator_bindings: ClassVar[tuple[ValidatorBinding, ...]] = ()
26
+ mutates_source: ClassVar[bool] = False
27
+ upstream_requirements: ClassVar[tuple[Any, ...]] = ()
28
+
29
+ @classmethod
30
+ def supports(cls, request: SupportRequest) -> SupportResult:
31
+ supported = request.source_kind in cls.source_kinds
32
+ return SupportResult(
33
+ supported=supported,
34
+ code="OK" if supported else "UNSUPPORTED_SOURCE_KIND",
35
+ reason=(
36
+ "causal GCM report source is supported"
37
+ if supported
38
+ else "GCM report exporter requires causal_gcm source"
39
+ ),
40
+ )
41
+
42
+
43
+ __all__ = ["GCMReportExporter"]