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.
- tributo_algorithms-0.1.0.dist-info/METADATA +328 -0
- tributo_algorithms-0.1.0.dist-info/RECORD +110 -0
- tributo_algorithms-0.1.0.dist-info/WHEEL +4 -0
- tributo_algorithms-0.1.0.dist-info/entry_points.txt +57 -0
- tributo_algorithms-0.1.0.dist-info/licenses/LICENSE +202 -0
- tributo_algorithms_boosting/__init__.py +42 -0
- tributo_algorithms_boosting/algorithm.py +825 -0
- tributo_algorithms_boosting/checkpointing.py +441 -0
- tributo_algorithms_boosting/contracts.py +232 -0
- tributo_algorithms_boosting/data_config.py +59 -0
- tributo_algorithms_boosting/descriptor.py +124 -0
- tributo_algorithms_boosting/lightgbm.py +511 -0
- tributo_algorithms_boosting/lightgbm_contracts.py +186 -0
- tributo_algorithms_boosting/lightgbm_descriptor.py +112 -0
- tributo_algorithms_boosting/native.py +557 -0
- tributo_algorithms_boosting/stages.py +150 -0
- tributo_algorithms_catboost/__init__.py +5 -0
- tributo_algorithms_catboost/algorithm.py +379 -0
- tributo_algorithms_catboost/contracts.py +145 -0
- tributo_algorithms_catboost/descriptor.py +121 -0
- tributo_algorithms_catboost/exporter.py +106 -0
- tributo_algorithms_catboost/flavor.py +191 -0
- tributo_algorithms_causal_core/__init__.py +41 -0
- tributo_algorithms_causal_core/algorithm.py +1193 -0
- tributo_algorithms_causal_core/contracts.py +136 -0
- tributo_algorithms_causal_core/descriptor.py +270 -0
- tributo_algorithms_causal_core/exporter.py +52 -0
- tributo_algorithms_causal_discovery/__init__.py +23 -0
- tributo_algorithms_causal_discovery/algorithm.py +526 -0
- tributo_algorithms_causal_discovery/contracts.py +97 -0
- tributo_algorithms_causal_discovery/descriptor.py +130 -0
- tributo_algorithms_causal_discovery/exporter.py +43 -0
- tributo_algorithms_causal_dowhy/__init__.py +38 -0
- tributo_algorithms_causal_dowhy/algorithm.py +325 -0
- tributo_algorithms_causal_dowhy/contracts.py +209 -0
- tributo_algorithms_causal_dowhy/descriptor.py +106 -0
- tributo_algorithms_causal_dowhy/exporter.py +43 -0
- tributo_algorithms_causal_dowhy/gcm.py +634 -0
- tributo_algorithms_causal_dowhy/gcm_descriptor.py +110 -0
- tributo_algorithms_causal_dr/__init__.py +22 -0
- tributo_algorithms_causal_dr/algorithm.py +446 -0
- tributo_algorithms_causal_dr/contracts.py +94 -0
- tributo_algorithms_causal_dr/descriptor.py +104 -0
- tributo_algorithms_causal_xlearner/__init__.py +29 -0
- tributo_algorithms_causal_xlearner/algorithm.py +448 -0
- tributo_algorithms_causal_xlearner/contracts.py +97 -0
- tributo_algorithms_causal_xlearner/descriptor.py +120 -0
- tributo_algorithms_causal_xlearner/exporter.py +432 -0
- tributo_algorithms_causal_xlearner/flavor.py +120 -0
- tributo_algorithms_causal_xlearner/model.py +116 -0
- tributo_algorithms_classical/__init__.py +41 -0
- tributo_algorithms_classical/contracts.py +139 -0
- tributo_algorithms_classical/descriptors.py +370 -0
- tributo_algorithms_classical/exporter.py +166 -0
- tributo_algorithms_classical/isolation_forest.py +172 -0
- tributo_algorithms_classical/isolation_forest_descriptor.py +122 -0
- tributo_algorithms_classical/kmeans.py +315 -0
- tributo_algorithms_classical/kmeans_descriptor.py +147 -0
- tributo_algorithms_classical/linear_regression.py +206 -0
- tributo_algorithms_classical/logistic_regression.py +238 -0
- tributo_algorithms_classical/models.py +28 -0
- tributo_algorithms_classical/multinomial_nb.py +643 -0
- tributo_algorithms_classical/multinomial_nb_descriptor.py +183 -0
- tributo_algorithms_classical/pca.py +187 -0
- tributo_algorithms_classical/pca_descriptor.py +111 -0
- tributo_algorithms_classical/random_forest.py +304 -0
- tributo_algorithms_classical/sgd.py +331 -0
- tributo_algorithms_classical/sgd_contracts.py +121 -0
- tributo_algorithms_classical/sgd_descriptor.py +143 -0
- tributo_algorithms_classical/unsupervised_contracts.py +198 -0
- tributo_algorithms_classical/unsupervised_exporter.py +427 -0
- tributo_algorithms_classical/unsupervised_models.py +90 -0
- tributo_algorithms_graph_pyg/__init__.py +37 -0
- tributo_algorithms_graph_pyg/algorithm.py +883 -0
- tributo_algorithms_graph_pyg/contracts.py +260 -0
- tributo_algorithms_graph_pyg/descriptor.py +201 -0
- tributo_algorithms_multistage_torch/__init__.py +40 -0
- tributo_algorithms_multistage_torch/algorithm.py +532 -0
- tributo_algorithms_multistage_torch/contracts.py +220 -0
- tributo_algorithms_multistage_torch/descriptor.py +146 -0
- tributo_algorithms_multistage_torch/pretrain.py +570 -0
- tributo_algorithms_multistage_torch/pretrain_descriptor.py +153 -0
- tributo_algorithms_recsys_torch/__init__.py +35 -0
- tributo_algorithms_recsys_torch/contracts.py +295 -0
- tributo_algorithms_recsys_torch/descriptor.py +136 -0
- tributo_algorithms_recsys_torch/jagged.py +707 -0
- tributo_algorithms_recsys_torch/jagged_descriptor.py +130 -0
- tributo_algorithms_recsys_torch/recipe.py +192 -0
- tributo_algorithms_representation/__init__.py +20 -0
- tributo_algorithms_representation/contracts.py +117 -0
- tributo_algorithms_representation/descriptor.py +137 -0
- tributo_algorithms_representation/recipe.py +162 -0
- tributo_algorithms_tabular_torch/__init__.py +46 -0
- tributo_algorithms_tabular_torch/contracts.py +228 -0
- tributo_algorithms_tabular_torch/descriptor.py +223 -0
- tributo_algorithms_tabular_torch/priors.py +216 -0
- tributo_algorithms_tabular_torch/pu_metrics.py +269 -0
- tributo_algorithms_tabular_torch/pu_reducer.py +129 -0
- tributo_algorithms_tabular_torch/recipe.py +294 -0
- tributo_algorithms_timeseries/__init__.py +36 -0
- tributo_algorithms_timeseries/contracts.py +120 -0
- tributo_algorithms_timeseries/descriptor.py +137 -0
- tributo_algorithms_timeseries/recipe.py +195 -0
- tributo_algorithms_timeseries/rnn_contracts.py +170 -0
- tributo_algorithms_timeseries/rnn_descriptor.py +167 -0
- tributo_algorithms_timeseries/rnn_recipe.py +223 -0
- tributo_algorithms_transformers_nlp/__init__.py +20 -0
- tributo_algorithms_transformers_nlp/contracts.py +109 -0
- tributo_algorithms_transformers_nlp/descriptor.py +137 -0
- tributo_algorithms_transformers_nlp/recipe.py +235 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""Executable contracts for distributed causal estimation."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ATEConfigValidator:
|
|
10
|
+
api_version = 1
|
|
11
|
+
schema_digest = "6" * 64
|
|
12
|
+
|
|
13
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
14
|
+
allowed = {
|
|
15
|
+
"confidence_z",
|
|
16
|
+
"cross_fit_folds",
|
|
17
|
+
"fold_column",
|
|
18
|
+
"output",
|
|
19
|
+
"policy_cost",
|
|
20
|
+
"treatment_col",
|
|
21
|
+
}
|
|
22
|
+
if unknown := sorted(set(value) - allowed):
|
|
23
|
+
raise ValueError(f"unknown ATE config keys: {unknown}")
|
|
24
|
+
treatment = value.get("treatment_col")
|
|
25
|
+
if not isinstance(treatment, str) or not treatment:
|
|
26
|
+
raise ValueError("treatment_col is required")
|
|
27
|
+
output = value.get("output")
|
|
28
|
+
if not isinstance(output, Mapping) or not output.get("bundle_uri"):
|
|
29
|
+
raise ValueError("output.bundle_uri is required")
|
|
30
|
+
folds = value.get("cross_fit_folds", 5)
|
|
31
|
+
if (
|
|
32
|
+
not isinstance(folds, int)
|
|
33
|
+
or isinstance(folds, bool)
|
|
34
|
+
or not 2 <= folds <= 20
|
|
35
|
+
):
|
|
36
|
+
raise ValueError("cross_fit_folds must be between 2 and 20")
|
|
37
|
+
return dict(value)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class IVConfigValidator(ATEConfigValidator):
|
|
41
|
+
api_version = 1
|
|
42
|
+
schema_digest = "5" * 64
|
|
43
|
+
|
|
44
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
45
|
+
allowed = {
|
|
46
|
+
"confidence_z",
|
|
47
|
+
"instrument_col",
|
|
48
|
+
"output",
|
|
49
|
+
"policy_cost",
|
|
50
|
+
"treatment_col",
|
|
51
|
+
}
|
|
52
|
+
if unknown := sorted(set(value) - allowed):
|
|
53
|
+
raise ValueError(f"unknown IV config keys: {unknown}")
|
|
54
|
+
instrument = value.get("instrument_col")
|
|
55
|
+
treatment = value.get("treatment_col")
|
|
56
|
+
if not isinstance(instrument, str) or not instrument:
|
|
57
|
+
raise ValueError("instrument_col is required")
|
|
58
|
+
if not isinstance(treatment, str) or not treatment or instrument == treatment:
|
|
59
|
+
raise ValueError("treatment_col must differ from instrument_col")
|
|
60
|
+
output = value.get("output")
|
|
61
|
+
if not isinstance(output, Mapping) or not output.get("bundle_uri"):
|
|
62
|
+
raise ValueError("output.bundle_uri is required")
|
|
63
|
+
return dict(value)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class CausalInputValidator:
|
|
67
|
+
api_version = 1
|
|
68
|
+
schema_digest = "2" * 64
|
|
69
|
+
|
|
70
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
71
|
+
bindings = value.get("bindings")
|
|
72
|
+
if not isinstance(bindings, list) or len(bindings) != 1:
|
|
73
|
+
raise ValueError("causal estimation requires one train binding")
|
|
74
|
+
binding = bindings[0]
|
|
75
|
+
if (
|
|
76
|
+
not isinstance(binding, Mapping)
|
|
77
|
+
or not binding.get("feature_names")
|
|
78
|
+
or not binding.get("label_name")
|
|
79
|
+
):
|
|
80
|
+
raise ValueError("causal input requires treatment/features and outcome")
|
|
81
|
+
return value
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class CausalOutputValidator:
|
|
85
|
+
api_version = 1
|
|
86
|
+
schema_digest = "3" * 64
|
|
87
|
+
|
|
88
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
89
|
+
outputs = value.get("outputs")
|
|
90
|
+
if value.get("status") != "succeeded" or not isinstance(outputs, Mapping):
|
|
91
|
+
raise ValueError("causal estimation failed")
|
|
92
|
+
if not outputs.get("bundle_uri") or not outputs.get("report_artifact_sha256"):
|
|
93
|
+
raise ValueError("causal output requires Bundle and report artifact")
|
|
94
|
+
return value
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class TreatmentCoverageValidator:
|
|
98
|
+
api_version = 1
|
|
99
|
+
schema_digest = "4" * 64
|
|
100
|
+
|
|
101
|
+
def validate(self, value: Mapping[str, Any]) -> Mapping[str, Any]:
|
|
102
|
+
if (
|
|
103
|
+
value.get("input_complete") is not True
|
|
104
|
+
or value.get("distributed") is not True
|
|
105
|
+
):
|
|
106
|
+
raise ValueError("causal distributed coverage is incomplete")
|
|
107
|
+
workers = value.get("workers")
|
|
108
|
+
if not isinstance(workers, list):
|
|
109
|
+
raise ValueError("causal coverage requires Worker evidence")
|
|
110
|
+
totals = {"treated": 0, "control": 0}
|
|
111
|
+
for worker in workers:
|
|
112
|
+
rows = worker.get("input_rows") if isinstance(worker, Mapping) else None
|
|
113
|
+
if not isinstance(rows, Mapping):
|
|
114
|
+
raise ValueError("causal treatment coverage is missing")
|
|
115
|
+
train_rows = rows.get("train")
|
|
116
|
+
local_total = 0
|
|
117
|
+
for group in totals:
|
|
118
|
+
count = rows.get(f"coverage.{group}")
|
|
119
|
+
if not isinstance(count, int) or isinstance(count, bool) or count < 0:
|
|
120
|
+
raise ValueError(f"causal {group} coverage is malformed")
|
|
121
|
+
totals[group] += count
|
|
122
|
+
local_total += count
|
|
123
|
+
if local_total != train_rows:
|
|
124
|
+
raise ValueError("treatment groups do not partition train rows")
|
|
125
|
+
if any(count <= 0 for count in totals.values()):
|
|
126
|
+
raise ValueError("causal estimation requires treatment overlap")
|
|
127
|
+
return value
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
__all__ = [
|
|
131
|
+
"ATEConfigValidator",
|
|
132
|
+
"CausalInputValidator",
|
|
133
|
+
"CausalOutputValidator",
|
|
134
|
+
"IVConfigValidator",
|
|
135
|
+
"TreatmentCoverageValidator",
|
|
136
|
+
]
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
"""Lightweight descriptors for official distributed causal estimators."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from tributo.algorithms import AlgorithmBuilder
|
|
6
|
+
from tributo.algorithms.api import (
|
|
7
|
+
ContractBinding,
|
|
8
|
+
ContractBindingSet,
|
|
9
|
+
DistributedAlgorithmDescriptor,
|
|
10
|
+
DistributionStrategy,
|
|
11
|
+
EnvironmentSpec,
|
|
12
|
+
ExecutionMode,
|
|
13
|
+
ExecutionProfile,
|
|
14
|
+
MapReducePolicy,
|
|
15
|
+
QualifiedReference,
|
|
16
|
+
StateField,
|
|
17
|
+
WorkerRange,
|
|
18
|
+
WorkerResources,
|
|
19
|
+
)
|
|
20
|
+
from tributo.training.algorithm_spec import AlgorithmSpec, Capability, ProblemType
|
|
21
|
+
|
|
22
|
+
_PACKAGE = "tributo-algorithms"
|
|
23
|
+
_VERSION = "0.1.0"
|
|
24
|
+
_COMMON_STATE = (
|
|
25
|
+
StateField("treated_count", "int64", ()),
|
|
26
|
+
StateField("control_count", "int64", ()),
|
|
27
|
+
StateField("treated_sum", "float64", ()),
|
|
28
|
+
StateField("control_sum", "float64", ()),
|
|
29
|
+
StateField("row_count", "int64", ()),
|
|
30
|
+
)
|
|
31
|
+
_STATE_SCHEMA = (
|
|
32
|
+
*_COMMON_STATE[:-1],
|
|
33
|
+
StateField("treated_sum_squares", "float64", ()),
|
|
34
|
+
StateField("control_sum_squares", "float64", ()),
|
|
35
|
+
_COMMON_STATE[-1],
|
|
36
|
+
)
|
|
37
|
+
_DML_STATE_SCHEMA = (
|
|
38
|
+
StateField("xtx", "float64", (None, None)),
|
|
39
|
+
StateField("xty", "float64", (None,)),
|
|
40
|
+
StateField("xtt", "float64", (None,)),
|
|
41
|
+
StateField("yty", "float64", ()),
|
|
42
|
+
StateField("ytt", "float64", ()),
|
|
43
|
+
StateField("ttt", "float64", ()),
|
|
44
|
+
*_COMMON_STATE,
|
|
45
|
+
StateField("fold_xtx", "float64", (None, None, None)),
|
|
46
|
+
StateField("fold_xty", "float64", (None, None)),
|
|
47
|
+
StateField("fold_xtt", "float64", (None, None)),
|
|
48
|
+
StateField("fold_yty", "float64", (None,)),
|
|
49
|
+
StateField("fold_ytt", "float64", (None,)),
|
|
50
|
+
StateField("fold_ttt", "float64", (None,)),
|
|
51
|
+
)
|
|
52
|
+
_IV_STATE_SCHEMA = (
|
|
53
|
+
StateField("xtx", "float64", (None, None)),
|
|
54
|
+
StateField("xty", "float64", (None,)),
|
|
55
|
+
StateField("xtt", "float64", (None,)),
|
|
56
|
+
StateField("xtz", "float64", (None,)),
|
|
57
|
+
StateField("yty", "float64", ()),
|
|
58
|
+
StateField("ytt", "float64", ()),
|
|
59
|
+
StateField("ttt", "float64", ()),
|
|
60
|
+
StateField("ytz", "float64", ()),
|
|
61
|
+
StateField("ttz", "float64", ()),
|
|
62
|
+
StateField("ztz", "float64", ()),
|
|
63
|
+
*_COMMON_STATE,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _contract(contract_id: str, digest: str, validator: str) -> ContractBinding:
|
|
68
|
+
return ContractBinding(
|
|
69
|
+
contract_id=contract_id,
|
|
70
|
+
schema_version=1,
|
|
71
|
+
schema_digest=digest * 64,
|
|
72
|
+
validator_ref=QualifiedReference.parse(
|
|
73
|
+
f"tributo_algorithms_causal_core.contracts:{validator}"
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _spec(
|
|
79
|
+
*,
|
|
80
|
+
name: str,
|
|
81
|
+
model_family: str,
|
|
82
|
+
lifecycle_kind: str,
|
|
83
|
+
config_contract_ref: str,
|
|
84
|
+
input_contract_ref: str,
|
|
85
|
+
) -> AlgorithmSpec:
|
|
86
|
+
return AlgorithmSpec(
|
|
87
|
+
name=name,
|
|
88
|
+
trainer_cls=None,
|
|
89
|
+
version="1.0.0",
|
|
90
|
+
default_config={},
|
|
91
|
+
supported_tasks=("fit",),
|
|
92
|
+
operations=("fit",),
|
|
93
|
+
problem_types=(ProblemType.CAUSAL_EFFECT_ESTIMATION,),
|
|
94
|
+
capabilities=(
|
|
95
|
+
Capability.DISTRIBUTED,
|
|
96
|
+
Capability.EXPORTABLE,
|
|
97
|
+
Capability.TUNABLE,
|
|
98
|
+
),
|
|
99
|
+
learning_paradigm="causal_inference",
|
|
100
|
+
model_family=model_family,
|
|
101
|
+
data_modalities=("tabular",),
|
|
102
|
+
lifecycle_kind=lifecycle_kind,
|
|
103
|
+
allowed_execution_modes=(ExecutionMode.MAP_REDUCE.value,),
|
|
104
|
+
config_contract_ref=config_contract_ref,
|
|
105
|
+
input_contract_ref=input_contract_ref,
|
|
106
|
+
output_contract_ref="tributo.official.causal.report-bundle.v1",
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
_ATE_SPEC = _spec(
|
|
111
|
+
name="difference_in_means_ate",
|
|
112
|
+
model_family="difference_in_means",
|
|
113
|
+
lifecycle_kind="identify_estimate_policy",
|
|
114
|
+
config_contract_ref="tributo.official.causal.ate.config.v1",
|
|
115
|
+
input_contract_ref="tributo.official.causal.binary-treatment.v1",
|
|
116
|
+
)
|
|
117
|
+
_DML_SPEC = _spec(
|
|
118
|
+
name="linear_dml_ate",
|
|
119
|
+
model_family="linear_dml",
|
|
120
|
+
lifecycle_kind="identify_crossfit_estimate_policy",
|
|
121
|
+
config_contract_ref="tributo.official.causal.linear-dml.config.v1",
|
|
122
|
+
input_contract_ref="tributo.official.causal.binary-treatment.v1",
|
|
123
|
+
)
|
|
124
|
+
_IV_SPEC = _spec(
|
|
125
|
+
name="linear_iv_ate",
|
|
126
|
+
model_family="linear_instrumental_variables",
|
|
127
|
+
lifecycle_kind="identify_first_stage_estimate_policy",
|
|
128
|
+
config_contract_ref="tributo.official.causal.linear-iv.config.v1",
|
|
129
|
+
input_contract_ref="tributo.official.causal.binary-treatment-instrument.v1",
|
|
130
|
+
)
|
|
131
|
+
_ENVIRONMENT = EnvironmentSpec(
|
|
132
|
+
environment_id="tributo.official.causal-core.v1",
|
|
133
|
+
dependencies=(
|
|
134
|
+
"numpy>=2,<3",
|
|
135
|
+
"scikit-learn>=1.4,<2",
|
|
136
|
+
"skl2onnx>=1.17",
|
|
137
|
+
"tributo>=1.1",
|
|
138
|
+
f"tributo-algorithms[causal-core]=={_VERSION}",
|
|
139
|
+
),
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _bindings(
|
|
144
|
+
spec: AlgorithmSpec,
|
|
145
|
+
*,
|
|
146
|
+
config_digest: str,
|
|
147
|
+
config_validator: str,
|
|
148
|
+
coverage_id: str,
|
|
149
|
+
) -> ContractBindingSet:
|
|
150
|
+
return ContractBindingSet(
|
|
151
|
+
config=_contract(
|
|
152
|
+
spec.config_contract_ref or "",
|
|
153
|
+
config_digest,
|
|
154
|
+
config_validator,
|
|
155
|
+
),
|
|
156
|
+
input=_contract(
|
|
157
|
+
spec.input_contract_ref or "",
|
|
158
|
+
"2",
|
|
159
|
+
"CausalInputValidator",
|
|
160
|
+
),
|
|
161
|
+
output=_contract(
|
|
162
|
+
spec.output_contract_ref or "",
|
|
163
|
+
"3",
|
|
164
|
+
"CausalOutputValidator",
|
|
165
|
+
),
|
|
166
|
+
coverage=_contract(coverage_id, "4", "TreatmentCoverageValidator"),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _descriptor(
|
|
171
|
+
*,
|
|
172
|
+
spec: AlgorithmSpec,
|
|
173
|
+
implementation_id: str,
|
|
174
|
+
implementation_class: str,
|
|
175
|
+
state_schema: tuple[StateField, ...],
|
|
176
|
+
allowed_config_keys: tuple[str, ...],
|
|
177
|
+
contract_bindings: ContractBindingSet,
|
|
178
|
+
) -> DistributedAlgorithmDescriptor:
|
|
179
|
+
implementation = f"tributo_algorithms_causal_core.algorithm:{implementation_class}"
|
|
180
|
+
return AlgorithmBuilder.from_distributed_algorithm(
|
|
181
|
+
spec=spec,
|
|
182
|
+
implementation_id=implementation_id,
|
|
183
|
+
implementation_version="1.0.0",
|
|
184
|
+
implementation=implementation,
|
|
185
|
+
executable_factory="tributo_algorithms_causal_core.algorithm:create_algorithm",
|
|
186
|
+
distribution=_PACKAGE,
|
|
187
|
+
framework=None,
|
|
188
|
+
environment=_ENVIRONMENT,
|
|
189
|
+
allowed_config_keys=allowed_config_keys,
|
|
190
|
+
strategy=DistributionStrategy.RAY_MAP_REDUCE,
|
|
191
|
+
supported_worker_range=WorkerRange(2, 256),
|
|
192
|
+
supported_execution_profiles=(
|
|
193
|
+
ExecutionProfile.LOCAL,
|
|
194
|
+
ExecutionProfile.CLUSTER,
|
|
195
|
+
),
|
|
196
|
+
resources_per_worker=WorkerResources(num_cpus=1),
|
|
197
|
+
policy=MapReducePolicy(
|
|
198
|
+
state_schema=state_schema,
|
|
199
|
+
max_partial_state_bytes=64 * 1024 * 1024,
|
|
200
|
+
reducer_ref=f"{implementation}.merge_states",
|
|
201
|
+
finalizer_ref=f"{implementation}.finalize_model",
|
|
202
|
+
commutative=True,
|
|
203
|
+
max_retries=0,
|
|
204
|
+
),
|
|
205
|
+
package_name=_PACKAGE,
|
|
206
|
+
package_version=_VERSION,
|
|
207
|
+
tributo_version_spec=">=1.1",
|
|
208
|
+
exporter="tributo_algorithms_causal_core.algorithm:export_model",
|
|
209
|
+
flavor_id="onnx-runtime-v1",
|
|
210
|
+
contract_bindings=contract_bindings,
|
|
211
|
+
descriptor_api_version=2,
|
|
212
|
+
is_default=True,
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
ATE_DESCRIPTOR = _descriptor(
|
|
217
|
+
spec=_ATE_SPEC,
|
|
218
|
+
implementation_id="tributo.official.causal.difference_in_means",
|
|
219
|
+
implementation_class="DifferenceInMeansATE",
|
|
220
|
+
state_schema=_STATE_SCHEMA,
|
|
221
|
+
allowed_config_keys=("confidence_z", "output", "policy_cost", "treatment_col"),
|
|
222
|
+
contract_bindings=_bindings(
|
|
223
|
+
_ATE_SPEC,
|
|
224
|
+
config_digest="6",
|
|
225
|
+
config_validator="ATEConfigValidator",
|
|
226
|
+
coverage_id="tributo.official.causal.treatment-coverage.v1",
|
|
227
|
+
),
|
|
228
|
+
)
|
|
229
|
+
LINEAR_DML_DESCRIPTOR = _descriptor(
|
|
230
|
+
spec=_DML_SPEC,
|
|
231
|
+
implementation_id="tributo.official.causal.linear_dml",
|
|
232
|
+
implementation_class="LinearDMLATE",
|
|
233
|
+
state_schema=_DML_STATE_SCHEMA,
|
|
234
|
+
allowed_config_keys=(
|
|
235
|
+
"confidence_z",
|
|
236
|
+
"cross_fit_folds",
|
|
237
|
+
"fold_column",
|
|
238
|
+
"output",
|
|
239
|
+
"policy_cost",
|
|
240
|
+
"treatment_col",
|
|
241
|
+
),
|
|
242
|
+
contract_bindings=_bindings(
|
|
243
|
+
_DML_SPEC,
|
|
244
|
+
config_digest="6",
|
|
245
|
+
config_validator="ATEConfigValidator",
|
|
246
|
+
coverage_id="tributo.official.causal.dml-treatment-coverage.v1",
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
LINEAR_IV_DESCRIPTOR = _descriptor(
|
|
250
|
+
spec=_IV_SPEC,
|
|
251
|
+
implementation_id="tributo.official.causal.linear_iv",
|
|
252
|
+
implementation_class="LinearIVATE",
|
|
253
|
+
state_schema=_IV_STATE_SCHEMA,
|
|
254
|
+
allowed_config_keys=(
|
|
255
|
+
"confidence_z",
|
|
256
|
+
"instrument_col",
|
|
257
|
+
"output",
|
|
258
|
+
"policy_cost",
|
|
259
|
+
"treatment_col",
|
|
260
|
+
),
|
|
261
|
+
contract_bindings=_bindings(
|
|
262
|
+
_IV_SPEC,
|
|
263
|
+
config_digest="5",
|
|
264
|
+
config_validator="IVConfigValidator",
|
|
265
|
+
coverage_id="tributo.official.causal.iv-treatment-coverage.v1",
|
|
266
|
+
),
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
__all__ = ["ATE_DESCRIPTOR", "LINEAR_DML_DESCRIPTOR", "LINEAR_IV_DESCRIPTOR"]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""Causal report Bundle exporter owned by the official causal Wheel."""
|
|
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 (
|
|
9
|
+
SupportRequest,
|
|
10
|
+
SupportResult,
|
|
11
|
+
ValidatorBinding,
|
|
12
|
+
)
|
|
13
|
+
from tributo.training.exporters.causal_report import CausalReportExporter
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CausalReportOptions(BaseModel):
|
|
17
|
+
model_config = ConfigDict(extra="forbid")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OfficialCausalReportExporter(CausalReportExporter):
|
|
21
|
+
"""Export versioned causal study metadata as a Bundle report role."""
|
|
22
|
+
|
|
23
|
+
api_version: ClassVar[int] = 2
|
|
24
|
+
exporter_id: ClassVar[str] = "official-causal-report-v1"
|
|
25
|
+
output_format: ClassVar[str] = "json"
|
|
26
|
+
output_flavor_id: ClassVar[str] = "report"
|
|
27
|
+
artifact_kind: ClassVar[str] = "report"
|
|
28
|
+
priority: ClassVar[int] = 90
|
|
29
|
+
source_kinds: ClassVar[tuple[str, ...]] = ("prebuilt_onnx",)
|
|
30
|
+
options_model: ClassVar[type[BaseModel]] = CausalReportOptions
|
|
31
|
+
validator_bindings: ClassVar[tuple[ValidatorBinding, ...]] = ()
|
|
32
|
+
mutates_source: ClassVar[bool] = False
|
|
33
|
+
upstream_requirements: ClassVar[tuple[Any, ...]] = ()
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def supports(cls, request: SupportRequest) -> SupportResult:
|
|
37
|
+
return SupportResult(
|
|
38
|
+
supported=request.source_kind == "prebuilt_onnx",
|
|
39
|
+
code=(
|
|
40
|
+
"OK"
|
|
41
|
+
if request.source_kind == "prebuilt_onnx"
|
|
42
|
+
else "UNSUPPORTED_SOURCE_KIND"
|
|
43
|
+
),
|
|
44
|
+
reason=(
|
|
45
|
+
"causal report source is supported"
|
|
46
|
+
if request.source_kind == "prebuilt_onnx"
|
|
47
|
+
else "causal report requires a prebuilt causal ONNX source"
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
__all__ = ["OfficialCausalReportExporter"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Official distributed causal discovery algorithms with lazy runtime exports."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from tributo_algorithms_causal_discovery.descriptor import PC_DISCOVERY_DESCRIPTOR
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def __getattr__(name: str) -> Any:
|
|
11
|
+
if name != "DistributedPCStability":
|
|
12
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
13
|
+
import importlib
|
|
14
|
+
|
|
15
|
+
value = getattr(
|
|
16
|
+
importlib.import_module("tributo_algorithms_causal_discovery.algorithm"),
|
|
17
|
+
name,
|
|
18
|
+
)
|
|
19
|
+
globals()[name] = value
|
|
20
|
+
return value
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
__all__ = ["PC_DISCOVERY_DESCRIPTOR", "DistributedPCStability"]
|